Skip to content

Commit

Permalink
Merge pull request ElementsProject#1108 from jamesdorfman/fix-signblo…
Browse files Browse the repository at this point in the history
…ck-witness-rpc

RPC: correctly display signblock_witness post-dynafed
  • Loading branch information
stevenroose authored Apr 26, 2022
2 parents cf2eb09 + f79c148 commit 80862ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class CBlock;
class CBlockHeader;
class CScript;
struct CScriptWitness;
class CTransaction;
struct CMutableTransaction;
class uint256;
Expand Down Expand Up @@ -44,6 +45,7 @@ int ParseSighashString(const UniValue& sighash);
UniValue ValueFromAmount(const CAmount& amount);
std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
UniValue EncodeHexScriptWitness(const CScriptWitness& witness);
std::string SighashToStr(unsigned char sighash_type);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
Expand Down
9 changes: 9 additions & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
return HexStr(ssTx);
}

UniValue EncodeHexScriptWitness(const CScriptWitness& witness)
{
UniValue witness_hex(UniValue::VARR);
for (const auto &item : witness.stack) {
witness_hex.push_back(HexStr(item));
}
return witness_hex;
}

void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
{
out.pushKV("asm", ScriptToAsmStr(script));
Expand Down
9 changes: 6 additions & 3 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
result.pushKV("difficulty", GetDifficulty(blockindex));
result.pushKV("chainwork", blockindex->nChainWork.GetHex());
} else {
result.pushKV("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution));
result.pushKV("signblock_witness_hex", HexStr(blockindex->proof.solution));
if (!blockindex->dynafed_params.IsNull()) {
if (blockindex->dynafed_params.IsNull()) {
result.pushKV("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution));
result.pushKV("signblock_witness_hex", HexStr(blockindex->proof.solution));
} else {
result.pushKV("signblock_witness_hex", EncodeHexScriptWitness(blockindex->m_signblock_witness));
result.pushKV("dynamic_parameters", dynaParamsToJSON(blockindex->dynafed_params));
}
}
Expand Down Expand Up @@ -218,6 +220,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
result.pushKV("signblock_witness_hex", HexStr(blockindex->proof.solution));
result.pushKV("signblock_challenge", HexStr(blockindex->proof.challenge));
} else {
result.pushKV("signblock_witness_hex", EncodeHexScriptWitness(blockindex->m_signblock_witness));
result.pushKV("dynamic_parameters", dynaParamsToJSON(block.m_dynafed_params));
}
}
Expand Down

0 comments on commit 80862ff

Please sign in to comment.