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 pingPromise = recordPing(deviceTime, machineVersion, machineModel)
const currentConfigVersionPromise = fetchCurrentConfigVersion() const currentConfigVersionPromise = fetchCurrentConfigVersion()
const currentAvailablePromoCodes = loyalty.getNumberOfAvailablePromoCodes() const currentAvailablePromoCodes = loyalty.getNumberOfAvailablePromoCodes()
const supportsBatchingPromise = cryptoCodes.map(c => wallet.supportsBatching(settings, c))
const timezoneObj = { utcOffset: timezone[0], dstOffset: timezone[1] } const timezoneObj = { utcOffset: timezone[0], dstOffset: timezone[1] }
const promises = [ const promises = [
@ -246,6 +247,7 @@ function plugins (settings, deviceId) {
currentConfigVersionPromise, currentConfigVersionPromise,
timezoneObj timezoneObj
].concat( ].concat(
supportsBatchingPromise,
tickerPromises, tickerPromises,
balancePromises, balancePromises,
testnetPromises, testnetPromises,
@ -258,9 +260,10 @@ function plugins (settings, deviceId) {
const configVersion = arr[2] const configVersion = arr[2]
const tz = arr[3] const tz = arr[3]
const cryptoCodesCount = cryptoCodes.length const cryptoCodesCount = cryptoCodes.length
const tickers = arr.slice(4, cryptoCodesCount + 4) const batchableCoins = arr.slice(4, cryptoCodesCount + 4)
const balances = arr.slice(cryptoCodesCount + 4, 2 * cryptoCodesCount + 4) const tickers = arr.slice(cryptoCodesCount + 4, 2 * cryptoCodesCount + 4)
const testNets = arr.slice(2 * cryptoCodesCount + 4, arr.length - 2) 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 coinParams = _.zip(cryptoCodes, testNets)
const coinsWithoutRate = _.map(mapCoinSettings, coinParams) const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
const areThereAvailablePromoCodes = arr[arr.length - 1] > 0 const areThereAvailablePromoCodes = arr[arr.length - 1] > 0
@ -278,7 +281,9 @@ function plugins (settings, deviceId) {
} }
function sendCoins (tx) { function sendCoins (tx) {
if (wallet.supportsBatching(settings, tx.cryptoCode)) { return wallet.supportsBatching(settings, tx.cryptoCode)
.then(supportsBatching => {
if (supportsBatching) {
return transactionBatching.addTransactionToBatch(tx) return transactionBatching.addTransactionToBatch(tx)
.then(() => ({ .then(() => ({
batched: true, batched: true,
@ -288,6 +293,7 @@ function plugins (settings, deviceId) {
})) }))
} }
return wallet.sendCoins(settings, tx) return wallet.sendCoins(settings, tx)
})
} }
function recordPing (deviceTime, version, model) { 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') .then(() => parseInt(rpcConfig.port, 10) === 18332 ? 'test' : 'main')
} }
function supportsBatching (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => _.isFunction(sendCoinsBatch))
}
module.exports = { module.exports = {
balance, balance,
sendCoins, sendCoins,
newAddress, newAddress,
getStatus, getStatus,
newFunding, 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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
@ -179,5 +184,6 @@ module.exports = {
cryptoNetwork, cryptoNetwork,
fetchRBF, fetchRBF,
estimateFee, estimateFee,
sendCoinsBatch sendCoinsBatch,
supportsBatching
} }

View file

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

View file

@ -29,7 +29,8 @@ module.exports = {
newFunding, newFunding,
privateKey, privateKey,
isStrictAddress, isStrictAddress,
connect connect,
supportsBatching
} }
function connect (url) { 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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
newAddress, newAddress,
getStatus, getStatus,
newFunding newFunding,
supportsBatching
} }

View file

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

View file

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