coinUtils fixes

This commit is contained in:
Josh Harvey 2017-07-09 13:31:01 +03:00
parent b7aa655587
commit 5a26f718c5
9 changed files with 63 additions and 71 deletions

View file

@ -1,20 +1,18 @@
const jsonRpc = require('../../common/json-rpc')
const path = require('path')
const options = require('../../../options')
const BN = require('../../../bn')
const E = require('../../../error')
const coinUtils = require('../../../coin-utils')
const DEFAULT_PORT = 8332
const SATOSHI_SHIFT = 8
const configPath = path.resolve(options.blockchainDir, 'bitcoin.conf')
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
const configPath = coinUtils.cryptoDir(cryptoRec)
const unitScale = cryptoRec.unitScale
const config = jsonRpc.parseConf(configPath)
const rpcConfig = {
username: config.rpcuser,
password: config.rpcpassword,
port: config.rpcport || DEFAULT_PORT
port: config.rpcport || cryptoRec.defaultPort
}
function fetch (method, params) {
@ -29,7 +27,7 @@ function checkCryptoCode (cryptoCode) {
function accountBalance (acount, cryptoCode, confirmations) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['', confirmations]))
.then(r => BN(r).shift(SATOSHI_SHIFT).round())
.then(r => BN(r).shift(unitScale).round())
}
// We want a balance that includes all spends (0 conf) but only deposits that
@ -39,7 +37,7 @@ function balance (account, cryptoCode) {
}
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
const coins = cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)
const coins = cryptoAtoms.shift(-unitScale).toFixed(8)
return checkCryptoCode(cryptoCode)
.then(() => fetch('sendtoaddress', [address, coins]))
@ -56,7 +54,7 @@ function newAddress (account, info) {
function addressBalance (address, confs) {
return fetch('getreceivedbyaddress', [address, confs])
.then(r => BN(r).shift(SATOSHI_SHIFT).round())
.then(r => BN(r).shift(unitScale).round())
}
function confirmedBalance (address, cryptoCode) {