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:
parent
c8adaabf85
commit
73c0d09198
7 changed files with 154 additions and 6 deletions
|
|
@ -81,13 +81,18 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
|
|||
|
||||
function sendCoinsBatch (account, txs, cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => calculateFeeDiscount(feeMultiplier))
|
||||
.then(newFee => fetch('settxfee', [newFee]))
|
||||
.then(() => {
|
||||
const txAddressAmountPairs = _.map(tx => [tx.address, tx.cryptoAtoms.shift(-unitScale).toFixed(8)], txs)
|
||||
return Promise.all([JSON.stringify(_.fromPairs(txAddressAmountPairs))])
|
||||
})
|
||||
.then(([obj]) => fetch('sendmany', ['', obj]))
|
||||
.then(res => ({
|
||||
txid: res.txid
|
||||
.then((txId) => fetch('gettransaction', [txId]))
|
||||
.then((res) => _.pick(['fee', 'txid'], res))
|
||||
.then((pickedObj) => ({
|
||||
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||
txid: pickedObj.txid
|
||||
}))
|
||||
.catch(err => {
|
||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||
|
|
@ -173,5 +178,6 @@ module.exports = {
|
|||
newFunding,
|
||||
cryptoNetwork,
|
||||
fetchRBF,
|
||||
estimateFee
|
||||
estimateFee,
|
||||
sendCoinsBatch
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue