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

TypeScript underscore.Underscore类代码示例

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

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



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

示例1: async

export const prepareDuniterServer = async (options:any) => {

  const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'};
  const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'};
  const remuniterKeyring = { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'};

  const s1 = NewTestingServer(Underscore.extend({ pair: catKeyring }, options || {}));
  const sR = NewTestingServer(Underscore.extend({ pair: remuniterKeyring }, options || {}));

  const cat = {
    uid: 'cat',
    pub: catKeyring.pub,
    sec: catKeyring.sec
  }

  const tac = {
    uid: 'tac',
    pub: tacKeyring.pub,
    sec: tacKeyring.sec
  }

  const remuniter = {
    uid: 'remuniter',
    pub: remuniterKeyring.pub,
    sec: remuniterKeyring.sec
  }

  await s1._server.initWithDAL()
  await sR._server.initWithDAL()

  return { s1, sR, cat, tac, remuniter };
}
开发者ID:duniter,项目名称:remuniter,代码行数:32,代码来源:pay-test.ts


示例2: async

    pay: async (fromBlock: number, toBlock: number) => {
      let blocks = await duniterServer.dal.getBlocksBetween(fromBlock, toBlock);
      let reallyPaid = payperblock * blocks.length; // Implicitely: amount in the current base
      let statsPerIssuer = getStatsPerIssuer(blocks, payperblock);
      let sources = await duniterServer.dal.getAvailableSourcesByPubkey(remuniterPubkey);
      let current = await duniterServer.dal.getCurrentBlockOrNull() as DBBlock
      let maxBase = current.unitbase;

      const minBase = sources.reduce((min, src) => Math.min(min, src.base), 0);
      const bases: {
        [k: number]: number
      } = {}
      sources.forEach((src) => bases[src.base] = 0);
      sources.forEach((src) => bases[src.base] += src.amount);
      bases[maxBase] = bases[maxBase] || 0;

      // Try to convert 1 base to the other
      let outputsOfRests = [];
      for (let i = minBase; i < maxBase; i++) {
        bases[i] = bases[i] || 0;
        bases[i + 1] = bases[i + 1] || 0;
        const rest = bases[i] % 10;
        bases[i] -= rest;
        bases[i + 1] += bases[i] / 10;
        outputsOfRests.push([rest, i, 'SIG(' + remuniterPubkey + ')'].join(':'));
      }
      const availableMoney = bases[maxBase];

      let outputsToIssuers = Underscore.keys(statsPerIssuer).map((issuer) => [statsPerIssuer[issuer].amount, maxBase, 'SIG(' + issuer + ')'].join(':'));

      if (availableMoney >= reallyPaid) {
        let tx = {
          documentType: 'transaction',
          version: 10,
          currency: duniterServer.conf.currency,
          blockstamp: [current.number, current.hash].join('-'),
          locktime: 0,
          issuers: [remuniterPubkey],
          inputs: sources.map((src) => [src.amount, src.base, src.type, src.identifier, src.noffset].join(':')),
          unlocks: sources.map((src, index) => [index, 'SIG(0)'].join(':')),
          outputs: outputsOfRests.concat(outputsToIssuers).concat([availableMoney - reallyPaid, maxBase, 'SIG(' + remuniterPubkey + ')'].join(':')),
          comment: ['REMU', fromBlock, toBlock].join(':'),
          signatures: [] as string[]
        };
        let rawTX = getRawTransaction(tx);

        // ----- SIGNATURE -----
        tx.signatures = [await duniterServer.sign(rawTX)];

        // ----- SUBMITTING -----
        await duniterServer.writeRawTransaction(getRawTransaction(tx));

        return existsTx(fromBlock, toBlock, 'sending');
      }
      return false;
    },
开发者ID:duniter,项目名称:remuniter,代码行数:56,代码来源:wallet.ts


示例3: return

 return (async () => {
   let txh: TxHistory = await duniterServer.dal.getTransactionsHistory(remuniterPubkey);
   let txs = Underscore.filter(txh[txCategory], (tx: DBTx) => {
     let match = tx.comment && tx.comment.match(/^REMU:(\d+):(\d+)$/);
     if (!match) {
       return false;
     }
     let from = parseInt(match[1]);
     let to = parseInt(match[2]);
     return (from <= fromBlock && fromBlock <= to) || (from <= toBlock && toBlock <= to);
   });
   return txs.length > 0 && txs[0];
 })()
开发者ID:duniter,项目名称:remuniter,代码行数:13,代码来源:wallet.ts


示例4: parseInt

 return txh.sent.reduce((sum, tx) => {
   let match = tx.comment && tx.comment.match(/^REMU:(\d+):(\d+)$/);
   if (!match) {
     return false;
   }
   let from = parseInt(match[1]);
   let to = parseInt(match[2]);
   let nbBlocks = to - from + 1;
   let totalGiven = 0;
   tx.outputs.forEach((out: any) => {
     let match = String(out.raw || out).match(/(\d+):(\d+):SIG\((.*)\)/);
     if (match) {
       let outputAmount = parseInt(match[1]) * Math.pow(10, parseInt(match[2]));
       if (tx.issuers.indexOf(match[3]) === -1) {
         totalGiven += outputAmount;
       }
     }
   });
   let localPayPerBlock = totalGiven / nbBlocks;
   let blocksIssuedInTx = Underscore.filter(blocks, (b: any) => b.issuer == pubkey && b.number >= from && b.number <= to);
   let paidToPubkey = localPayPerBlock * blocksIssuedInTx.length;
   return sum + paidToPubkey;
 }, 0);
开发者ID:duniter,项目名称:remuniter,代码行数:23,代码来源:wallet.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript server.Server类代码示例发布时间:2022-05-25
下一篇:
TypeScript dugite.GitProcess类代码示例发布时间: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