feat: add tx hash retrieval in wallet plugin

This commit is contained in:
José Oliveira 2022-07-19 20:14:40 +01:00
parent 3b01820242
commit 708dea736d
7 changed files with 56 additions and 6 deletions

View file

@ -129,6 +129,13 @@ function checkBlockchainStatus (cryptoCode) {
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') .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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
@ -136,5 +143,6 @@ module.exports = {
getStatus, getStatus,
newFunding, newFunding,
cryptoNetwork, cryptoNetwork,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }

View file

@ -191,6 +191,13 @@ function checkBlockchainStatus (cryptoCode) {
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') .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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
@ -202,5 +209,6 @@ module.exports = {
estimateFee, estimateFee,
sendCoinsBatch, sendCoinsBatch,
checkBlockchainStatus, checkBlockchainStatus,
getTxHashesByAddress,
SUPPORTS_BATCHING SUPPORTS_BATCHING
} }

View file

@ -125,11 +125,19 @@ function checkBlockchainStatus (cryptoCode) {
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') .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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
newAddress, newAddress,
getStatus, getStatus,
newFunding, newFunding,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }

View file

@ -32,7 +32,8 @@ module.exports = {
privateKey, privateKey,
isStrictAddress, isStrictAddress,
connect, connect,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }
const infuraCalls = {} const infuraCalls = {}
@ -62,6 +63,10 @@ function isStrictAddress (cryptoCode, toAddress, settings, operatorId) {
return cryptoCode === 'ETH' && util.isValidChecksumAddress(toAddress) 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) { function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
const { toAddress, cryptoAtoms, cryptoCode } = tx const { toAddress, cryptoAtoms, cryptoCode } = tx
const isErc20Token = coins.utils.isErc20Token(cryptoCode) const isErc20Token = coins.utils.isErc20Token(cryptoCode)

View file

@ -125,11 +125,16 @@ function checkBlockchainStatus (cryptoCode) {
.then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready')
} }
function getTxHashesByAddress (cryptoCode, address) {
throw new Error(`Transactions hash retrieval not implemented for this coin!`)
}
module.exports = { module.exports = {
balance, balance,
sendCoins, sendCoins,
newAddress, newAddress,
getStatus, getStatus,
newFunding, newFunding,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }

View file

@ -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 = { module.exports = {
balance, balance,
sendCoins, sendCoins,
@ -242,5 +250,6 @@ module.exports = {
getStatus, getStatus,
newFunding, newFunding,
cryptoNetwork, cryptoNetwork,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }

View file

@ -151,11 +151,18 @@ function checkBlockchainStatus (cryptoCode) {
.then(res => !!res['initial_block_download_complete'] ? 'ready' : 'syncing') .then(res => !!res['initial_block_download_complete'] ? 'ready' : 'syncing')
} }
function getTxHashesByAddress (cryptoCode, address) {
checkCryptoCode(cryptoCode)
.then(() => fetch('getaddresstxids', [address]))
.then(_.mapKeys(() => 'txid'))
}
module.exports = { module.exports = {
balance, balance,
sendCoins, sendCoins,
newAddress, newAddress,
getStatus, getStatus,
newFunding, newFunding,
checkBlockchainStatus checkBlockchainStatus,
getTxHashesByAddress
} }