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 1/6] 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 } From e798be94aeb02f4b8319ccd09d195ce9fac1c6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 20 Jul 2022 11:08:57 +0100 Subject: [PATCH 2/6] fix: remove coins not supported by ciphertrace --- lib/plugins/wallet/dashd/dashd.js | 5 +---- lib/plugins/wallet/monerod/monerod.js | 6 +----- lib/plugins/wallet/zcashd/zcashd.js | 4 +--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index 9b84a6a0..57a58ae3 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -126,10 +126,7 @@ function checkBlockchainStatus (cryptoCode) { } 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)) + throw new Error(`Transactions hash retrieval is not implemented for this coin!`) } module.exports = { diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 1ed93bf8..50e45ba1 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -236,11 +236,7 @@ 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)) + throw new Error(`Transactions hash retrieval is not implemented for this coin!`) } module.exports = { diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index d9d7f867..057cd4a2 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -152,9 +152,7 @@ function checkBlockchainStatus (cryptoCode) { } function getTxHashesByAddress (cryptoCode, address) { - checkCryptoCode(cryptoCode) - .then(() => fetch('getaddresstxids', [address])) - .then(_.mapKeys(() => 'txid')) + throw new Error(`Transactions hash retrieval is not implemented for this coin!`) } module.exports = { From 71212d8cd1c5ca1ffed0a988fdb8605f7d6b4489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 20 Jul 2022 11:21:28 +0100 Subject: [PATCH 3/6] Revert "fix: remove coins not supported by ciphertrace" This reverts commit e798be94aeb02f4b8319ccd09d195ce9fac1c6c1. --- lib/plugins/wallet/dashd/dashd.js | 5 ++++- lib/plugins/wallet/monerod/monerod.js | 6 +++++- lib/plugins/wallet/zcashd/zcashd.js | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index 57a58ae3..9b84a6a0 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -126,7 +126,10 @@ function checkBlockchainStatus (cryptoCode) { } function getTxHashesByAddress (cryptoCode, address) { - throw new Error(`Transactions hash retrieval is not implemented for this coin!`) + 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 = { diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 50e45ba1..1ed93bf8 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -236,7 +236,11 @@ function checkBlockchainStatus (cryptoCode) { } function getTxHashesByAddress (cryptoCode, address) { - throw new Error(`Transactions hash retrieval is not implemented for this coin!`) + 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 = { diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index 057cd4a2..d9d7f867 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -152,7 +152,9 @@ function checkBlockchainStatus (cryptoCode) { } function getTxHashesByAddress (cryptoCode, address) { - throw new Error(`Transactions hash retrieval is not implemented for this coin!`) + checkCryptoCode(cryptoCode) + .then(() => fetch('getaddresstxids', [address])) + .then(_.mapKeys(() => 'txid')) } module.exports = { From baf95b1e7c2b2b9ca3dcdc7c0ab72409315bebbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 20 Jul 2022 11:31:49 +0100 Subject: [PATCH 4/6] fix: zcash getTxHashesByAddress return value --- lib/plugins/wallet/zcashd/zcashd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index d9d7f867..f0fb27f4 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -154,7 +154,7 @@ function checkBlockchainStatus (cryptoCode) { function getTxHashesByAddress (cryptoCode, address) { checkCryptoCode(cryptoCode) .then(() => fetch('getaddresstxids', [address])) - .then(_.mapKeys(() => 'txid')) + .then(_.values) } module.exports = { From bc1925a14c19e6b0395bfca8472719937a288ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 21 Jul 2022 10:22:24 +0100 Subject: [PATCH 5/6] fix: promise all array values and monero get_transfers arg --- lib/plugins/wallet/bitcoincashd/bitcoincashd.js | 2 +- lib/plugins/wallet/bitcoind/bitcoind.js | 2 +- lib/plugins/wallet/dashd/dashd.js | 2 +- lib/plugins/wallet/monerod/monerod.js | 4 ++-- lib/plugins/wallet/zcashd/zcashd.js | 1 - 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js index 9fb3cd09..1208a19e 100644 --- a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js +++ b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js @@ -132,7 +132,7 @@ function checkBlockchainStatus (cryptoCode) { 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(txsByAddress => Promise.all(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress)))) .then(_.map(({ hash }) => hash)) } diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 2a52e01b..cc30e4b4 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -194,7 +194,7 @@ function checkBlockchainStatus (cryptoCode) { 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(txsByAddress => Promise.all(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress)))) .then(_.map(({ hash }) => hash)) } diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index 9b84a6a0..e5167332 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -128,7 +128,7 @@ function checkBlockchainStatus (cryptoCode) { 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(txsByAddress => Promise.all(_.map(id => fetch('getrawtransaction', [id]), _.flatMap(it => it.txids, txsByAddress)))) .then(_.map(({ hash }) => hash)) } diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 1ed93bf8..0d938dc0 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -164,7 +164,7 @@ function getStatus (account, tx, requested, settings, operatorId) { return checkCryptoCode(cryptoCode) .then(() => refreshWallet()) .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 => { const confirmedToAddress = _.filter(it => it.address === toAddress, transferRes.in ?? []) const pendingToAddress = _.filter(it => it.address === toAddress, transferRes.pool ?? []) @@ -239,7 +239,7 @@ 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(addressRes => fetch('get_transfers', { in: true, pool: true, pending: true, account_index: addressRes.index.major, subaddr_indices: [addressRes.index.minor] })) .then(_.map(({ txid }) => txid)) } diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index f0fb27f4..dfacdbc2 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -154,7 +154,6 @@ function checkBlockchainStatus (cryptoCode) { function getTxHashesByAddress (cryptoCode, address) { checkCryptoCode(cryptoCode) .then(() => fetch('getaddresstxids', [address])) - .then(_.values) } module.exports = { From 0a0b6eed2c00e04c904b0a4fb579e13999ab1c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 27 Jul 2022 13:45:36 +0100 Subject: [PATCH 6/6] feat: add get txs hashes fallback on ciphertrace --- .../wallet-scoring/ciphertrace/ciphertrace.js | 19 +++++++++++++------ lib/plugins/wallet/mock-wallet/mock-wallet.js | 18 ++++++++++++++++-- lib/wallet-scoring.js | 11 ++++++----- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js index b6416b82..02db9562 100644 --- a/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js +++ b/lib/plugins/wallet-scoring/ciphertrace/ciphertrace.js @@ -52,17 +52,24 @@ function isValidWalletScore (account, score) { return _.isNil(account) ? Promise.resolve(true) : Promise.resolve(score < threshold) } -function getTransactionHash (account, cryptoCode, receivingAddress) { - const client = getClient(account) - if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null) - +function getAddressTransactionsHashes (receivingAddress, cryptoCode, client, wallet) { 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`) return axios.get(`https://rest.ciphertrace.com/api/${apiVersion}/${_.toLower(cryptoCode) !== 'btc' ? `${_.toLower(cryptoCode)}_` : ``}address/search?features=tx&address=${receivingAddress}&mempool=true`, { 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 => { const data = res.data if (_.size(data.txHistory) > 1) { @@ -72,7 +79,7 @@ function getTransactionHash (account, cryptoCode, receivingAddress) { return _.join(', ', _.map(it => it.txHash, data.txHistory)) }) .catch(err => { - console.log(`** DEBUG ** getTransactionHash ERROR: ${err}`) + console.log(`** DEBUG ** getTransactionHash from wallet node ERROR: ${err}`) throw err }) } diff --git a/lib/plugins/wallet/mock-wallet/mock-wallet.js b/lib/plugins/wallet/mock-wallet/mock-wallet.js index 6d163cf8..4e359287 100644 --- a/lib/plugins/wallet/mock-wallet/mock-wallet.js +++ b/lib/plugins/wallet/mock-wallet/mock-wallet.js @@ -10,9 +10,14 @@ const SECONDS = 1000 const PUBLISH_TIME = 3 * SECONDS const AUTHORIZE_TIME = PUBLISH_TIME + 5 * SECONDS const CONFIRM_TIME = AUTHORIZE_TIME + 10 * SECONDS +const SUPPORTED_COINS = coinUtils.cryptoCurrencies() let t0 +const checkCryptoCode = (cryptoCode) => !_.includes(cryptoCode, SUPPORTED_COINS) + ? Promise.reject(new Error('Unsupported crypto: ' + cryptoCode)) + : Promise.resolve() + function _balance (cryptoCode) { const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode) 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)) - 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) { @@ -123,5 +136,6 @@ module.exports = { newAddress, getStatus, newFunding, - checkBlockchainStatus + checkBlockchainStatus, + getTxHashesByAddress } diff --git a/lib/wallet-scoring.js b/lib/wallet-scoring.js index ab461ce4..0281c25a 100644 --- a/lib/wallet-scoring.js +++ b/lib/wallet-scoring.js @@ -1,13 +1,14 @@ const ph = require('./plugin-helper') -const _ = require('lodash/fp') 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 wallet = cryptoCode ? ph.load(ph.WALLET, configManager.getWalletSettings(cryptoCode, settings.config).wallet) : null const plugin = ph.load(ph.WALLET_SCORING, pluginCode) const account = settings.accounts[pluginCode] - return { plugin, account } + return { plugin, account, wallet } } function rateWallet (settings, cryptoCode, address) { @@ -31,9 +32,9 @@ function isValidWalletScore (settings, score) { function getTransactionHash (settings, cryptoCode, receivingAddress) { return Promise.resolve() .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) }) }