feat: add transaction batching module

feat: plugin sendCoins batching support
feat: batching processing on poller
feat: mock-wallet batching
fix: bitcoin tx batching
fix: transaction batching db table
This commit is contained in:
Sérgio Salgado 2021-05-24 02:53:36 +01:00
parent c8adaabf85
commit 73c0d09198
7 changed files with 154 additions and 6 deletions

View file

@ -1,3 +1,5 @@
const _ = require('lodash/fp')
const BN = require('../../../bn')
const E = require('../../../error')
const { utils: coinUtils } = require('lamassu-coins')
@ -57,7 +59,29 @@ function sendCoins (account, tx, settings, operatorId) {
})
}
<<<<<<< HEAD
function newAddress (account, info, tx, settings, operatorId) {
=======
function sendCoinsBatch (account, txs, cryptoCode) {
sendCount = sendCount + txs.length
return new Promise((resolve, reject) => {
setTimeout(() => {
const cryptoSum = _.reduce((acc, value) => acc.add(value.crypto_atoms), BN(0), txs)
if (isInsufficient(cryptoSum, cryptoCode)) {
console.log('[%s] DEBUG: Mock wallet insufficient funds: %s',
cryptoCode, cryptoSum.toString())
return reject(new E.InsufficientFundsError())
}
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms in a batch',
cryptoCode, cryptoSum.toString())
return resolve({ txid: '<txHash>', fee: BN(0) })
}, 2000)
})
}
function newAddress () {
>>>>>>> feat: add transaction batching module
t0 = Date.now()
return Promise.resolve('<Fake address, don\'t send>')
}
@ -93,6 +117,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
module.exports = {
NAME,
balance,
sendCoinsBatch,
sendCoins,
newAddress,
getStatus,