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,26 +1,21 @@
const jsonRpc = require('../../common/json-rpc')
const path = require('path')
const options = require('../../../options')
const coinUtils = require('../../../coin-utils')
const BN = require('../../../bn')
const E = require('../../../error')
const DEFAULT_PORT = 9332
const SATOSHI_SHIFT = 8
const configPath = path.resolve(options.blockchainDir, 'litecoin.conf')
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
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
}
console.log('DEBUG101: %j', configPath)
console.log('DEBUG100: %j', rpcConfig)
function fetch (method, params) {
return jsonRpc.fetch(rpcConfig, method, params)
}
@ -33,7 +28,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
@ -43,7 +38,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]))
@ -60,7 +55,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) {