diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py index 0c5ae32fb..c53c72ec9 100755 --- a/qa/rpc-tests/rawtransactions.py +++ b/qa/rpc-tests/rawtransactions.py @@ -85,6 +85,9 @@ class RawTransactionsTest(BitcoinTestFramework): gottx = self.nodes[0].getrawtransaction(tx, 1) assert_equal(gottx['txid'], tx) assert 'in_active_chain' not in gottx + # We should have hex for the transaction from the getblock and getrawtransaction calls. + blk = self.nodes[0].getblock(block1, 2) + assert_equal(gottx['hex'], blk['tx'][1]['hex']) # We should not get the tx if we provide an unrelated block assert_raises(JSONRPCException, self.nodes[0].getrawtransaction, tx, 1, block2) # An invalid block hash should raise errors diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 05b9e914c..9b6802357 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -164,6 +164,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) entry.pushKV("expiryheight", (int64_t)tx.nExpiryHeight); } + entry.pushKV("hex", EncodeHexTx(tx)); + KeyIO keyIO(Params()); UniValue vin(UniValue::VARR); BOOST_FOREACH(const CTxIn& txin, tx.vin) {