fix: check for wallet tx batching support

This commit is contained in:
Sérgio Salgado 2021-05-24 16:16:51 +01:00
parent 73c0d09198
commit 8289c55acf
10 changed files with 77 additions and 26 deletions

View file

@ -238,6 +238,7 @@ function plugins (settings, deviceId) {
const pingPromise = recordPing(deviceTime, machineVersion, machineModel)
const currentConfigVersionPromise = fetchCurrentConfigVersion()
const currentAvailablePromoCodes = loyalty.getNumberOfAvailablePromoCodes()
const supportsBatchingPromise = cryptoCodes.map(c => wallet.supportsBatching(settings, c))
const timezoneObj = { utcOffset: timezone[0], dstOffset: timezone[1] }
const promises = [
@ -246,6 +247,7 @@ function plugins (settings, deviceId) {
currentConfigVersionPromise,
timezoneObj
].concat(
supportsBatchingPromise,
tickerPromises,
balancePromises,
testnetPromises,
@ -258,9 +260,10 @@ function plugins (settings, deviceId) {
const configVersion = arr[2]
const tz = arr[3]
const cryptoCodesCount = cryptoCodes.length
const tickers = arr.slice(4, cryptoCodesCount + 4)
const balances = arr.slice(cryptoCodesCount + 4, 2 * cryptoCodesCount + 4)
const testNets = arr.slice(2 * cryptoCodesCount + 4, arr.length - 2)
const batchableCoins = arr.slice(4, cryptoCodesCount + 4)
const tickers = arr.slice(cryptoCodesCount + 4, 2 * cryptoCodesCount + 4)
const balances = arr.slice(2 * cryptoCodesCount + 4, 3 * cryptoCodesCount + 4)
const testNets = arr.slice(3 * cryptoCodesCount + 4, arr.length - 1)
const coinParams = _.zip(cryptoCodes, testNets)
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
const areThereAvailablePromoCodes = arr[arr.length - 1] > 0
@ -278,16 +281,19 @@ function plugins (settings, deviceId) {
}
function sendCoins (tx) {
if (wallet.supportsBatching(settings, tx.cryptoCode)) {
return transactionBatching.addTransactionToBatch(tx)
.then(() => ({
batched: true,
sendPending: false,
error: null,
errorCode: null
}))
}
return wallet.sendCoins(settings, tx)
return wallet.supportsBatching(settings, tx.cryptoCode)
.then(supportsBatching => {
if (supportsBatching) {
return transactionBatching.addTransactionToBatch(tx)
.then(() => ({
batched: true,
sendPending: false,
error: null,
errorCode: null
}))
}
return wallet.sendCoins(settings, tx)
})
}
function recordPing (deviceTime, version, model) {

View file

@ -129,11 +129,17 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) {
.then(() => parseInt(rpcConfig.port, 10) === 18332 ? 'test' : 'main')
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
balance,
sendCoins,
newAddress,
getStatus,
newFunding,
cryptoNetwork
cryptoNetwork,
supportsBatching
}

View file

@ -170,6 +170,11 @@ function fetchRBF (txId) {
})
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
balance,
sendCoins,
@ -179,5 +184,6 @@ module.exports = {
cryptoNetwork,
fetchRBF,
estimateFee,
sendCoinsBatch
sendCoinsBatch,
supportsBatching
}

View file

@ -157,6 +157,11 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) {
.then(() => account.environment === 'test' ? 'test' : 'main')
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
NAME,
balance,
@ -164,5 +169,6 @@ module.exports = {
newAddress,
getStatus,
newFunding,
cryptoNetwork
cryptoNetwork,
supportsBatching
}

View file

@ -112,10 +112,16 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
balance,
sendCoins,
newAddress,
getStatus,
newFunding
newFunding,
supportsBatching
}

View file

@ -29,7 +29,8 @@ module.exports = {
newFunding,
privateKey,
isStrictAddress,
connect
connect,
supportsBatching
}
function connect (url) {
@ -222,3 +223,8 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
})
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}

View file

@ -112,10 +112,16 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
balance,
sendCoins,
newAddress,
getStatus,
newFunding
newFunding,
supportsBatching
}

View file

@ -3,8 +3,10 @@ const _ = require('lodash/fp')
const BN = require('../../../bn')
const E = require('../../../error')
const { utils: coinUtils } = require('lamassu-coins')
const consoleLogLevel = require('console-log-level')
const NAME = 'FakeWallet'
const BATCHABLE_COINS = ['BTC']
const SECONDS = 1000
const PUBLISH_TIME = 3 * SECONDS
@ -59,9 +61,6 @@ 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) => {
@ -81,7 +80,6 @@ function sendCoinsBatch (account, txs, cryptoCode) {
}
function newAddress () {
>>>>>>> feat: add transaction batching module
t0 = Date.now()
return Promise.resolve('<Fake address, don\'t send>')
}
@ -114,6 +112,10 @@ function getStatus (account, tx, requested, settings, operatorId) {
return Promise.resolve({status: 'confirmed'})
}
function supportsBatching (account, cryptoCode) {
return Promise.resolve(_.includes(cryptoCode, BATCHABLE_COINS))
}
module.exports = {
NAME,
balance,
@ -121,5 +123,6 @@ module.exports = {
sendCoins,
newAddress,
getStatus,
newFunding
newFunding,
supportsBatching
}

View file

@ -138,10 +138,16 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = {
balance,
sendCoins,
newAddress,
getStatus,
newFunding
newFunding,
supportsBatching
}

View file

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