coinUtils fixes
This commit is contained in:
parent
b7aa655587
commit
5a26f718c5
9 changed files with 63 additions and 71 deletions
|
|
@ -1,22 +1,19 @@
|
|||
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 = 9998
|
||||
const SATOSHI_SHIFT = 8
|
||||
|
||||
const configPath = path.resolve(options.blockchainDir, 'dash.conf')
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
|
||||
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) {
|
||||
|
|
@ -31,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
|
||||
|
|
@ -41,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]))
|
||||
|
|
@ -58,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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue