feat: add batch_id to cash_in_txs

feat: bitcoind sendmany request
feat: check if wallet supports transaction batching
This commit is contained in:
Sérgio Salgado 2021-05-21 16:21:54 +01:00
parent 24ed69244c
commit c8adaabf85
3 changed files with 43 additions and 0 deletions

View file

@ -79,6 +79,22 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
})
}
function sendCoinsBatch (account, txs, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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
}))
.catch(err => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err
})
}
function newAddress (account, info, tx, settings, operatorId) {
return checkCryptoCode(info.cryptoCode)
.then(() => fetch('getnewaddress'))

View file

@ -210,6 +210,11 @@ function isStrictAddress (settings, cryptoCode, toAddress) {
})
}
function supportsBatching (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => _.isFunction(r.wallet.sendCoinsBatch))
}
const coinFilter = ['ETH']
const balance = (settings, cryptoCode) => {

View file

@ -0,0 +1,22 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TYPE transaction_batch_status AS ENUM('open', 'failed', 'sent')`,
`CREATE TABLE transaction_batches (
id UUID PRIMARY KEY,
crypto_code TEXT NOT NULL,
status transaction_batch_status NOT NULL DEFAULT 'open',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
closed_at TIMESTAMPTZ,
error_message TEXT
)`,
`ALTER TABLE cash_in_txs ADD COLUMN batch_id REFERENCES transaction_batches(id)`
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}