Merge pull request #1340 from josepfo/feat/get-tx-hashes-for-address
Feat/get tx hashes for address
This commit is contained in:
commit
0cdd1d7801
10 changed files with 91 additions and 20 deletions
|
|
@ -52,17 +52,24 @@ function isValidWalletScore (account, score) {
|
||||||
return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold)
|
return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTransactionHash (account, cryptoCode, receivingAddress) {
|
function getAddressTransactionsHashes (receivingAddress, cryptoCode, client, wallet) {
|
||||||
const client = getClient(account)
|
|
||||||
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)
|
|
||||||
|
|
||||||
const { apiVersion, authHeader } = client
|
const { apiVersion, authHeader } = client
|
||||||
|
|
||||||
console.log(`** DEBUG ** getTransactionHash ENDPOINT: https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`)
|
console.log(`** DEBUG ** getTransactionHash ENDPOINT: https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`)
|
||||||
|
|
||||||
return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, {
|
return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, {
|
||||||
headers: authHeader
|
headers: authHeader
|
||||||
})
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`)
|
||||||
|
console.log(`** DEBUG ** Fetching transactions hashes via wallet node...`)
|
||||||
|
return wallet.getTxHashesByAddress(cryptoCode, receivingAddress)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTransactionHash (account, cryptoCode, receivingAddress, wallet) {
|
||||||
|
const client = getClient(account)
|
||||||
|
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)
|
||||||
|
getAddressTransactionsHashes(receivingAddress, cryptoCode, client, wallet)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const data = res.data
|
const data = res.data
|
||||||
if (_.size(data.txHistory) > 1) {
|
if (_.size(data.txHistory) > 1) {
|
||||||
|
|
@ -72,7 +79,7 @@ function getTransactionHash (account, cryptoCode, receivingAddress) {
|
||||||
return _.join(', ', _.map(it => it.txHash, data.txHistory))
|
return _.join(', ', _.map(it => it.txHash, data.txHistory))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`)
|
console.log(`** DEBUG ** getTransactionHash from wallet node ERROR: ${err}`)
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress))))
|
||||||
|
.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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress))))
|
||||||
|
.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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress))))
|
||||||
|
.then(_.map(({ hash }) => hash))
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
checkBlockchainStatus
|
checkBlockchainStatus,
|
||||||
|
getTxHashesByAddress
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ module.exports = {
|
||||||
privateKey,
|
privateKey,
|
||||||
isStrictAddress,
|
isStrictAddress,
|
||||||
connect,
|
connect,
|
||||||
checkBlockchainStatus
|
checkBlockchainStatus,
|
||||||
|
getTxHashesByAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
const SWEEP_QUEUE = new PQueue({
|
const SWEEP_QUEUE = new PQueue({
|
||||||
|
|
@ -69,6 +70,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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,14 @@ const SECONDS = 1000
|
||||||
const PUBLISH_TIME = 3 * SECONDS
|
const PUBLISH_TIME = 3 * SECONDS
|
||||||
const AUTHORIZE_TIME = PUBLISH_TIME + 5 * SECONDS
|
const AUTHORIZE_TIME = PUBLISH_TIME + 5 * SECONDS
|
||||||
const CONFIRM_TIME = AUTHORIZE_TIME + 10 * SECONDS
|
const CONFIRM_TIME = AUTHORIZE_TIME + 10 * SECONDS
|
||||||
|
const SUPPORTED_COINS = coinUtils.cryptoCurrencies()
|
||||||
|
|
||||||
let t0
|
let t0
|
||||||
|
|
||||||
|
const checkCryptoCode = (cryptoCode) => !_.includes(cryptoCode, SUPPORTED_COINS)
|
||||||
|
? Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||||
|
: Promise.resolve()
|
||||||
|
|
||||||
function _balance (cryptoCode) {
|
function _balance (cryptoCode) {
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||||
const unitScale = cryptoRec.unitScale
|
const unitScale = cryptoRec.unitScale
|
||||||
|
|
@ -107,7 +112,15 @@ function getStatus (account, tx, requested, settings, operatorId) {
|
||||||
|
|
||||||
console.log('[%s] DEBUG: Mock wallet has confirmed transaction [%s]', cryptoCode, toAddress.slice(0, 5))
|
console.log('[%s] DEBUG: Mock wallet has confirmed transaction [%s]', cryptoCode, toAddress.slice(0, 5))
|
||||||
|
|
||||||
return Promise.resolve({status: 'confirmed'})
|
return Promise.resolve({ status: 'confirmed' })
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTxHashesByAddress (cryptoCode, address) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
return resolve([]) // TODO: should return something other than empty list?
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBlockchainStatus (cryptoCode) {
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
|
|
@ -123,5 +136,6 @@ module.exports = {
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
checkBlockchainStatus
|
checkBlockchainStatus,
|
||||||
|
getTxHashesByAddress
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => refreshWallet())
|
.then(() => refreshWallet())
|
||||||
.then(() => fetch('get_address_index', { address: toAddress }))
|
.then(() => fetch('get_address_index', { address: toAddress }))
|
||||||
.then(addressRes => fetch('get_transfers', { in: true, pool: true, account_index: addressRes.index.major, address_indices: [addressRes.index.minor] }))
|
.then(addressRes => fetch('get_transfers', { in: true, pool: true, account_index: addressRes.index.major, subaddr_indices: [addressRes.index.minor] }))
|
||||||
.then(transferRes => {
|
.then(transferRes => {
|
||||||
const confirmedToAddress = _.filter(it => it.address === toAddress, transferRes.in ?? [])
|
const confirmedToAddress = _.filter(it => it.address === toAddress, transferRes.in ?? [])
|
||||||
const pendingToAddress = _.filter(it => it.address === toAddress, transferRes.pool ?? [])
|
const pendingToAddress = _.filter(it => it.address === toAddress, transferRes.pool ?? [])
|
||||||
|
|
@ -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, subaddr_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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,11 +151,17 @@ 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]))
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
newAddress,
|
newAddress,
|
||||||
getStatus,
|
getStatus,
|
||||||
newFunding,
|
newFunding,
|
||||||
checkBlockchainStatus
|
checkBlockchainStatus,
|
||||||
|
getTxHashesByAddress
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
const ph = require('./plugin-helper')
|
const ph = require('./plugin-helper')
|
||||||
const _ = require('lodash/fp')
|
|
||||||
const argv = require('minimist')(process.argv.slice(2))
|
const argv = require('minimist')(process.argv.slice(2))
|
||||||
|
const configManager = require('./new-config-manager')
|
||||||
|
|
||||||
function loadWalletScoring (settings) {
|
function loadWalletScoring (settings, cryptoCode) {
|
||||||
const pluginCode = argv.mockScoring ? 'mock-scoring' : 'ciphertrace'
|
const pluginCode = argv.mockScoring ? 'mock-scoring' : 'ciphertrace'
|
||||||
|
const wallet = cryptoCode ? ph.load(ph.WALLET, configManager.getWalletSettings(cryptoCode, settings.config).wallet) : null
|
||||||
const plugin = ph.load(ph.WALLET_SCORING, pluginCode)
|
const plugin = ph.load(ph.WALLET_SCORING, pluginCode)
|
||||||
const account = settings.accounts[pluginCode]
|
const account = settings.accounts[pluginCode]
|
||||||
|
|
||||||
return { plugin, account }
|
return { plugin, account, wallet }
|
||||||
}
|
}
|
||||||
|
|
||||||
function rateWallet (settings, cryptoCode, address) {
|
function rateWallet (settings, cryptoCode, address) {
|
||||||
|
|
@ -31,9 +32,9 @@ function isValidWalletScore (settings, score) {
|
||||||
function getTransactionHash (settings, cryptoCode, receivingAddress) {
|
function getTransactionHash (settings, cryptoCode, receivingAddress) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const { plugin, account } = loadWalletScoring(settings)
|
const { plugin, account, wallet } = loadWalletScoring(settings, cryptoCode)
|
||||||
|
|
||||||
return plugin.getTransactionHash(account, cryptoCode, receivingAddress)
|
return plugin.getTransactionHash(account, cryptoCode, receivingAddress, wallet)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue