• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript decentraland-commons.Log类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中decentraland-commons.Log的典型用法代码示例。如果您正苦于以下问题:TypeScript Log类的具体用法?TypeScript Log怎么用?TypeScript Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Log类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Log

import {
  Translation,
  TranslationData,
  TranslationCache
} from '../src/Translation'

interface RemoteTranslation {
  locale: string
  key: string
  text: string
  replacedKeys: TranslationData
  defaultText: string
}

let BATCH_SIZE = 10
const log = new Log('translate')

const nonTranslatable = ['Decentraland', 'LAND', 'MANA']

const TRANSLATION_KEY = 'tk'
const NON_TRANSLATABLE_KEY = 'nt'
const DEFAULT_LOCALE = Translation.DEFAULT_LOCALE

async function main() {
  const translation = new Translation()

  const mainTranslations = await translation.fetch(DEFAULT_LOCALE)
  const availableLocales = await getAvailableLocales()

  const mainKeys = Object.keys(mainTranslations)
  let flatMissingTranslations = {}
开发者ID:decentraland,项目名称:agora,代码行数:31,代码来源:translate.ts


示例2: upsertDistrictAccountsFromContributions

async function upsertDistrictAccountsFromContributions() {
  const districtEntries: DistrictEntry[] = await db.query(
    SQL`SELECT D.address, D.project_id, SUM(D.lands) AS lands,
      (SELECT row_to_json(P.*) FROM projects P WHERE P.id = D.project_id) AS project
        FROM district_entries D
        GROUP BY D.address, D.project_id`
  )

  log.info(`Normalizing ${districtEntries.length} district_entries.`)

  for (const districtEntry of districtEntries) {
    const token = await upsertToken(districtEntry.project)
    if (!token) continue

    const address = districtEntry.address.toLowerCase()

    log.info(`Upserting ${address}`)
    const account = new AccountBalance({
      address,
      token_address: token.get('address'),
      balance: districtEntry.lands.toString()
    })
    await account.upsert({ target: ['address', 'token_address'] })
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:25,代码来源:initDb.ts


示例3: monitorBalances

export async function main() {
  log.info('Connecting database')
  await db.connect()

  const tokens = await Token.find<TokenAttributes>()

  for (const token of tokens) {
    if (DistrictToken.isValid(token)) continue

    const tokenContract = Object.create(new contracts.ERC20Token(token.address))
    tokenContract.getContractName = () => token.name
    tokenContracts[token.address] = tokenContract
  }

  try {
    log.info(`Connecting to Ethereum Node with ${tokens.map(t => t.name)}`)
    await eth.connect({
      contracts: Object.values(tokenContracts),
      provider: env.get('RPC_URL')
    })

    const delay = env.get('MONITOR_BALANCES_DELAY', '10000')
    log.info(`Using ${delay}ms as delay between updates`)
    await monitorBalances(Number(delay))
  } catch (error) {
    log.info('Whoops, something went wrong')
    log.info(error)

    process.exit()
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:31,代码来源:monitorBalances.ts


示例4: dropDumps

export async function initializeDatabase() {
  const shouldContinue = await cli.confirm(
    `Careful! this will DROP 'projects' and 'district_entries,
  upsert 'account_balances' and a district token.
Do you wish to continue?`
  )
  if (!shouldContinue) return process.exit()

  log.info('Connecting database')
  await db.connect()

  log.info('Initializing state')
  await dropDumps()

  log.info('Restoring district_entries')
  execSync(runpsql('../dumps/districts.20180105.sql'))

  log.info('Restoring projects')
  execSync(runpsql('../dumps/projects.20180105.sql'))

  log.info('Upserting district accounts')
  await upsertDistrictAccountsFromContributions()

  log.info('Dropping leftover tables')
  await dropDumps()

  log.info('All done!')
  process.exit()
}
开发者ID:decentraland,项目名称:agora,代码行数:29,代码来源:initDb.ts


示例5: upsertToken

async function upsertToken(project: Project) {
  if (!project.lookup) return null
  const name = project.name

  log.info(`Upserting Token for ${name}`)
  const token = new DistrictToken(name)
  await token.upsert({ target: ['address'] })

  return token
}
开发者ID:decentraland,项目名称:agora,代码行数:10,代码来源:initDb.ts


示例6: updateAccountBalances

async function updateAccountBalances() {
  const accounts = await AccountBalance.find<AccountBalanceAttributes>()

  for (const account of accounts) {
    const { address, token_address } = account
    const contract = tokenContracts[token_address]

    /*
      Perf improvement to avoid updating contributors account balances
      as they are fixed and only set once. It's important that a proper
      row exist before using the app that map a contributor address to
      it's contributions for each district
      ref: https://github.com/decentraland/agora/pull/126
    */
    if (DistrictToken.isAddress(token_address)) {
      continue
    }

    if (!contract) {
      log.info(`No contract for address ${token_address} in account ${address}`)
      continue
    }

    const contractBalance = await contract.balanceOf(address)
    const balance = eth.utils.fromWei(contractBalance).toString()

    log.info(`Updating Accounts and votes ${address} with balance ${balance}`)
    await Promise.all([
      AccountBalance.update<AccountBalanceAttributes>(
        { balance },
        { address, token_address }
      ),
      Vote.updateBalance(account, balance)
    ])
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:36,代码来源:monitorBalances.ts


示例7: main

async function main() {
  const translation = new Translation()

  const mainTranslations = await translation.fetch(DEFAULT_LOCALE)
  const availableLocales = await getAvailableLocales()

  const mainKeys = Object.keys(mainTranslations)
  let flatMissingTranslations = {}

  for (const locale of availableLocales) {
    const translations = await translation.fetch(locale)
    let requests: Promise<RemoteTranslation>[] = []

    for (const key of mainKeys) {
      if (key in translations) continue

      const defaultText = mainTranslations[key]
      const { textToTranslate, replacedKeys } = replaceTextKeys(defaultText)

      requests.push(
        translate(locale, textToTranslate).then(text => {
          const remoteTranslation: RemoteTranslation = {
            locale,
            key,
            text,
            replacedKeys,
            defaultText
          }
          return remoteTranslation
        })
      )

      if (requests.length > BATCH_SIZE) {
        await updateMissingTranslations(flatMissingTranslations, requests)
        requests = []
      }
    }

    await updateMissingTranslations(flatMissingTranslations, requests)
  }

  await writeTranslations(flatMissingTranslations)
  log.info('Done!')
}
开发者ID:decentraland,项目名称:agora,代码行数:44,代码来源:translate.ts


示例8: updateMissingTranslations

async function updateMissingTranslations(
  flatMissingTranslations: TranslationCache,
  requests: Promise<RemoteTranslation>[]
) {
  const translated = await Promise.all(requests)

  for (let { locale, key, text, replacedKeys, defaultText } of translated) {
    text = restoreTextKeys(text, replacedKeys)

    if (isCapitalized(defaultText) && !isCapitalized(text)) {
      text = capitalize(text)
    }

    if (!flatMissingTranslations[locale]) {
      flatMissingTranslations[locale] = {}
    }
    flatMissingTranslations[locale][key] = text
    log.info(`${locale}(${key}): ${defaultText} -> ${text}`)
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:20,代码来源:translate.ts



注:本文中的decentraland-commons.Log类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript decentraland-commons.env类代码示例发布时间:2022-05-25
下一篇:
TypeScript decaffeinate-parser.parse函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap