Prevent address reuse option
This commit is contained in:
parent
55cdc2fa52
commit
98cc3b18b7
9 changed files with 141 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue