Backport bitcoin#11027: [RPC] Only return hex field once in getrawtransaction (#3298)

* 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

* Remove backported traces of RPCSerializationFlags

We don't have this in Dash

Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
This commit is contained in:
Alexander Block 2020-01-22 11:36:22 +01:00 committed by UdjinM6
parent b7a89d3492
commit 1dd2b11000
4 changed files with 9 additions and 9 deletions

View File

@ -33,6 +33,6 @@ UniValue ValueFromAmount(const CAmount& amount);
std::string FormatScript(const CScript& script); std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx); std::string EncodeHexTx(const CTransaction& tx);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); 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, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
#endif // BITCOIN_CORE_IO_H #endif // BITCOIN_CORE_IO_H

View File

@ -160,7 +160,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
out.pushKV("addresses", a); 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, const CSpentIndexTxInfo* ptxSpentInfo)
{ {
uint256 txid = tx.GetHash(); uint256 txid = tx.GetHash();
entry.pushKV("txid", txid.GetHex()); entry.pushKV("txid", txid.GetHex());
@ -284,5 +284,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
if (!hashBlock.IsNull()) if (!hashBlock.IsNull())
entry.pushKV("blockhash", hashBlock.GetHex()); entry.pushKV("blockhash", hashBlock.GetHex());
if (include_hex) {
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction". entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".
} }
}

View File

@ -140,7 +140,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
if(txDetails) if(txDetails)
{ {
UniValue objTx(UniValue::VOBJ); UniValue objTx(UniValue::VOBJ);
TxToUniv(*tx, uint256(), objTx); TxToUniv(*tx, uint256(), objTx, true);
bool fLocked = llmq::quorumInstantSendManager->IsLocked(tx->GetHash()); bool fLocked = llmq::quorumInstantSendManager->IsLocked(tx->GetHash());
objTx.push_back(Pair("instantlock", fLocked || chainLock)); objTx.push_back(Pair("instantlock", fLocked || chainLock));
objTx.push_back(Pair("instantlock_internal", fLocked)); objTx.push_back(Pair("instantlock_internal", fLocked));

View File

@ -72,7 +72,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
} }
} }
TxToUniv(tx, uint256(), entry, &txSpentInfo); TxToUniv(tx, uint256(), entry, true, &txSpentInfo);
bool chainLock = false; bool chainLock = false;
if (!hashBlock.IsNull()) { if (!hashBlock.IsNull()) {
@ -204,10 +204,8 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries") + : "No such mempool transaction. Use -txindex to enable blockchain transaction queries") +
". Use gettransaction for wallet transactions."); ". Use gettransaction for wallet transactions.");
std::string strHex = EncodeHexTx(*tx);
if (!fVerbose) if (!fVerbose)
return strHex; return EncodeHexTx(*tx);
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
TxToJSON(*tx, hashBlock, result); TxToJSON(*tx, hashBlock, result);
@ -520,7 +518,7 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
TxToUniv(CTransaction(std::move(mtx)), uint256(), result); TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);
return result; return result;
} }