mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
refactor: share logic between ScriptPubKeyToUniv and ScriptToUniv
This commit is contained in:
parent
8721638daa
commit
d64deac7b8
4 changed files with 13 additions and 25 deletions
|
@ -44,8 +44,8 @@ UniValue ValueFromAmount(const CAmount amount);
|
|||
std::string FormatScript(const CScript& script);
|
||||
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
|
||||
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);
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_address = true);
|
||||
void ScriptToUniv(const CScript& script, UniValue& out);
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
|
||||
|
||||
#endif // BITCOIN_CORE_IO_H
|
||||
|
|
|
@ -141,22 +141,12 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
|
|||
return HexStr(ssTx);
|
||||
}
|
||||
|
||||
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
|
||||
void ScriptToUniv(const CScript& script, UniValue& out)
|
||||
{
|
||||
out.pushKV("asm", ScriptToAsmStr(script));
|
||||
out.pushKV("hex", HexStr(script));
|
||||
|
||||
std::vector<std::vector<unsigned char>> solns;
|
||||
TxoutType type = Solver(script, solns);
|
||||
out.pushKV("type", GetTxnOutputType(type));
|
||||
|
||||
CTxDestination address;
|
||||
if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
|
||||
out.pushKV("address", EncodeDestination(address));
|
||||
}
|
||||
ScriptPubKeyToUniv(script, out, /* fIncludeHex */ true, /* include_address */ false);
|
||||
}
|
||||
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_address)
|
||||
{
|
||||
CTxDestination address;
|
||||
|
||||
|
@ -165,9 +155,9 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fInclud
|
|||
out.pushKV("hex", HexStr(scriptPubKey));
|
||||
|
||||
std::vector<std::vector<unsigned char>> solns;
|
||||
TxoutType type = Solver(scriptPubKey, solns);
|
||||
const TxoutType type{Solver(scriptPubKey, solns)};
|
||||
|
||||
if (ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
|
||||
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
|
||||
out.pushKV("address", EncodeDestination(address));
|
||||
}
|
||||
out.pushKV("type", GetTxnOutputType(type));
|
||||
|
|
|
@ -1161,7 +1161,7 @@ static RPCHelpMan decodepsbt()
|
|||
txout = input.witness_utxo;
|
||||
|
||||
UniValue o(UniValue::VOBJ);
|
||||
ScriptToUniv(txout.scriptPubKey, o, true);
|
||||
ScriptPubKeyToUniv(txout.scriptPubKey, o, /* fIncludeHex */ true);
|
||||
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.pushKV("amount", ValueFromAmount(txout.nValue));
|
||||
|
@ -1208,12 +1208,12 @@ static RPCHelpMan decodepsbt()
|
|||
// Redeem script and witness script
|
||||
if (!input.redeem_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(input.redeem_script, r, false);
|
||||
ScriptToUniv(input.redeem_script, r);
|
||||
in.pushKV("redeem_script", r);
|
||||
}
|
||||
if (!input.witness_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(input.witness_script, r, false);
|
||||
ScriptToUniv(input.witness_script, r);
|
||||
in.pushKV("witness_script", r);
|
||||
}
|
||||
|
||||
|
@ -1268,12 +1268,12 @@ static RPCHelpMan decodepsbt()
|
|||
// Redeem script and witness script
|
||||
if (!output.redeem_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(output.redeem_script, r, false);
|
||||
ScriptToUniv(output.redeem_script, r);
|
||||
out.pushKV("redeem_script", r);
|
||||
}
|
||||
if (!output.witness_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(output.witness_script, r, false);
|
||||
ScriptToUniv(output.witness_script, r);
|
||||
out.pushKV("witness_script", r);
|
||||
}
|
||||
|
||||
|
|
|
@ -113,9 +113,7 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||
UniValue o2(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(script, o2, false);
|
||||
UniValue o3(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o3, true);
|
||||
UniValue o4(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o4, false);
|
||||
ScriptToUniv(script, o3);
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
|
|
Loading…
Add table
Reference in a new issue