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 addrMap[address] = vout
} }
// Checks with indexer if addresses are known and have been used // Checks with indexer if addresses are known and have been used
if (keys.indexer.active != 'local_bitcoind') { if (Object.keys(addrMap).length > 0) {
const results = await this.sources.getAddresses(Object.keys(addrMap)) if (keys.indexer.active != 'local_bitcoind') {
for (let r of results) const results = await this.sources.getAddresses(Object.keys(addrMap))
if (r.ntx > 0) for (let r of results)
faultyOutputs.push(addrMap[r.address]) if (r.ntx > 0)
faultyOutputs.push(addrMap[r.address])
}
} }
return faultyOutputs return faultyOutputs
} }

34
pushtx/pushtx-rest-api.js

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