feat: add mock wallet scoring
This commit is contained in:
parent
b0fa62a9f3
commit
584492cb55
6 changed files with 76 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ const E = require('../error')
|
||||||
|
|
||||||
const PENDING_INTERVAL_MS = 60 * T.minutes
|
const PENDING_INTERVAL_MS = 60 * T.minutes
|
||||||
|
|
||||||
const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse', 'promoCodeApplied']
|
const massageFields = ['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse', 'promoCodeApplied', 'failedWalletScore']
|
||||||
const massageUpdateFields = _.concat(massageFields, 'cryptoAtoms')
|
const massageUpdateFields = _.concat(massageFields, 'cryptoAtoms')
|
||||||
|
|
||||||
const massage = _.flow(_.omit(massageFields),
|
const massage = _.flow(_.omit(massageFields),
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ const cashInLow = require('./cash-in-low')
|
||||||
|
|
||||||
const PENDING_INTERVAL = '60 minutes'
|
const PENDING_INTERVAL = '60 minutes'
|
||||||
const MAX_PENDING = 10
|
const MAX_PENDING = 10
|
||||||
|
const WALLET_SCORE_THRESHOLD = 10
|
||||||
|
|
||||||
const TRANSACTION_STATES = `
|
const TRANSACTION_STATES = `
|
||||||
case
|
case
|
||||||
|
|
@ -33,11 +34,14 @@ function post (machineTx, pi) {
|
||||||
const updatedTx = r.tx
|
const updatedTx = r.tx
|
||||||
let blacklisted = false
|
let blacklisted = false
|
||||||
let addressReuse = false
|
let addressReuse = false
|
||||||
|
let failedWalletScore = false
|
||||||
|
|
||||||
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx), doesTxReuseAddress(updatedTx)])
|
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx), doesTxReuseAddress(updatedTx), doesWalletScoreFail(updatedTx, pi)])
|
||||||
.then(([{ config }, blacklistItems, isReusedAddress]) => {
|
.then(([{ config }, blacklistItems, isReusedAddress, walletScoreFailed]) => {
|
||||||
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
|
const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
|
||||||
|
|
||||||
|
failedWalletScore = walletScoreFailed
|
||||||
|
|
||||||
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
|
if (_.some(it => it.address === updatedTx.toAddress)(blacklistItems)) {
|
||||||
blacklisted = true
|
blacklisted = true
|
||||||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
|
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, false)
|
||||||
|
|
@ -45,12 +49,13 @@ function post (machineTx, pi) {
|
||||||
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
|
notifier.notifyIfActive('compliance', 'blacklistNotify', r.tx, true)
|
||||||
addressReuse = true
|
addressReuse = true
|
||||||
}
|
}
|
||||||
return postProcess(r, pi, blacklisted, addressReuse)
|
return postProcess(r, pi, blacklisted, addressReuse, failedWalletScore)
|
||||||
})
|
})
|
||||||
.then(changes => cashInLow.update(db, updatedTx, changes))
|
.then(changes => cashInLow.update(db, updatedTx, changes))
|
||||||
.then(tx => _.set('bills', machineTx.bills, tx))
|
.then(tx => _.set('bills', machineTx.bills, tx))
|
||||||
.then(tx => _.set('blacklisted', blacklisted, tx))
|
.then(tx => _.set('blacklisted', blacklisted, tx))
|
||||||
.then(tx => _.set('addressReuse', addressReuse, tx))
|
.then(tx => _.set('addressReuse', addressReuse, tx))
|
||||||
|
.then(tx => _.set('failedWalletScore', failedWalletScore, tx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +93,7 @@ function checkForBlacklisted (tx) {
|
||||||
return Promise.resolve(false)
|
return Promise.resolve(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
function postProcess (r, pi, isBlacklisted, addressReuse) {
|
function postProcess (r, pi, isBlacklisted, addressReuse, failedWalletScore) {
|
||||||
if (addressReuse) {
|
if (addressReuse) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
operatorCompleted: true,
|
operatorCompleted: true,
|
||||||
|
|
@ -103,6 +108,13 @@ function postProcess (r, pi, isBlacklisted, addressReuse) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failedWalletScore) {
|
||||||
|
return Promise.resolve({
|
||||||
|
operatorCompleted: true,
|
||||||
|
error: 'Failed wallet score'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
registerTrades(pi, r)
|
registerTrades(pi, r)
|
||||||
|
|
||||||
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
||||||
|
|
@ -147,6 +159,14 @@ function doesTxReuseAddress (tx) {
|
||||||
return Promise.resolve(false)
|
return Promise.resolve(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doesWalletScoreFail (tx, pi) {
|
||||||
|
if (!tx.fiat || tx.fiat.isZero()) {
|
||||||
|
return pi.rateWallet(tx.toAddress)
|
||||||
|
.then(res => res >= WALLET_SCORE_THRESHOLD)
|
||||||
|
}
|
||||||
|
return Promise.resolve(false)
|
||||||
|
}
|
||||||
|
|
||||||
function monitorPending (settings) {
|
function monitorPending (settings) {
|
||||||
const sql = `select * from cash_in_txs
|
const sql = `select * from cash_in_txs
|
||||||
where created > now() - interval $1
|
where created > now() - interval $1
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const pluginCodes = {
|
||||||
TICKER: 'ticker',
|
TICKER: 'ticker',
|
||||||
EXCHANGE: 'exchange',
|
EXCHANGE: 'exchange',
|
||||||
WALLET: 'wallet',
|
WALLET: 'wallet',
|
||||||
|
WALLET_SCORING: 'wallet-scoring',
|
||||||
LAYER2: 'layer2',
|
LAYER2: 'layer2',
|
||||||
SMS: 'sms',
|
SMS: 'sms',
|
||||||
EMAIL: 'email',
|
EMAIL: 'email',
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ const T = require('./time')
|
||||||
const configManager = require('./new-config-manager')
|
const configManager = require('./new-config-manager')
|
||||||
const ticker = require('./ticker')
|
const ticker = require('./ticker')
|
||||||
const wallet = require('./wallet')
|
const wallet = require('./wallet')
|
||||||
|
const walletScoring = require('./wallet-scoring')
|
||||||
const exchange = require('./exchange')
|
const exchange = require('./exchange')
|
||||||
const sms = require('./sms')
|
const sms = require('./sms')
|
||||||
const email = require('./email')
|
const email = require('./email')
|
||||||
|
|
@ -776,6 +777,11 @@ function plugins (settings, deviceId) {
|
||||||
.then(buildRates)
|
.then(buildRates)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rateWallet (address) {
|
||||||
|
return walletScoring.rateWallet(settings, address)
|
||||||
|
.then(res => res.rating)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getRates,
|
getRates,
|
||||||
buildRates,
|
buildRates,
|
||||||
|
|
@ -803,7 +809,8 @@ function plugins (settings, deviceId) {
|
||||||
getNotificationConfig,
|
getNotificationConfig,
|
||||||
notifyOperator,
|
notifyOperator,
|
||||||
fetchCurrentConfigVersion,
|
fetchCurrentConfigVersion,
|
||||||
pruneMachinesHeartbeat
|
pruneMachinesHeartbeat,
|
||||||
|
rateWallet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
lib/plugins/wallet-scoring/mock-scoring/mock-scoring.js
Normal file
15
lib/plugins/wallet-scoring/mock-scoring/mock-scoring.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const NAME = 'FakeScoring'
|
||||||
|
|
||||||
|
function rateWallet (account, address) {
|
||||||
|
return new Promise((resolve, _) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log('[WALLET-SCORING] DEBUG: Mock scoring rating wallet address %s', address)
|
||||||
|
return resolve({ address, rating: 5 })
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
NAME,
|
||||||
|
rateWallet
|
||||||
|
}
|
||||||
27
lib/wallet-scoring.js
Normal file
27
lib/wallet-scoring.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
const ph = require('./plugin-helper')
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
const argv = require('minimist')(process.argv.slice(2))
|
||||||
|
|
||||||
|
function loadWalletScoring (settings) {
|
||||||
|
if (_.isNil(argv.mockScoring)) {
|
||||||
|
throw new Error('No wallet scoring API set!')
|
||||||
|
}
|
||||||
|
const pluginCode = argv.mockScoring ? 'mock-scoring' : ''
|
||||||
|
const plugin = ph.load(ph.WALLET_SCORING, pluginCode)
|
||||||
|
const account = settings.accounts[pluginCode]
|
||||||
|
|
||||||
|
return { plugin, account }
|
||||||
|
}
|
||||||
|
|
||||||
|
function rateWallet (settings, address) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
const { plugin, account } = loadWalletScoring(settings)
|
||||||
|
|
||||||
|
return plugin.rateWallet(account, address)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
rateWallet
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue