rpc: fix getTXOutProof.

This commit is contained in:
Christopher Jeffrey 2017-08-19 19:36:28 -07:00
parent c69e7195b9
commit 040e798d9f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -862,7 +862,8 @@ RPC.prototype.getTXOutProof = async function getTXOutProof(args, help) {
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid TXIDs.');
const items = new Validator([txids]);
const hashes = new Set();
const set = new Set();
const hashes = [];
let last = null;
@ -872,10 +873,11 @@ RPC.prototype.getTXOutProof = async function getTXOutProof(args, help) {
if (!hash)
throw new RPCError(errs.TYPE_ERROR, 'Invalid TXID.');
if (hashes.has(hash))
if (set.has(hash))
throw new RPCError(errs.INVALID_PARAMETER, 'Duplicate txid.');
hashes.add(hash);
set.add(hash);
hashes.push(hash);
last = hash;
}
@ -897,14 +899,14 @@ RPC.prototype.getTXOutProof = async function getTXOutProof(args, help) {
if (!block)
throw new RPCError(errs.MISC_ERROR, 'Block not found.');
for (const txid of hashes) {
if (!block.hasTX(txid)) {
for (const hash of hashes) {
if (!block.hasTX(hash)) {
throw new RPCError(errs.VERIFY_ERROR,
'Block does not contain all txids.');
}
}
block = MerkleBlock.fromHashes(block, txids);
block = MerkleBlock.fromHashes(block, hashes);
return block.toRaw().toString('hex');
};