Skip to content
Permalink
Browse files
RPC: add transaction hash to mempool entry output
  • Loading branch information
luke-jr committed Mar 28, 2020
1 parent 6b4f182 commit 8cd33e76374bd1b18f9e94873f51071e0edf0b68
Showing 2 changed files with 8 additions and 3 deletions.
@@ -388,6 +388,7 @@ static std::vector<RPCResult> MempoolEntryDescription() { return {
RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
RPCResult{RPCResult::Type::NUM, "ancestorsize", "virtual transaction size of in-mempool ancestors (including this one)"},
RPCResult{RPCResult::Type::STR_AMOUNT, "ancestorfees", "modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)"},
RPCResult{RPCResult::Type::STR_HEX, "hash", "hash of entire serialized transaction"},
RPCResult{RPCResult::Type::STR_HEX, "wtxid", "hash of serialized transaction, including witness data"},
RPCResult{RPCResult::Type::OBJ, "fees", "",
{
@@ -428,6 +429,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
info.pushKV("ancestorsize", e.GetSizeWithAncestors());
info.pushKV("ancestorfees", e.GetModFeesWithAncestors());
info.pushKV("wtxid", pool.vTxHashes[e.vTxHashesIdx].first.ToString());
info.pushKV("hash", info["wtxid"]);
const CTransaction& tx = e.GetTx();
std::set<std::string> setDepends;
for (const CTxIn& txin : tx.vin)
@@ -230,7 +230,8 @@ def run_test(self):
tx1_hex = self.nodes[0].gettransaction(txid1)['hex']
tx1 = FromHex(CTransaction(), tx1_hex)

# Check that wtxid is properly reported in mempool entry (txid1)
# Check that hash and wtxid are properly reported in mempool entry (txid1)
assert_equal(int(self.nodes[0].getmempoolentry(txid1)["hash"], 16), tx1.calc_sha256(True))
assert_equal(int(self.nodes[0].getmempoolentry(txid1)["wtxid"], 16), tx1.calc_sha256(True))

# Check that weight and vsize are properly reported in mempool entry (txid1)
@@ -246,7 +247,8 @@ def run_test(self):
tx = FromHex(CTransaction(), tx2_hex)
assert not tx.wit.is_null()

# Check that wtxid is properly reported in mempool entry (txid2)
# Check that hash and wtxid are properly reported in mempool entry (txid2)
assert_equal(int(self.nodes[0].getmempoolentry(txid2)["hash"], 16), tx.calc_sha256(True))
assert_equal(int(self.nodes[0].getmempoolentry(txid2)["wtxid"], 16), tx.calc_sha256(True))

# Check that weight and vsize are properly reported in mempool entry (txid2)
@@ -269,7 +271,8 @@ def run_test(self):
assert txid2 in template_txids
assert txid3 in template_txids

# Check that wtxid is properly reported in mempool entry (txid3)
# Check that hash and wtxid are properly reported in mempool entry (txid3)
assert_equal(int(self.nodes[0].getmempoolentry(txid3)["hash"], 16), tx.calc_sha256(True))
assert_equal(int(self.nodes[0].getmempoolentry(txid3)["wtxid"], 16), tx.calc_sha256(True))

# Check that weight and vsize are properly reported in mempool entry (txid3)

0 comments on commit 8cd33e7

Please sign in to comment.