Skip to content

Commit 820ddd4

Browse files
committed
Merge #11027: [RPC] Only return hex field once in getrawtransaction
6bbdafc Pass serialization flags and whether to include hex to TxToUniv (Andrew Chow) e029c6e Only return hex field once in getrawtransaction (Andrew Chow) Pull request description: The hex is already returned in `TxToUniv()`, no need to give it out a second time in getrawtransaction itself. Tree-SHA512: 270289f2d6dea37f51f5a42db3dae5debdbe83c6b504fccfd3391588da986ed474592c6655d522dc51022d4b08fa90ed1ebb249afe036309f95adfe3652cb262
2 parents a853229 + 6bbdafc commit 820ddd4

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/core_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ UniValue ValueFromAmount(const CAmount& amount);
3131
std::string FormatScript(const CScript& script);
3232
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
3333
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
34-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry);
34+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0);
3535

3636
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
153153
out.pushKV("addresses", a);
154154
}
155155

156-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
156+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags)
157157
{
158158
entry.pushKV("txid", tx.GetHash().GetHex());
159159
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
@@ -207,5 +207,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
207207
if (!hashBlock.IsNull())
208208
entry.pushKV("blockhash", hashBlock.GetHex());
209209

210-
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
210+
if (include_hex) {
211+
entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
212+
}
211213
}

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
125125
if(txDetails)
126126
{
127127
UniValue objTx(UniValue::VOBJ);
128-
TxToUniv(*tx, uint256(), objTx);
128+
TxToUniv(*tx, uint256(), objTx, true, RPCSerializationFlags());
129129
txs.push_back(objTx);
130130
}
131131
else

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
4141
// Blockchain contextual information (confirmations and blocktime) is not
4242
// available to code in bitcoin-common, so we query them here and push the
4343
// data into the returned UniValue.
44-
TxToUniv(tx, uint256(), entry);
44+
TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags());
4545

4646
if (!hashBlock.IsNull()) {
4747
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
@@ -160,13 +160,10 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
160160
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries") +
161161
". Use gettransaction for wallet transactions.");
162162

163-
std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags());
164-
165163
if (!fVerbose)
166-
return strHex;
164+
return EncodeHexTx(*tx, RPCSerializationFlags());
167165

168166
UniValue result(UniValue::VOBJ);
169-
result.push_back(Pair("hex", strHex));
170167
TxToJSON(*tx, hashBlock, result);
171168
return result;
172169
}
@@ -483,7 +480,7 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
483480
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
484481

485482
UniValue result(UniValue::VOBJ);
486-
TxToUniv(CTransaction(std::move(mtx)), uint256(), result);
483+
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);
487484

488485
return result;
489486
}

0 commit comments

Comments
 (0)