From 68d9d95dfa22220664f22ffb3f2f1105fecd15f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 3 Feb 2022 17:11:48 +0000 Subject: [PATCH] feat: add transaction batching option to advanced wallet settings --- .../wallet/bitcoincashd/bitcoincashd.js | 8 ------- lib/plugins/wallet/bitcoind/bitcoind.js | 7 ------- lib/plugins/wallet/bitgo/bitgo.js | 8 ------- lib/plugins/wallet/dashd/dashd.js | 7 ------- lib/plugins/wallet/geth/base.js | 8 ------- lib/plugins/wallet/litecoind/litecoind.js | 7 ------- lib/plugins/wallet/mock-wallet/mock-wallet.js | 6 ------ lib/plugins/wallet/monerod/monerod.js | 8 ------- lib/plugins/wallet/zcashd/zcashd.js | 7 ------- lib/wallet.js | 3 +-- .../src/pages/Wallet/AdvancedWallet.js | 9 ++++++-- new-lamassu-admin/src/pages/Wallet/helper.js | 21 +++++++++++++++---- 12 files changed, 25 insertions(+), 74 deletions(-) diff --git a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js index 4bc7a0fd..76d23295 100644 --- a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js +++ b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js @@ -8,8 +8,6 @@ const { utils: coinUtils } = require('lamassu-coins') const cryptoRec = coinUtils.getCryptoCurrency('BCH') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = false - const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { @@ -118,11 +116,6 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) { .then(() => parseInt(rpcConfig.port, 10) === 18332 ? 'test' : 'main') } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) @@ -136,6 +129,5 @@ module.exports = { getStatus, newFunding, cryptoNetwork, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 3075a3fa..fb146e6b 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -9,7 +9,6 @@ const { utils: coinUtils } = require('lamassu-coins') const cryptoRec = coinUtils.getCryptoCurrency('BTC') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = true const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { @@ -171,11 +170,6 @@ function fetchRBF (txId) { }) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) @@ -192,6 +186,5 @@ module.exports = { fetchRBF, estimateFee, sendCoinsBatch, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/bitgo/bitgo.js b/lib/plugins/wallet/bitgo/bitgo.js index c7c22abd..868ca80f 100644 --- a/lib/plugins/wallet/bitgo/bitgo.js +++ b/lib/plugins/wallet/bitgo/bitgo.js @@ -14,8 +14,6 @@ const NAME = 'BitGo' const SUPPORTED_COINS = ['BTC', 'ZEC', 'LTC', 'BCH', 'DASH'] const BCH_CODES = ['BCH', 'TBCH'] -const SUPPORTS_BATCHING = false - function buildBitgo (account) { const env = account.environment === 'test' ? 'test' : 'prod' return new BitGo.BitGo({ accessToken: account.token.trim(), env, userAgent: userAgent }) @@ -159,11 +157,6 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) { .then(() => account.environment === 'test' ? 'test' : 'main') } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => Promise.resolve('ready')) @@ -177,6 +170,5 @@ module.exports = { getStatus, newFunding, cryptoNetwork, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index b28e3d59..439b1fdd 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -9,7 +9,6 @@ const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('DASH') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = false const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { @@ -113,11 +112,6 @@ function newFunding (account, cryptoCode, settings, operatorId) { })) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) @@ -130,6 +124,5 @@ module.exports = { newAddress, getStatus, newFunding, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index 64b890c1..f7ecbcd5 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -17,8 +17,6 @@ const paymentPrefixPath = "m/44'/60'/0'/0'" const defaultPrefixPath = "m/44'/60'/1'/0'" let lastUsedNonces = {} -const SUPPORTS_BATCHING = false - module.exports = { NAME, balance, @@ -32,7 +30,6 @@ module.exports = { privateKey, isStrictAddress, connect, - supportsBatching, checkBlockchainStatus } @@ -227,11 +224,6 @@ function newFunding (account, cryptoCode, settings, operatorId) { }) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(pify(web3.eth.isSyncing)) diff --git a/lib/plugins/wallet/litecoind/litecoind.js b/lib/plugins/wallet/litecoind/litecoind.js index 7ae5f9b2..df92edeb 100644 --- a/lib/plugins/wallet/litecoind/litecoind.js +++ b/lib/plugins/wallet/litecoind/litecoind.js @@ -9,7 +9,6 @@ const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('LTC') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = false const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { @@ -113,11 +112,6 @@ function newFunding (account, cryptoCode, settings, operatorId) { })) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) @@ -130,6 +124,5 @@ module.exports = { newAddress, getStatus, newFunding, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/mock-wallet/mock-wallet.js b/lib/plugins/wallet/mock-wallet/mock-wallet.js index 9b17e4ad..5ffc88e1 100644 --- a/lib/plugins/wallet/mock-wallet/mock-wallet.js +++ b/lib/plugins/wallet/mock-wallet/mock-wallet.js @@ -5,7 +5,6 @@ const E = require('../../../error') const { utils: coinUtils } = require('lamassu-coins') const NAME = 'FakeWallet' -const BATCHABLE_COINS = ['BTC'] const SECONDS = 1000 const PUBLISH_TIME = 3 * SECONDS @@ -111,10 +110,6 @@ function getStatus (account, tx, requested, settings, operatorId) { return Promise.resolve({status: 'confirmed'}) } -function supportsBatching (cryptoCode) { - return Promise.resolve(_.includes(cryptoCode, BATCHABLE_COINS)) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => Promise.resolve('ready')) @@ -128,6 +123,5 @@ module.exports = { newAddress, getStatus, newFunding, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 3b85088c..34c3d351 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -17,8 +17,6 @@ const configPath = utils.configPath(cryptoRec, blockchainDir) const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainDir), 'wallets') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = false - function rpcConfig () { try { const config = jsonRpc.parseConf(configPath) @@ -200,11 +198,6 @@ function cryptoNetwork (account, cryptoCode) { }) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => { @@ -236,6 +229,5 @@ module.exports = { getStatus, newFunding, cryptoNetwork, - supportsBatching, checkBlockchainStatus } diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index bc8c30c4..e5683cd8 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -9,7 +9,6 @@ const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('ZEC') const unitScale = cryptoRec.unitScale -const SUPPORTS_BATCHING = false const rpcConfig = jsonRpc.rpcConfig(cryptoRec) @@ -139,11 +138,6 @@ function newFunding (account, cryptoCode, settings, operatorId) { })) } -function supportsBatching (cryptoCode) { - return checkCryptoCode(cryptoCode) - .then(() => SUPPORTS_BATCHING) -} - function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) @@ -156,6 +150,5 @@ module.exports = { newAddress, getStatus, newFunding, - supportsBatching, checkBlockchainStatus } diff --git a/lib/wallet.js b/lib/wallet.js index 2b39f260..902a24c5 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -233,8 +233,7 @@ function isStrictAddress (settings, cryptoCode, toAddress) { } function supportsBatching (settings, cryptoCode) { - return fetchWallet(settings, cryptoCode) - .then(r => r.wallet.supportsBatching(cryptoCode)) + return Promise.resolve(!!configManager.getWalletSettings(cryptoCode, settings.config).allowTransactionBatching) } function checkBlockchainStatus (settings, cryptoCode) { diff --git a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js index e326c720..8897c534 100644 --- a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js +++ b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js @@ -7,7 +7,11 @@ import React from 'react' import { NamespacedTable as EditableTable } from 'src/components/editableTable' import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' -import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper' +import { + WalletSchema, + AdvancedWalletSchema, + getAdvancedWalletElements +} from './helper' const SAVE_CONFIG = gql` mutation Save($config: JSONObject, $accounts: JSONObject) { @@ -51,8 +55,9 @@ const AdvancedWallet = () => { enableEdit editWidth={174} save={save} + stripeWhen={it => !WalletSchema.isValidSync(it)} validationSchema={AdvancedWalletSchema} - elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils)} + elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils, config)} /> ) } diff --git a/new-lamassu-admin/src/pages/Wallet/helper.js b/new-lamassu-admin/src/pages/Wallet/helper.js index 226dbd66..bcfc493a 100644 --- a/new-lamassu-admin/src/pages/Wallet/helper.js +++ b/new-lamassu-admin/src/pages/Wallet/helper.js @@ -1,8 +1,11 @@ import * as R from 'ramda' import * as Yup from 'yup' -import { NumberInput } from 'src/components/inputs/formik' -import Autocomplete from 'src/components/inputs/formik/Autocomplete.js' +import { + Autocomplete, + Checkbox, + NumberInput +} from 'src/components/inputs/formik' import { disabledColor } from 'src/styling/variables' import { CURRENCY_MAX } from 'src/utils/constants' import { transformNumber } from 'src/utils/number' @@ -29,10 +32,11 @@ const WalletSchema = Yup.object().shape({ }) const AdvancedWalletSchema = Yup.object().shape({ - cryptoUnits: Yup.string().required() + cryptoUnits: Yup.string().required(), + allowTransactionBatching: Yup.boolean().required() }) -const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => { +const getAdvancedWalletElements = (cryptoCurrencies, coinUtils, config) => { const viewCryptoCurrency = it => R.compose( R.prop(['display']), @@ -66,6 +70,15 @@ const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => { valueProp: 'code', labelProp: 'display' } + }, + { + name: 'allowTransactionBatching', + size: 'sm', + stripe: true, + width: 250, + view: (_, ite) => + config[`${ite.id}_allowTransactionBatching`] ? 'Yes' : 'No', + input: Checkbox } ] }