Skip to content

Commit

Permalink
Merge bitcoin#11027: [RPC] Only return hex field once in getrawtransa…
Browse files Browse the repository at this point in the history
…ction

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
  • Loading branch information
laanwj authored and codablock committed Jan 21, 2020
1 parent 5b4fe43 commit 786dc78
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ UniValue ValueFromAmount(const CAmount& amount);
std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);

#endif // BITCOIN_CORE_IO_H
6 changes: 4 additions & 2 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
out.pushKV("addresses", a);
}

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, const CSpentIndexTxInfo* ptxSpentInfo)
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CSpentIndexTxInfo* ptxSpentInfo)
{
uint256 txid = tx.GetHash();
entry.pushKV("txid", txid.GetHex());
Expand Down Expand Up @@ -283,5 +283,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
if (!hashBlock.IsNull())
entry.pushKV("blockhash", hashBlock.GetHex());

entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
if (include_hex) {
entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
}
}
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
if(txDetails)
{
UniValue objTx(UniValue::VOBJ);
TxToUniv(*tx, uint256(), objTx);
TxToUniv(*tx, uint256(), objTx, true, RPCSerializationFlags());
bool fLocked = llmq::quorumInstantSendManager->IsLocked(tx->GetHash());
objTx.push_back(Pair("instantlock", fLocked || chainLock));
objTx.push_back(Pair("instantlock_internal", fLocked));
Expand Down
8 changes: 3 additions & 5 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
}
}

TxToUniv(tx, uint256(), entry, &txSpentInfo);
TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags(), &txSpentInfo);

bool chainLock = false;
if (!hashBlock.IsNull()) {
Expand Down Expand Up @@ -204,10 +204,8 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries") +
". Use gettransaction for wallet transactions.");

std::string strHex = EncodeHexTx(*tx);

if (!fVerbose)
return strHex;
return EncodeHexTx(*tx, RPCSerializationFlags());

UniValue result(UniValue::VOBJ);
TxToJSON(*tx, hashBlock, result);
Expand Down Expand Up @@ -519,7 +517,7 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");

UniValue result(UniValue::VOBJ);
TxToUniv(CTransaction(std::move(mtx)), uint256(), result);
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);

return result;
}
Expand Down

0 comments on commit 786dc78

Please sign in to comment.