feat: backport remote BTC node support

This commit is contained in:
Sérgio Salgado 2023-02-01 15:16:35 +00:00
parent 24473de6d5
commit 1b6ba5e6dc
15 changed files with 272 additions and 55 deletions

View file

@ -5,6 +5,7 @@ const BN = require('../../../bn')
const E = require('../../../error')
const logger = require('../../../logger')
const { utils: coinUtils } = require('@lamassu/coins')
const { isDevMode } = require('../../../environment-helper')
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
const unitScale = cryptoRec.unitScale
@ -36,15 +37,15 @@ function checkCryptoCode (cryptoCode) {
function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getwalletinfo'))
.then(({ balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0))
.then(() => fetch('getbalances'))
.then(({ mine }) => new BN(mine.trusted).shiftedBy(unitScale).decimalPlaces(0))
.catch(errorHandle)
}
function accountUnconfirmedBalance (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getwalletinfo'))
.then(({ unconfirmed_balance: balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0))
.then(() => fetch('getbalances'))
.then(({ mine }) => new BN(mine.untrusted_pending).plus(mine.immature).shiftedBy(unitScale).decimalPlaces(0))
.catch(errorHandle)
}
@ -62,7 +63,7 @@ function estimateFee () {
function calculateFeeDiscount (feeMultiplier) {
// 0 makes bitcoind do automatic fee selection
const AUTOMATIC_FEE = 0
const AUTOMATIC_FEE = isDevMode() ? 0.01 : 0
if (!feeMultiplier || feeMultiplier.eq(1)) return AUTOMATIC_FEE
return estimateFee()
.then(estimatedFee => {