Skip to content

Commit

Permalink
Merge bitcoin#22650: Remove -deprecatedrpc=addresses flag and corresp…
Browse files Browse the repository at this point in the history
…onding code/logic

43cd6b8 doc: add release notes for removal of the -deprecatedrpc=addresses flag (Michael Dietz)
2b1fdc2 refactor: minor styling, prefer snake case and same line if (Michael Dietz)
d64deac refactor: share logic between ScriptPubKeyToUniv and ScriptToUniv (Michael Dietz)
8721638 rpc: remove deprecated addresses and reqSigs from rpc outputs (Michael Dietz)

Pull request description:

  Resolves bitcoin#21797 now that we've branched-off to v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed.

   `-deprecatedrpc=addresses` was initially added in this PR bitcoin#20286 (which resolved the original issue bitcoin#20102).

  Some chunks of code and logic are no longer used/necessary with the removal of this, and therefore some minor refactoring is done in this PR as well (separated commits)

ACKs for top commit:
  MarcoFalke:
    re-ACK 43cd6b8 🐉
  meshcollider:
    Code review ACK 43cd6b8
  jonatack:
    ACK 43cd6b8 per `git range-diff a9d0cec 92dc5e9 43cd6b8`, also rebased to latest master, debug built + quick re-review of each commit to bring back context, and ran tests locally at the final commit

Tree-SHA512: fba83495e396d3c06f0dcf49292f14f4aa6b68fa758f0503941fade1a6e7271cda8378e2734af1faea550d1b43c85a36c52ebcc9dec0732936f9233b4b97901c
  • Loading branch information
meshcollider authored and knst committed Feb 11, 2025
1 parent d723975 commit adef879
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 305 deletions.
9 changes: 9 additions & 0 deletions doc/release-notes-22650.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Updated RPCs
------------

- The `-deprecatedrpc=addresses` configuration option has been removed. RPCs
`gettxout`, `getrawtransaction`, `decoderawtransaction`, `decodescript`,
`gettransaction verbose=true` and REST endpoints `/rest/tx`, `/rest/getutxos`,
`/rest/block` no longer return the `addresses` and `reqSigs` fields, which
were previously deprecated in 21.0. (#6569)

2 changes: 1 addition & 1 deletion src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
static void OutputTxJSON(const CTransaction& tx)
{
UniValue entry(UniValue::VOBJ);
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
TxToUniv(tx, uint256(), entry);

std::string jsonOutput = entry.write(4);
tfm::format(std::cout, "%s\n", jsonOutput);
Expand Down
6 changes: 3 additions & 3 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ UniValue ValueFromAmount(const CAmount amount);
std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx);
std::string SighashToStr(unsigned char sighash_type);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, 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, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);

#endif // BITCOIN_CORE_IO_H
46 changes: 9 additions & 37 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,56 +152,28 @@ std::string EncodeHexTx(const CTransaction& tx)
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, /* include_hex */ true, /* include_address */ false);
}

// TODO: from v21 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option
// this method can also be combined with `ScriptToUniv` as they will overlap
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
UniValue& out, bool fIncludeHex, bool include_addresses)
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address)
{
TxoutType type;
CTxDestination address;
std::vector<CTxDestination> addresses;
int nRequired;

out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
if (fIncludeHex)
out.pushKV("hex", HexStr(scriptPubKey));
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));

if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired) || type == TxoutType::PUBKEY) {
out.pushKV("type", GetTxnOutputType(type));
return;
}
std::vector<std::vector<unsigned char>> solns;
const TxoutType type{Solver(scriptPubKey, solns)};

if (ExtractDestination(scriptPubKey, address)) {
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
out.pushKV("address", EncodeDestination(address));
}
out.pushKV("type", GetTxnOutputType(type));

if (include_addresses) {
UniValue a(UniValue::VARR);
for (const CTxDestination& addr : addresses) {
a.push_back(EncodeDestination(addr));
}
out.pushKV("addresses", a);
out.pushKV("reqSigs", nRequired);
}
}

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
{
uint256 txid = tx.GetHash();
entry.pushKV("txid", txid.GetHex());
Expand Down Expand Up @@ -269,7 +241,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add
out.pushKV("n", (int64_t)i);

UniValue o(UniValue::VOBJ);
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
out.pushKV("scriptPubKey", o);

// Add spent information if spentindex is enabled
Expand Down
15 changes: 1 addition & 14 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
// coinbase transaction (i == 0) doesn't have undo data
const CTxUndo* txundo = (have_undo && i) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
UniValue objTx(UniValue::VOBJ);
TxToUniv(*tx, uint256(), objTx, true, txundo);
TxToUniv(*tx, uint256(), objTx, true, 0, txundo);
bool fLocked = isman.IsLocked(tx->GetHash());
objTx.pushKV("instantlock", fLocked || result["chainlock"].get_bool());
objTx.pushKV("instantlock_internal", fLocked);
Expand Down Expand Up @@ -1207,11 +1207,8 @@ static RPCHelpMan gettxout()
{
{RPCResult::Type::STR, "asm", ""},
{RPCResult::Type::STR_HEX, "hex", ""},
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
{RPCResult::Type::STR_HEX, "type", "The type, eg pubkeyhash"},
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
{{RPCResult::Type::STR, "address", "Dash address"}}},
}},
{RPCResult::Type::BOOL, "coinbase", "Coinbase or not"},
}},
Expand Down Expand Up @@ -1899,16 +1896,6 @@ void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], s
}
}

