本文整理汇总了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)
}
示例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!`);
}
});
示例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);
}));
示例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();
};
示例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;
}
示例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()),
};
}
示例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)
}
示例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
})
示例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)
})
示例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();
});