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

TypeScript bignumber.js.default类代码示例

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

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



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

示例1: dropsToXrp

function dropsToXrp(drops: string | BigNumber): string {
  if (typeof drops === 'string') {
    if (!drops.match(/^-?[0-9]*\.?[0-9]*$/)) {
      throw new ValidationError(`dropsToXrp: invalid value '${drops}',` +
        ` should be a number matching (^-?[0-9]*\.?[0-9]*$).`)
    } else if (drops === '.') {
      throw new ValidationError(`dropsToXrp: invalid value '${drops}',` +
        ` should be a BigNumber or string-encoded number.`)
    }
  }

  // Converting to BigNumber and then back to string should remove any
  // decimal point followed by zeros, e.g. '1.00'.
  // Important: specify base 10 to avoid exponential notation, e.g. '1e-7'.
  drops = (new BigNumber(drops)).toString(10)

  // drops are only whole units
  if (drops.includes('.')) {
    throw new ValidationError(`dropsToXrp: value '${drops}' has` +
      ` too many decimal places.`)
  }

  // This should never happen; the value has already been
  // validated above. This just ensures BigNumber did not do
  // something unexpected.
  if (!drops.match(/^-?[0-9]+$/)) {
    throw new ValidationError(`dropsToXrp: failed sanity check -` +
      ` value '${drops}',` +
      ` does not match (^-?[0-9]+$).`)
  }

  return (new BigNumber(drops)).dividedBy(1000000.0).toString(10)
}
开发者ID:ripple,项目名称:ripple-lib,代码行数:33,代码来源:utils.ts


示例2: Error

BitGo.prototype.checkFunded = co(function *checkFunded() {
  // We are testing both BTC and ETH funds here, to make sure that
  // we don't spend for already 'failed' test runs (e.g., spending ETH when we don't have enough BTC)

  // Test we have enough ETH
  yield this.authenticateTestUser(this.testUserOTP());
  const testWalletId = BitGo.V2.TEST_ETH_WALLET_ID;

  const {
    tethWallet,
    tbtcWallet,
    unspentWallet,
    sweep1Wallet
  } = yield Promise.props({
    tethWallet: this.coin('teth').wallets().get({ id: testWalletId }),
    tbtcWallet: this.coin('tbtc').wallets().getWallet({ id: BitGo.V2.TEST_WALLET1_ID }),
    unspentWallet:  this.coin('tbtc').wallets().getWallet({ id: BitGo.V2.TEST_WALLET2_UNSPENTS_ID }),
    sweep1Wallet: this.coin('tbtc').wallets().getWallet({ id: BitGo.V2.TEST_SWEEP1_ID }),
  });

  const spendableBalance = tethWallet.spendableBalanceString;

  let balance = new BigNumber(spendableBalance);

  // Check our balance is over 60000 (we spend 50000, add some cushion)
  if (balance.lt(60000)) {
    throw new Error(`The TETH wallet ${testWalletId} does not have enough funds to run the test suite. The current balance is ${balance}. Please fund this wallet!`);
  }

  // Check we have enough in the wallet to run test suite
  tbtcWallet.should.have.property('spendableBalanceString');
  balance = new BigNumber(tbtcWallet.spendableBalanceString());

  // Check our balance is over 0.05 tBTC (we spend 0.04, add some cushion)
  let minimumBalance = 0.05 * 1e8;
  if (balance.lt(minimumBalance)) {
    throw new Error(`The TBTC wallet ${tbtcWallet.id()} does not have enough funds to run the test suite. The current balance is ${balance}. Please fund this wallet!`);
  }

  // Check we have enough in the wallet to run test suite
  unspentWallet.should.have.property('spendableBalanceString');
  balance = new BigNumber(unspentWallet.spendableBalanceString());

  // Check our balance is over 0.05 tBTC (we spend 0.04, add some cushion)
  minimumBalance = 0.05 * 1e8;
  if (balance.lt(minimumBalance)) {
    throw new Error(`The TBTC wallet ${unspentWallet.id()} does not have enough funds to run the test suite. The current balance is ${balance}. Please fund this wallet!`);
  }

  // Check we have enough in the wallet to run test suite
  sweep1Wallet.should.have.property('spendableBalanceString');
  balance = new BigNumber(sweep1Wallet.spendableBalanceString());

  // Since we will lose our unspents value to fees, make sure there is a large enough balance to continue
  minimumBalance = 0.05 * 1e8;

  if (balance.lt(minimumBalance)) {
    throw new Error(`The TBTC wallet ${sweep1Wallet.id()} does not have enough funds to run the test suite. The current balance is ${balance}. Please fund this wallet!`);
  }
});
开发者ID:BitGo,项目名称:BitGoJS,代码行数:60,代码来源:test_bitgo.ts