void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
{
ScriptPubKeyToUniv(scriptPubKey, out, fIncludeHex, IsDeprecatedRPCEnabled("addresses"));
}

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
{
TxToUniv(tx, hashBlock, IsDeprecatedRPCEnabled("addresses"), entry, include_hex, txundo, ptxSpentInfo);
}

template<typename T>
static inline bool SetHasKeys(const std::set<T>& set) {return false;}
template<typename T, typename Tk, typename... Args>
Expand Down
4 changes: 0 additions & 4 deletions src/rpc/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define BITCOIN_RPC_BLOCKCHAIN_H

#include <consensus/amount.h>
#include <core_io.h>
#include <fs.h>
#include <streams.h>
#include <sync.h>
Expand Down Expand Up @@ -49,9 +48,6 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
/** Used by getblockstats to get feerates at different percentiles by weight */
void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_size);

void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);

/**
* Helper to create UTXO snapshots given a chainstate and a file handle.
* @return a UniValue map containing metadata about the snapshot.
Expand Down
30 changes: 7 additions & 23 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool
txSpentInfoPtr = &txSpentInfo;
}

TxToUniv(tx, uint256(), entry, true, /* txundo = */ nullptr, txSpentInfoPtr);
TxToUniv(tx, uint256(), entry, true, 0, /* txundo = */ nullptr, txSpentInfoPtr);

bool chainLock = false;
if (!hashBlock.IsNull()) {
Expand Down Expand Up @@ -178,13 +178,8 @@ static RPCHelpMan getrawtransaction()
{
{RPCResult::Type::STR, "asm", "the asm"},
{RPCResult::Type::STR, "hex", "the hex"},
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
{
{RPCResult::Type::STR, "address", "Dash address"},
}},
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
}},
}},
}},
Expand Down Expand Up @@ -763,13 +758,8 @@ static RPCHelpMan decoderawtransaction()
{
{RPCResult::Type::STR, "asm", "the asm"},
{RPCResult::Type::STR_HEX, "hex", "the hex"},
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
{
{RPCResult::Type::STR, "address", "Dash address"},
}},
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
}},
}},
}},
Expand Down Expand Up @@ -811,13 +801,7 @@ static RPCHelpMan decodescript()
{
{RPCResult::Type::STR, "asm", "Script public key"},
{RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
{
{RPCResult::Type::STR, "address", "Dash address"},
}},
{RPCResult::Type::STR, "p2sh", "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
},
},
RPCExamples{
Expand All @@ -836,7 +820,7 @@ static RPCHelpMan decodescript()
} else {
// Empty scripts are valid
}
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
ScriptPubKeyToUniv(script, r, /* include_hex */ false);

std::vector<std::vector<unsigned char>> solutions_data;
const TxoutType which_type{Solver(script, solutions_data)};
Expand Down Expand Up @@ -1490,7 +1474,7 @@ static RPCHelpMan decodepsbt()
// Redeem 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);
}

Expand Down Expand Up @@ -1588,7 +1572,7 @@ static RPCHelpMan decodepsbt()
// Redeem 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);
}

Expand Down
41 changes: 0 additions & 41 deletions src/script/standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,47 +196,6 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
assert(false);
}

// TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
{
addressRet.clear();
std::vector<valtype> vSolutions;
typeRet = Solver(scriptPubKey, vSolutions);
if (typeRet == TxoutType::NONSTANDARD) {
return false;
} else if (typeRet == TxoutType::NULL_DATA) {
// This is data, not addresses
return false;
}

if (typeRet == TxoutType::MULTISIG)
{
nRequiredRet = vSolutions.front()[0];
for (unsigned int i = 1; i < vSolutions.size()-1; i++)
{
CPubKey pubKey(vSolutions[i]);
if (!pubKey.IsValid())
continue;

CTxDestination address = PKHash(pubKey);
addressRet.push_back(address);
}

if (addressRet.empty())
return false;
}
else
{
nRequiredRet = 1;
CTxDestination address;
if (!ExtractDestination(scriptPubKey, address))
return false;
addressRet.push_back(address);
}

return true;
}

namespace {
class CScriptVisitor
{
Expand Down
14 changes: 1 addition & 13 deletions src/script/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,11 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c

/**
* Parse a standard scriptPubKey for the destination address. Assigns result to
* the addressRet parameter and returns true if successful. For multisig
* scripts, instead use ExtractDestinations. Currently only works for P2PK,
* the addressRet parameter and returns true if successful. Currently only works for P2PK,
* P2PKH, and P2SH scripts.
*/
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);

/**
* Parse a standard scriptPubKey with one or more destination addresses. For
* multisig scripts, this populates the addressRet vector with the pubkey IDs
* and nRequiredRet with the n required to spend. For other destinations,
* addressRet is populated with a single value and nRequiredRet is set to 1.
* Returns true if successful.
*
* TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
*/
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);

/**
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty
Expand Down
Loading

0 comments on commit adef879

Please sign in to comment.