當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。