fix: verify if wallet scoring is enabled
This commit is contained in:
parent
69a4d52753
commit
727544344b
6 changed files with 79 additions and 37 deletions
|
|
@ -174,16 +174,20 @@ function doesTxReuseAddress (tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWalletScore (tx, pi) {
|
function getWalletScore (tx, pi) {
|
||||||
if (!tx.fiat || tx.fiat.isZero()) {
|
pi.isWalletScoringEnabled(tx)
|
||||||
return pi.rateWallet(tx.cryptoCode, tx.toAddress)
|
.then(isEnabled => {
|
||||||
}
|
if(!isEnabled) return null
|
||||||
// Passthrough the previous result
|
if (!tx.fiat || tx.fiat.isZero()) {
|
||||||
return pi.isValidWalletScore(tx.walletScore)
|
return pi.rateWallet(tx.cryptoCode, tx.toAddress)
|
||||||
.then(isValid => ({
|
}
|
||||||
address: tx.toAddress,
|
// Passthrough the previous result
|
||||||
score: tx.walletScore,
|
return pi.isValidWalletScore(tx.walletScore)
|
||||||
isValid
|
.then(isValid => ({
|
||||||
}))
|
address: tx.toAddress,
|
||||||
|
score: tx.walletScore,
|
||||||
|
isValid
|
||||||
|
}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function monitorPending (settings) {
|
function monitorPending (settings) {
|
||||||
|
|
|
||||||
|
|
@ -122,30 +122,34 @@ function getWalletScore (tx, pi) {
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
// Transaction shows up on the blockchain, we can request the sender address
|
// Transaction shows up on the blockchain, we can request the sender address
|
||||||
return pi.getTransactionHash(tx)
|
return pi.isWalletScoringEnabled(tx)
|
||||||
.then(rejectEmpty("No transaction hashes"))
|
.then(isEnabled => {
|
||||||
.then(txHashes => pi.getInputAddresses(tx, txHashes))
|
if (!isEnabled) return tx
|
||||||
.then(rejectEmpty("No input addresses"))
|
return pi.getTransactionHash(tx)
|
||||||
.then(addresses => Promise.all(_.map(it => pi.rateWallet(tx.cryptoCode, it), addresses)))
|
.then(rejectEmpty("No transaction hashes"))
|
||||||
.then(rejectEmpty("No score ratings"))
|
.then(txHashes => pi.getInputAddresses(tx, txHashes))
|
||||||
.then(_.maxBy(_.get(['score'])))
|
.then(rejectEmpty("No input addresses"))
|
||||||
.then(highestScore =>
|
.then(addresses => Promise.all(_.map(it => pi.rateWallet(tx.cryptoCode, it), addresses)))
|
||||||
// Conservatively assign the highest risk of all input addresses to the risk of this transaction
|
.then(rejectEmpty("No score ratings"))
|
||||||
highestScore.isValid
|
.then(_.maxBy(_.get(['score'])))
|
||||||
? _.assign(tx, { walletScore: highestScore.score })
|
.then(highestScore =>
|
||||||
: _.assign(tx, {
|
// Conservatively assign the highest risk of all input addresses to the risk of this transaction
|
||||||
walletScore: highestScore.score,
|
highestScore.isValid
|
||||||
error: 'Address score is above defined threshold',
|
? _.assign(tx, { walletScore: highestScore.score })
|
||||||
errorCode: 'scoreThresholdReached',
|
: _.assign(tx, {
|
||||||
|
walletScore: highestScore.score,
|
||||||
|
error: 'Address score is above defined threshold',
|
||||||
|
errorCode: 'scoreThresholdReached',
|
||||||
|
dispense: true
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.catch(error => _.assign(tx, {
|
||||||
|
walletScore: 10,
|
||||||
|
error: `Failure getting address score: ${error.message}`,
|
||||||
|
errorCode: 'ciphertraceError',
|
||||||
dispense: true
|
dispense: true
|
||||||
})
|
}))
|
||||||
)
|
})
|
||||||
.catch(error => _.assign(tx, {
|
|
||||||
walletScore: 10,
|
|
||||||
error: `Failure getting address score: ${error.message}`,
|
|
||||||
errorCode: 'ciphertraceError',
|
|
||||||
dispense: true
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function monitorLiveIncoming (settings) {
|
function monitorLiveIncoming (settings) {
|
||||||
|
|
|
||||||
|
|
@ -850,6 +850,10 @@ function plugins (settings, deviceId) {
|
||||||
return walletScoring.getInputAddresses(settings, tx.cryptoCode, txHashes)
|
return walletScoring.getInputAddresses(settings, tx.cryptoCode, txHashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isWalletScoringEnabled (tx) {
|
||||||
|
return walletScoring.isWalletScoringEnabled(settings, tx.cryptoCode)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getRates,
|
getRates,
|
||||||
recordPing,
|
recordPing,
|
||||||
|
|
@ -882,7 +886,8 @@ function plugins (settings, deviceId) {
|
||||||
rateWallet,
|
rateWallet,
|
||||||
isValidWalletScore,
|
isValidWalletScore,
|
||||||
getTransactionHash,
|
getTransactionHash,
|
||||||
getInputAddresses
|
getInputAddresses,
|
||||||
|
isWalletScoringEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,19 @@ function getInputAddresses (account, cryptoCode, txHashes) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isWalletScoringEnabled (account, cryptoCode) {
|
||||||
|
if (!SUPPORTED_COINS.includes(cryptoCode)) {
|
||||||
|
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(!_.isNil(account) && account.enabled)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NAME,
|
NAME,
|
||||||
rateWallet,
|
rateWallet,
|
||||||
isValidWalletScore,
|
isValidWalletScore,
|
||||||
getTransactionHash,
|
getTransactionHash,
|
||||||
getInputAddresses
|
getInputAddresses,
|
||||||
|
isWalletScoringEnabled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,20 @@ function getInputAddresses (account, cryptoCode, txHashes) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isWalletScoringEnabled (account, cryptoCode) {
|
||||||
|
return new Promise((resolve, _) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
return resolve(true)
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NAME,
|
NAME,
|
||||||
rateWallet,
|
rateWallet,
|
||||||
isValidWalletScore,
|
isValidWalletScore,
|
||||||
getTransactionHash,
|
getTransactionHash,
|
||||||
getInputAddresses
|
getInputAddresses,
|
||||||
|
isWalletScoringEnabled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,19 @@ function getInputAddresses (settings, cryptoCode, txHashes) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isWalletScoringEnabled (settings, cryptoCode) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
const { plugin, account } = loadWalletScoring(settings)
|
||||||
|
|
||||||
|
return plugin.isWalletScoringEnabled(account, cryptoCode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
rateWallet,
|
rateWallet,
|
||||||
isValidWalletScore,
|
isValidWalletScore,
|
||||||
getTransactionHash,
|
getTransactionHash,
|
||||||
getInputAddresses
|
getInputAddresses,
|
||||||
|
isWalletScoringEnabled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue