feat: add crypto reservation for batched transaction
This commit is contained in:
parent
0132227251
commit
008dd3e9f6
4 changed files with 49 additions and 24 deletions
|
|
@ -13,6 +13,8 @@ const ph = require('./plugin-helper')
|
|||
const layer2 = require('./layer2')
|
||||
const httpError = require('./route-helpers').httpError
|
||||
const logger = require('./logger')
|
||||
const { getOpenBatchCryptoValue } = require('./tx-batching')
|
||||
const BN = require('./bn')
|
||||
|
||||
const FETCH_INTERVAL = 5000
|
||||
const INSUFFICIENT_FUNDS_CODE = 570
|
||||
|
|
@ -46,7 +48,9 @@ const lastBalance = {}
|
|||
function _balance (settings, cryptoCode) {
|
||||
return fetchWallet(settings, cryptoCode)
|
||||
.then(r => r.wallet.balance(r.account, cryptoCode, settings, r.operatorId))
|
||||
.then(balance => ({ balance, timestamp: Date.now() }))
|
||||
.then(balance => Promise.all([balance, supportsBatching(settings, cryptoCode)]))
|
||||
.then(([balance, supportsBatching]) => Promise.all([balance, supportsBatching ? getOpenBatchCryptoValue(cryptoCode) : Promise.resolve(BN(0))]))
|
||||
.then(([balance, reservedBalance]) => ({ balance: balance.minus(reservedBalance), reservedBalance, timestamp: Date.now() }))
|
||||
.then(r => {
|
||||
lastBalance[cryptoCode] = r
|
||||
return r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue