当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.Underscore类代码示例

本文整理汇总了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;未经允许,请勿转载。