Browse Source

rework some code used for strict_mode_vouts

use-env-var-docker
kenshin-samourai 5 years ago
parent
commit
70547a4292
  1. 12
      pushtx/pushtx-processor.js
  2. 34
      pushtx/pushtx-rest-api.js

12
pushtx/pushtx-processor.js

@ -76,11 +76,13 @@ class PushTxProcessor {
addrMap[address] = vout
}
// Checks with indexer if addresses are known and have been used
if (keys.indexer.active != 'local_bitcoind') {
const results = await this.sources.getAddresses(Object.keys(addrMap))
for (let r of results)
if (r.ntx > 0)
faultyOutputs.push(addrMap[r.address])
if (Object.keys(addrMap).length > 0) {
if (keys.indexer.active != 'local_bitcoind') {
const results = await this.sources.getAddresses(Object.keys(addrMap))
for (let r of results)
if (r.ntx > 0)
faultyOutputs.push(addrMap[r.address])
}
}
return faultyOutputs
}

34
pushtx/pushtx-rest-api.js

@ -153,27 +153,23 @@ class PushTxRestApi {
return this._traceError(res, errors.body.INVDATA)
if (query.strict_mode_vouts) {
const outs = query.strict_mode_vouts.split('|')
if (outs.length > 0) {
let faults
for (let item of outs) {
if (!validator.isInt(item))
return this._traceError(res, errors.body.INVDATA)
}
try {
const indices = outs.map(v => parseInt(v, 10))
faults = await pushTxProcessor.enforceStrictModeVouts(query.tx, indices)
} catch(e) {
this._traceError(res, e)
}
if (faults.length > 0) {
return this._traceError(res, {
'message': JSON.stringify({
'message': faults,
'code': errors.pushtx.VIOLATION_STRICT_MODE_VOUTS
try {
const vouts = query.strict_mode_vouts.split('|').map(v => parseInt(v, 10))
if (vouts.some(isNaN))
throw errors.txout.VOUT
if (vouts.length > 0) {
let faults = await pushTxProcessor.enforceStrictModeVouts(query.tx, vouts)
if (faults.length > 0) {
return this._traceError(res, {
'message': JSON.stringify({
'message': faults,
'code': errors.pushtx.VIOLATION_STRICT_MODE_VOUTS
})
})
})
}
}
} catch(e) {
return this._traceError(res, e)
}
}

Loading…
Cancel
Save