diff --git a/src/core_io.h b/src/core_io.h --- a/src/core_io.h +++ b/src/core_io.h @@ -30,7 +30,7 @@ std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags = 0); void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex); -void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, - UniValue &entry); +void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, + bool include_hex = true, int serialize_flags = 0); #endif // BITCOIN_CORE_IO_H diff --git a/src/core_write.cpp b/src/core_write.cpp --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -184,8 +184,8 @@ out.pushKV("addresses", a); } -void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, - UniValue &entry) { +void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, + bool include_hex, int serialize_flags) { entry.pushKV("txid", tx.GetId().GetHex()); entry.pushKV("hash", tx.GetHash().GetHex()); entry.pushKV("version", tx.nVersion); @@ -238,7 +238,9 @@ entry.pushKV("blockhash", hashBlock.GetHex()); } - // the hex-encoded transaction. used the name "hex" to be consistent with - // the verbose output of "getrawtransaction". - entry.pushKV("hex", EncodeHexTx(tx)); + if (include_hex) { + // the hex-encoded transaction. used the name "hex" to be consistent + // with the verbose output of "getrawtransaction". + entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); + } } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -120,7 +120,7 @@ for (const auto &tx : block.vtx) { if (txDetails) { UniValue objTx(UniValue::VOBJ); - TxToUniv(*tx, uint256(), objTx); + TxToUniv(*tx, uint256(), objTx, true, RPCSerializationFlags()); txs.push_back(objTx); } else { txs.push_back(tx->GetId().GetHex()); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -43,7 +43,7 @@ // Blockchain contextual information (confirmations and blocktime) is not // available to code in bitcoin-common, so we query them here and push the // data into the returned UniValue. - TxToUniv(tx, uint256(), entry); + TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags()); if (!hashBlock.IsNull()) { entry.pushKV("blockhash", hashBlock.GetHex()); @@ -181,14 +181,11 @@ ". Use gettransaction for wallet transactions."); } - std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); - if (!fVerbose) { - return strHex; + return EncodeHexTx(*tx, RPCSerializationFlags()); } UniValue result(UniValue::VOBJ); - result.pushKV("hex", strHex); TxToJSON(*tx, hashBlock, result); return result; } @@ -586,7 +583,7 @@ } UniValue result(UniValue::VOBJ); - TxToUniv(CTransaction(std::move(mtx)), uint256(), result); + TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false); return result; }