diff --git a/pushtx/pushtx-processor.js b/pushtx/pushtx-processor.js index dc78968..0ba6d4c 100644 --- a/pushtx/pushtx-processor.js +++ b/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 } diff --git a/pushtx/pushtx-rest-api.js b/pushtx/pushtx-rest-api.js index dd7aa87..c17923a 100644 --- a/pushtx/pushtx-rest-api.js +++ b/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) } }