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


TypeScript bn.js.default类代码示例

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


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

示例1: getRevealersForMessage

 // Select revealers from all eligible revealers for a message
 async getRevealersForMessage(reward: BN, numRevealers: number) {
   const eligibleRevealers: Revealer[] = await this.getEligibleRevealers();
   const minReward: BN = reward.div(new BN(numRevealers + 1));
   const filteredAndOrderedRevealers: Revealer[] = eligibleRevealers
     .filter((revealer: Revealer) => minReward.gte(revealer.minReward))
     .sort((a, b) => a.stakePerMessage.sub(b.stakePerMessage).toNumber());
   return filteredAndOrderedRevealers.slice(0, numRevealers);
 }
开发者ID:coderwithattitude,项目名称:kimono,代码行数:9,代码来源:Kimono.ts

示例2: it

    it(`should pass ${testName}`, function(done) {
      let incoming = officalTests[testName].in
      // if we are testing a big number
      if (incoming[0] === '#') {
        const bn = new BN(incoming.slice(1))
        incoming = Buffer.from(bn.toArray())
      }

      const encoded = RLP.encode(incoming)
      assert.equal('0x' + encoded.toString('hex'), officalTests[testName].out.toLowerCase())
      done()
    })
开发者ID:ethereumjs,项目名称:rlp,代码行数:12,代码来源:official.spec.ts

示例3: makeTokenTransferSkeleton

export function makeTokenTransferSkeleton(recipientAddress: string, consensusHash: string,
                                          tokenType: string, tokenAmount: BN,
                                          scratchArea: string
) {
  /*
   Format:

    0     2  3              19         38          46                        80
    |-----|--|--------------|----------|-----------|-------------------------|
    magic op  consensus_hash token_type amount (BE) scratch area
                             (ns_id)

    output 0: token transfer code
    output 1: recipient address
  */
  if (scratchArea.length > 34) {
    throw new Error('Invalid scratch area: must be no more than 34 bytes')
  }

  const opReturnBuffer = Buffer.alloc(46 + scratchArea.length)

  const tokenTypeHex = Buffer.from(tokenType).toString('hex')
  const tokenTypeHexPadded = `00000000000000000000000000000000000000${tokenTypeHex}`.slice(-38)

  const tokenValueHex = tokenAmount.toString(16, 2)

  if (tokenValueHex.length > 16) {
    // exceeds 2**64; can't fit
    throw new Error(`Cannot send tokens: cannot fit ${tokenAmount.toString()} into 8 bytes`)
  }

  const tokenValueHexPadded = `0000000000000000${tokenValueHex}`.slice(-16)

  opReturnBuffer.write(opEncode('$'), 0, 3, 'ascii')
  opReturnBuffer.write(consensusHash, 3, consensusHash.length / 2, 'hex')
  opReturnBuffer.write(tokenTypeHexPadded, 19, tokenTypeHexPadded.length / 2, 'hex')
  opReturnBuffer.write(tokenValueHexPadded, 38, tokenValueHexPadded.length / 2, 'hex')
  opReturnBuffer.write(scratchArea, 46, scratchArea.length, 'ascii')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)
  tx.addOutput(recipientAddress, DUST_MINIMUM)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:47,代码来源:skeletons.ts

示例4: getEligibleRevealers

 // Return all eligible revealers from contract
 async getEligibleRevealers() {
   const eligibleRevealersCount: BN = (await this.kimono.getEligibleRevealersCount())[0];
   const eligibleRevealers: Revealer[] = new Array(
     eligibleRevealersCount.toNumber()
   ).fill(undefined);
   for (let i = 0; i < eligibleRevealersCount.toNumber(); i++) {
     const revealerAddress = (await this.kimono.eligibleRevealers(i))[0];
     const [
       publicKey,
       minReward,
       stakePerMessage
     ] = await this.kimono.revealerTable(revealerAddress);
     eligibleRevealers[i] = {
       address: revealerAddress,
       publicKey,
       minReward,
       stakePerMessage
     };
   }
   return eligibleRevealers;
 }
开发者ID:coderwithattitude,项目名称:kimono,代码行数:22,代码来源:Kimono.ts

示例5: bnToBytes

export function bnToBytes(bn: BN, length: number) {
  return hexToBytes(bn.toString(16, length));
}
开发者ID:coderwithattitude,项目名称:kimono,代码行数:3,代码来源:crypto.ts

示例6:

 .filter((revealer: Revealer) => minReward.gte(revealer.minReward))
开发者ID:coderwithattitude,项目名称:kimono,代码行数:1,代码来源:Kimono.ts


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