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
29
lib/tx-batching-processing.js
Normal file
29
lib/tx-batching-processing.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const txBatching = require('./tx-batching')
|
||||
const wallet = require('./wallet')
|
||||
|
||||
function submitBatch (settings, batch) {
|
||||
txBatching.getBatchTransactions(batch)
|
||||
.then(txs => {
|
||||
wallet.sendCoinsBatch(settings, txs, batch.crypto_code)
|
||||
.then(res => txBatching.confirmSentBatch(batch, res))
|
||||
.catch(err => txBatching.setErroredBatch(batch, err.message))
|
||||
})
|
||||
}
|
||||
|
||||
function processBatches (settings, lifecycle) {
|
||||
return txBatching.getBatchesByStatus(['open'])
|
||||
.then(batches => {
|
||||
_.each(batch => {
|
||||
const elapsedMS = batch.time_elapsed * 1000
|
||||
|
||||
if (elapsedMS >= lifecycle) {
|
||||
return txBatching.closeTransactionBatch(batch)
|
||||
.then(() => submitBatch(settings, batch))
|
||||
}
|
||||
}, batches)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = processBatches
|
||||
Loading…
Add table
Add a link
Reference in a new issue