From 708dea736db18061715b57e00e14382201e1749c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Tue, 19 Jul 2022 20:14:40 +0100 Subject: [PATCH] feat: add tx hash retrieval in wallet plugin --- lib/plugins/wallet/bitcoincashd/bitcoincashd.js | 10 +++++++++- lib/plugins/wallet/bitcoind/bitcoind.js | 8 ++++++++ lib/plugins/wallet/dashd/dashd.js | 10 +++++++++- lib/plugins/wallet/geth/base.js | 7 ++++++- lib/plugins/wallet/litecoind/litecoind.js | 7 ++++++- lib/plugins/wallet/monerod/monerod.js | 11 ++++++++++- lib/plugins/wallet/zcashd/zcashd.js | 9 ++++++++- 7 files changed, 56 insertions(+), 6 deletions(-) diff --git a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js index 18a5c96a..9fb3cd09 100644 --- a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js +++ b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js @@ -129,6 +129,13 @@ function checkBlockchainStatus (cryptoCode) { .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } +function getTxHashesByAddress (cryptoCode, address) { + checkCryptoCode(cryptoCode) + .then(() => fetch('listreceivedbyaddress', [0, true, true, address])) + .then(txsByAddress => Promise.all(_.forEach(id => fetch('getrawtransaction', [id]), _.head(txsByAddress).txids))) + .then(_.map(({ hash }) => hash)) +} + module.exports = { balance, sendCoins, @@ -136,5 +143,6 @@ module.exports = { getStatus, newFunding, cryptoNetwork, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 43e994b8..2a52e01b 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -191,6 +191,13 @@ function checkBlockchainStatus (cryptoCode) { .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } +function getTxHashesByAddress (cryptoCode, address) { + checkCryptoCode(cryptoCode) + .then(() => fetch('listreceivedbyaddress', [0, true, true, address])) + .then(txsByAddress => Promise.all(_.forEach(id => fetch('getrawtransaction', [id]), _.head(txsByAddress).txids))) + .then(_.map(({ hash }) => hash)) +} + module.exports = { balance, sendCoins, @@ -202,5 +209,6 @@ module.exports = { estimateFee, sendCoinsBatch, checkBlockchainStatus, + getTxHashesByAddress, SUPPORTS_BATCHING } diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index 57d3ccc8..9b84a6a0 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -125,11 +125,19 @@ function checkBlockchainStatus (cryptoCode) { .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } +function getTxHashesByAddress (cryptoCode, address) { + checkCryptoCode(cryptoCode) + .then(() => fetch('listreceivedbyaddress', [0, true, true, true, address])) + .then(txsByAddress => Promise.all(_.forEach(id => fetch('getrawtransaction', [id]), _.head(txsByAddress).txids))) + .then(_.map(({ hash }) => hash)) +} + module.exports = { balance, sendCoins, newAddress, getStatus, newFunding, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index bdd7ac55..6c75adfd 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -32,7 +32,8 @@ module.exports = { privateKey, isStrictAddress, connect, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } const infuraCalls = {} @@ -62,6 +63,10 @@ function isStrictAddress (cryptoCode, toAddress, settings, operatorId) { return cryptoCode === 'ETH' && util.isValidChecksumAddress(toAddress) } +function getTxHashesByAddress (cryptoCode, address) { + throw new Error(`Transactions hash retrieval is not implemented for this coin!`) +} + function sendCoins (account, tx, settings, operatorId, feeMultiplier) { const { toAddress, cryptoAtoms, cryptoCode } = tx const isErc20Token = coins.utils.isErc20Token(cryptoCode) diff --git a/lib/plugins/wallet/litecoind/litecoind.js b/lib/plugins/wallet/litecoind/litecoind.js index 2168dde8..61dc1f9e 100644 --- a/lib/plugins/wallet/litecoind/litecoind.js +++ b/lib/plugins/wallet/litecoind/litecoind.js @@ -125,11 +125,16 @@ function checkBlockchainStatus (cryptoCode) { .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } +function getTxHashesByAddress (cryptoCode, address) { + throw new Error(`Transactions hash retrieval not implemented for this coin!`) +} + module.exports = { balance, sendCoins, newAddress, getStatus, newFunding, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index e70b32ad..1ed93bf8 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -235,6 +235,14 @@ function checkBlockchainStatus (cryptoCode) { }) } +function getTxHashesByAddress (cryptoCode, address) { + checkCryptoCode(cryptoCode) + .then(() => refreshWallet()) + .then(() => fetch('get_address_index', { address: address })) + .then(addressRes => fetch('get_transfers', { in: true, pool: true, pending: true, account_index: addressRes.index.major, address_indices: [addressRes.index.minor] })) + .then(_.map(({ txid }) => txid)) +} + module.exports = { balance, sendCoins, @@ -242,5 +250,6 @@ module.exports = { getStatus, newFunding, cryptoNetwork, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index b55d1ec5..d9d7f867 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -151,11 +151,18 @@ function checkBlockchainStatus (cryptoCode) { .then(res => !!res['initial_block_download_complete'] ? 'ready' : 'syncing') } +function getTxHashesByAddress (cryptoCode, address) { + checkCryptoCode(cryptoCode) + .then(() => fetch('getaddresstxids', [address])) + .then(_.mapKeys(() => 'txid')) +} + module.exports = { balance, sendCoins, newAddress, getStatus, newFunding, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress }