From b53162e12dccc3d2a58065e83c74fa149c57bdf0 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 5 Mar 2017 16:44:46 -0800 Subject: [PATCH] mempool: fix getDescendants and getAncestors. --- lib/http/rpc.js | 8 ++++---- lib/mempool/mempool.js | 28 +++++++++++++++------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 9fee1d4f..51437feb 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1037,7 +1037,7 @@ RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args, help) if (!entry) throw new RPCError('Transaction not in mempool.'); - entries = this.mempool.getAncestors(entry.tx); + entries = this.mempool.getAncestors(entry); if (verbose) { for (i = 0; i < entries.length; i++) { @@ -1047,7 +1047,7 @@ RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args, help) } else { for (i = 0; i < entries.length; i++) { entry = entries[i]; - out.push(entry.tx.txid()); + out.push(entry.txid()); } } @@ -1077,7 +1077,7 @@ RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args, h if (!entry) throw new RPCError('Transaction not in mempool.'); - entries = this.mempool.getDescendants(entry.tx); + entries = this.mempool.getDescendants(entry); if (verbose) { for (i = 0; i < entries.length; i++) { @@ -1087,7 +1087,7 @@ RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args, h } else { for (i = 0; i < entries.length; i++) { entry = entries[i]; - out.push(entry.tx.txid()); + out.push(entry.txid()); } } diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index c47e7d7e..6c998f8f 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -1283,7 +1283,7 @@ Mempool.prototype._countDescendants = function countDescendants(entry, count, se if (!child) continue; - next = child.tx.hash('hex'); + next = child.hash('hex'); if (set[next]) continue; @@ -1299,30 +1299,31 @@ Mempool.prototype._countDescendants = function countDescendants(entry, count, se /** * Get all transaction ancestors. - * @param {TX} tx + * @param {MempoolEntry} entry * @returns {MempoolEntry[]} */ -Mempool.prototype.getAncestors = function getAncestors(tx) { - return this._getAncestors(tx, [], {}); +Mempool.prototype.getAncestors = function getAncestors(entry) { + return this._getAncestors(entry, [], {}); }; /** * Get all transaction ancestors. * @private - * @param {TX} tx + * @param {MempoolEntry} entry * @param {MempoolEntry[]} entries * @param {Object} set * @returns {MempoolEntry[]} */ -Mempool.prototype._getAncestors = function getAncestors(tx, entries, set) { +Mempool.prototype._getAncestors = function getAncestors(entry, entries, set) { + var tx = entry.tx; var i, hash, input, parent; for (i = 0; i < tx.inputs.length; i++) { input = tx.inputs[i]; hash = input.prevout.hash; - parent = this.getTX(hash); + parent = this.getEntry(hash); if (!parent) continue; @@ -1341,28 +1342,29 @@ Mempool.prototype._getAncestors = function getAncestors(tx, entries, set) { /** * Get all a transaction descendants. - * @param {TX} tx + * @param {MempoolEntry} entry * @returns {MempoolEntry[]} */ -Mempool.prototype.getDescendants = function getDescendants(tx) { - return this._getDescendants(tx, [], {}); +Mempool.prototype.getDescendants = function getDescendants(entry) { + return this._getDescendants(entry, [], {}); }; /** * Get all a transaction descendants. - * @param {TX} tx + * @param {MempoolEntry} entry * @param {MempoolEntry[]} entries * @param {Object} set * @returns {MempoolEntry[]} */ -Mempool.prototype._getDescendants = function getDescendants(tx, entries, set) { +Mempool.prototype._getDescendants = function getDescendants(entry, entries, set) { + var tx = entry.tx; var hash = tx.hash('hex'); var i, child, next; for (i = 0; i < tx.outputs.length; i++) { - child = this.getSpentTX(hash, i); + child = this.getSpent(hash, i); if (!child) continue;