generalize bitcoind json-rpc

This commit is contained in:
Josh Harvey 2017-06-26 12:19:14 +03:00
parent f70211d774
commit 2c525c1e5c
11 changed files with 468 additions and 121 deletions

View file

@ -1,5 +1,6 @@
const BN = require('../../../bn')
const E = require('../../../error')
const coinUtils = require('../../../coin-utils')
const NAME = 'FakeWallet'
@ -10,44 +11,31 @@ const CONFIRM_TIME = 180 * SECONDS
let t0
function _balance (cryptoCode) {
const unitScale = coinUtils.unitScale(cryptoCode)
return BN(10).pow(unitScale).mul(10)
}
function balance (account, cryptoCode) {
return Promise.resolve()
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10)
if (cryptoCode === 'ETH') return BN(1e18 * 10)
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
.then(() => _balance(cryptoCode))
}
function pendingBalance (account, cryptoCode) {
return Promise.resolve()
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10.1)
if (cryptoCode === 'ETH') return BN(1e18 * 10.1)
if (cryptoCode === 'ZEC') return BN(1e8 * 10.1)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
return balance(account, cryptoCode)
.then(b => b.mul(1.1))
}
function confirmedBalance (account, cryptoCode) {
return Promise.resolve()
.then(() => {
if (cryptoCode === 'BTC') return BN(1e8 * 10)
if (cryptoCode === 'ETH') return BN(1e18 * 10)
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
throw new Error('Unsupported crypto: ' + cryptoCode)
})
return balance(account, cryptoCode)
}
// Note: This makes it easier to test insufficient funds errors
let sendCount = 100
function isInsufficient (cryptoAtoms, cryptoCode) {
if (cryptoCode === 'BTC') return cryptoAtoms.gt(1e5 * 10 * sendCount)
if (cryptoCode === 'ETH') return cryptoAtoms.gt(1e18 * 0.25 * sendCount)
if (cryptoCode === 'ZEC') return cryptoAtoms.gt(1e5 * 0.25 * sendCount)
throw new Error('Unsupported crypto: ' + cryptoCode)
const b = _balance(cryptoCode)
return cryptoAtoms.gt(b.div(1000).mul(sendCount))
}
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {