Skip to content

Commit

Permalink
Fix getblock older hex behaviour (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Aug 7, 2023
1 parent aa90c87 commit e6da5f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, int version)
{
const auto txInToUniValue = [](const CTransaction& tx, const CTxIn& txin, const unsigned int index, bool include_hex) {
const auto txInToUniValue = [](const CTransaction& tx, const CTxIn& txin, const unsigned int index, bool include_hex, int version) {
UniValue in(UniValue::VOBJ);
if (tx.IsCoinBase())
in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
Expand All @@ -194,7 +194,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
in.pushKV("vout", (int64_t)txin.prevout.n);
UniValue o(UniValue::VOBJ);
o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
if (include_hex) {
if (include_hex || version <= 2) {
o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
}
in.pushKV("scriptSig", o);
Expand All @@ -215,7 +215,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
out.pushKV("value", ValueFromAmount(txout.nValue));
out.pushKV("n", (int64_t)index);
UniValue o(UniValue::VOBJ);
ScriptPubKeyToUniv(txout.scriptPubKey, o, include_hex);
ScriptPubKeyToUniv(txout.scriptPubKey, o, include_hex || version <= 2);
out.pushKV("scriptPubKey", o);
// We skip this for v3+ as we tokenId field is unused.
if (version <= 2 && tx.nVersion >= CTransaction::TOKENS_MIN_VERSION) {
Expand All @@ -235,7 +235,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,

UniValue vin(UniValue::VARR);
for (unsigned int i = 0; i < tx.vin.size(); i++) {
vin.push_back(txInToUniValue(tx, tx.vin[i], i, include_hex));
vin.push_back(txInToUniValue(tx, tx.vin[i], i, include_hex, version));
}
entry.pushKV("vin", vin);

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
{
if (txDetails) {
UniValue objTx(UniValue::VOBJ);
TxToUniv(*tx, uint256(), objTx, version > 3, RPCSerializationFlags(), version);
TxToUniv(*tx, uint256(), objTx, version != 3, RPCSerializationFlags(), version);
if (version > 2) {
if (auto r = txVmInfo(*tx); r) {
objTx.pushKV("vm", *r);
Expand Down

0 comments on commit e6da5f3

Please sign in to comment.