示例3: it

 it('should fetch an enterprise eth fee balance', co(function *() {
   const enterprises = bitgo.coin('teth').enterprises();
   const enterprise = (yield enterprises.list())[0];
   const feeBalance = yield enterprise.getFeeAddressBalance();
   feeBalance.should.have.property('balance');
   const balance = new BigNumber(feeBalance.balance);
   balance.greaterThan(1000).should.equal(true);
 }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:8,代码来源:enterprise.ts


示例4: BigNumber

 const comparator = (recipient1, recipient2) => {
   if (recipient1.address !== recipient2.address) {
     return false;
   }
   const amount1 = new BigNumber(recipient1.amount);
   const amount2 = new BigNumber(recipient2.amount);
   return amount1.toFixed() === amount2.toFixed();
 };
开发者ID:BitGo,项目名称:BitGoJS,代码行数:8,代码来源:xrp.ts


示例5: Error

  /**
   * Explain/parse transaction
   * @param params
   * - txBase64: transaction encoded as base64 string
   * @returns {{displayOrder: [string,string,string,string,string], id: *, outputs: Array, changeOutputs: Array}}
   */
  explainTransaction(params) {
    const { txBase64 } = params;
    let tx;

    try {
      tx = new stellar.Transaction(txBase64);
    } catch (e) {
      throw new Error('txBase64 needs to be a valid tx encoded as base64 string');
    }
    const id = tx.hash().toString('hex');
    const explanation: any = {
      displayOrder: ['id', 'outputAmount', 'changeAmount', 'outputs', 'changeOutputs', 'fee', 'memo'],
      id,
      outputs: [],
      changeOutputs: [],
      memo: {}
    };

    // In a Stellar tx, the _memo property is an object with the methods:
    // value() and arm() that provide memo value and type, respectively.
    if (_.result(tx, '_memo.value') && _.result(tx, '_memo.arm')) {
      explanation.memo = {
        value: _.result(tx, '_memo.value').toString(),
        type: _.result(tx, '_memo.arm')
      };
    }

    let spendAmount = new BigNumber(0);
    // Process only operations of the native asset (XLM)
    const operations = _.filter(tx.operations, operation => !operation.asset || operation.asset.getCode() === 'XLM');
    if (_.isEmpty(operations)) {
      throw new Error('missing operations');
    }
    explanation.outputs = _.map(operations, operation => {
      // Get memo to attach to address, if type is 'id'
      const memoId = (_.get(explanation, 'memo.type') === 'id' && ! _.get(explanation, 'memo.value') ? `?memoId=${explanation.memo.value}` : '');
      const output = {
        amount: this.bigUnitsToBaseUnits(operation.startingBalance || operation.amount),
        address: operation.destination + memoId
      };
      spendAmount = spendAmount.plus(output.amount);
      return output;
    });

    explanation.outputAmount = spendAmount.toFixed(0);
    explanation.changeAmount = '0';

    explanation.fee = {
      fee: tx.fee.toFixed(0),
      feeRate: null,
      size: null
    };
    return explanation;
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:60,代码来源:xlm.ts


示例6: at

  /**
   * Calculates rewards at round position.
   * Fees and feesRemaining based on slots
   */
  public at(index: number): { balance: number, fees: number, feesRemaining: number, rewards: number } {
    const rewards       = this.roundRewards[index] ? new Bignum(this.roundRewards[index].toPrecision(15))
      .integerValue(BigNumber.ROUND_FLOOR) : 0;

    return {
      balance      : Number(this.fees.plus(rewards).toFixed()),
      fees         : Number(this.fees.toFixed()),
      feesRemaining: Number(this.feesRemaining.toFixed()),
      rewards      : Number(rewards.toFixed()),
    };
  }
开发者ID:RiseVision,项目名称:rise-node,代码行数:15,代码来源:RoundChanges.ts


示例7: getBigIntBufferSize

export function getBigIntBufferSize (value: BigNumber): number {
  for (let i = 0; i < VAR_INT_SIZES.length; i++) {
    const item = VAR_INT_SIZES[i]
    if (
      value.isGreaterThanOrEqualTo(item.min!) &&
      value.isLessThanOrEqualTo(item.max)
    ) {
      // Fast path: no extra work converting a BigNumber to a String.
      return item.bytes
    }
  }
  return computeBigNumberBufferSize(value)
}
开发者ID:interledger,项目名称:js-oer-utils,代码行数:13,代码来源:util.ts


示例8: scaleValue

      return api.connection.getFeeRef().then(feeRef => {
        const extraFee =
          (txJSON.TransactionType !== 'EscrowFinish' ||
            txJSON.Fulfillment === undefined) ? 0 :
            (cushion * feeRef * (32 + Math.floor(
              Buffer.from(txJSON.Fulfillment, 'hex').length / 16)))
        const feeDrops = common.xrpToDrops(fee)
        const maxFeeXRP = instructions.maxFee ?
          BigNumber.min(api._maxFeeXRP, instructions.maxFee) : api._maxFeeXRP
        const maxFeeDrops = common.xrpToDrops(maxFeeXRP)
        const normalFee = scaleValue(feeDrops, multiplier, extraFee)
        txJSON.Fee = BigNumber.min(normalFee, maxFeeDrops).toString(10)

        return txJSON
      })
开发者ID:ripple,项目名称:ripple-lib,代码行数:15,代码来源:utils.ts


示例9: BigNumber

 paths.alternatives = _.filter(paths.alternatives, alt => {
   if (!alt.source_amount) {
     return false
   }
   const pathfindSourceAmountValue = new BigNumber(
     pathfind.source.amount.currency === 'XRP' ?
     xrpToDrops(pathfind.source.amount.value) :
     pathfind.source.amount.value)
   const altSourceAmountValue = new BigNumber(
     typeof alt.source_amount === 'string' ?
     alt.source_amount :
     alt.source_amount.value
   )
   return altSourceAmountValue.eq(pathfindSourceAmountValue)
 })
开发者ID:ripple,项目名称:ripple-lib,代码行数:15,代码来源:pathfind.ts


示例10: it

  it('Logs one donation and reads it', async () => {
    await db.updateCreator(c_url, c_name);
    const creatorId = (await db.getCreator(c_url)).id;

    const donationId = await db.logDonation(
      creatorId,
      weiAmount.toString(),
      usdAmount.toString(),
      txHash
    );

    const donation = await db.getDonation(donationId);

    expect(donation.weiAmount).toEqual(weiAmount.toString());
    expect(donation.creator_id).not.toBeNull();
  });
开发者ID:ActivityWatch,项目名称:thankful,代码行数:16,代码来源:db.test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript bip32.fromBase58函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bignumber.js.BigNumber类代码示例发布时间: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