Prevent address reuse option

This commit is contained in:
Rafael Taranto 2019-07-31 12:17:39 +01:00 committed by Josh Harvey
parent 55cdc2fa52
commit 98cc3b18b7
9 changed files with 141 additions and 13 deletions

View file

@ -8,7 +8,7 @@ const E = require('../error')
const PENDING_INTERVAL_MS = 60 * T.minutes
const massage = _.flow(_.omit(['direction', 'cryptoNetwork', 'bills', 'blacklisted']),
const massage = _.flow(_.omit(['direction', 'cryptoNetwork', 'bills', 'blacklisted', 'addressReuse']),
convertBigNumFields, _.mapKeys(_.snakeCase))
module.exports = {toObj, upsert, insert, update, massage, isClearToSend}

View file

@ -6,6 +6,8 @@ const blacklist = require('../blacklist')
const db = require('../db')
const plugins = require('../plugins')
const logger = require('../logger')
const settingsLoader = require('../settings-loader')
const configManager = require('../config-manager')
const cashInAtomic = require('./cash-in-atomic')
const cashInLow = require('./cash-in-low')
@ -20,15 +22,24 @@ function post (machineTx, pi) {
.then(r => {
const updatedTx = r.tx
let blacklisted = false
let addressReuse = false
return checkForBlacklisted(updatedTx)
.then(isBlacklisted => {
blacklisted = !!isBlacklisted
return postProcess(r, pi, blacklisted)
.then(blacklistItem => {
if (blacklistItem && blacklistItem.created_by_operator) {
blacklisted = true
}
if (blacklistItem && !blacklistItem.created_by_operator) {
addressReuse = true
}
return postProcess(r, pi, blacklisted, addressReuse)
})
.then(changes => cashInLow.update(db, updatedTx, changes))
.then(tx => _.set('bills', machineTx.bills, tx))
.then(tx => _.set('blacklisted', blacklisted, tx))
.then(tx => _.set('addressReuse', addressReuse, tx))
})
}
@ -66,7 +77,14 @@ function checkForBlacklisted (tx) {
return Promise.resolve(false)
}
function postProcess (r, pi, isBlacklisted) {
function postProcess (r, pi, isBlacklisted, addressReuse) {
if (addressReuse) {
return Promise.resolve({
operatorCompleted: true,
error: 'Address Reused'
})
}
if (isBlacklisted) {
return Promise.resolve({
operatorCompleted: true,
@ -104,6 +122,14 @@ function postProcess (r, pi, isBlacklisted) {
}
})
.then(sendRec => {
settingsLoader.loadLatest().then(it => {
const config = configManager.unscoped(it.config)
if (config.rejectAddressReuseActive) {
blacklist.addToUsedAddresses(r.tx.toAddress, r.tx.cryptoCode)
.catch(err => logger.error('Failure adding to addressReuse', err))
}
})
pi.notifyOperator(r.tx, sendRec)
.catch((err) => logger.error('Failure sending transaction notification', err))
return logAction(sendRec, r.tx)