Skip to content

Commit d6492d4

Browse files
committed
Merge bitcoin/bitcoin#22650: Remove -deprecatedrpc=addresses flag and corresponding 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 #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 #20286 (which resolved the original issue #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
2 parents f000cdc + 43cd6b8 commit d6492d4

15 files changed

+53
-316
lines changed

doc/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ P2P and network changes
6464
Updated RPCs
6565
------------
6666

67+
- The `-deprecatedrpc=addresses` configuration option has been removed. RPCs
68+
`gettxout`, `getrawtransaction`, `decoderawtransaction`, `decodescript`,
69+
`gettransaction verbose=true` and REST endpoints `/rest/tx`, `/rest/getutxos`,
70+
`/rest/block` no longer return the `addresses` and `reqSigs` fields, which
71+
were previously deprecated in 22.0. (#22650)
72+
6773
New RPCs
6874
--------
6975

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
727727
static void OutputTxJSON(const CTransaction& tx)
728728
{
729729
UniValue entry(UniValue::VOBJ);
730-
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
730+
TxToUniv(tx, uint256(), entry);
731731

732732
std::string jsonOutput = entry.write(4);
733733
tfm::format(std::cout, "%s\n", jsonOutput);

src/core_io.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ UniValue ValueFromAmount(const CAmount amount);
4444
std::string FormatScript(const CScript& script);
4545
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
4646
std::string SighashToStr(unsigned char sighash_type);
47-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
48-
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
49-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
47+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
48+
void ScriptToUniv(const CScript& script, UniValue& out);
49+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
5050

5151
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -141,56 +141,28 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
141141
return HexStr(ssTx);
142142
}
143143

144-
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
144+
void ScriptToUniv(const CScript& script, UniValue& out)
145145
{
146-
out.pushKV("asm", ScriptToAsmStr(script));
147-
out.pushKV("hex", HexStr(script));
148-
149-
std::vector<std::vector<unsigned char>> solns;
150-
TxoutType type = Solver(script, solns);
151-
out.pushKV("type", GetTxnOutputType(type));
152-
153-
CTxDestination address;
154-
if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
155-
out.pushKV("address", EncodeDestination(address));
156-
}
146+
ScriptPubKeyToUniv(script, out, /* include_hex */ true, /* include_address */ false);
157147
}
158148

159-
// TODO: from v23 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option
160-
// this method can also be combined with `ScriptToUniv` as they will overlap
161-
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
162-
UniValue& out, bool fIncludeHex, bool include_addresses)
149+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address)
163150
{
164-
TxoutType type;
165151
CTxDestination address;
166-
std::vector<CTxDestination> addresses;
167-
int nRequired;
168152

169153
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
170-
if (fIncludeHex)
171-
out.pushKV("hex", HexStr(scriptPubKey));
154+
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
172155

173-
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired) || type == TxoutType::PUBKEY) {
174-
out.pushKV("type", GetTxnOutputType(type));
175-
return;
176-
}
156+
std::vector<std::vector<unsigned char>> solns;
157+
const TxoutType type{Solver(scriptPubKey, solns)};
177158

178-
if (ExtractDestination(scriptPubKey, address)) {
159+
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
179160
out.pushKV("address", EncodeDestination(address));
180161
}
181162
out.pushKV("type", GetTxnOutputType(type));
182-
183-
if (include_addresses) {
184-
UniValue a(UniValue::VARR);
185-
for (const CTxDestination& addr : addresses) {
186-
a.push_back(EncodeDestination(addr));
187-
}
188-
out.pushKV("addresses", a);
189-
out.pushKV("reqSigs", nRequired);
190-
}
191163
}
192164

193-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
165+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
194166
{
195167
entry.pushKV("txid", tx.GetHash().GetHex());
196168
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
@@ -249,7 +221,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add
249221
out.pushKV("n", (int64_t)i);
250222

251223
UniValue o(UniValue::VOBJ);
252-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
224+
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
253225
out.pushKV("scriptPubKey", o);
254226
vout.push_back(out);
255227

src/rpc/blockchain.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,11 +1256,8 @@ static RPCHelpMan gettxout()
12561256
{RPCResult::Type::OBJ, "scriptPubKey", "", {
12571257
{RPCResult::Type::STR, "asm", ""},
12581258
{RPCResult::Type::STR_HEX, "hex", ""},
1259-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
12601259
{RPCResult::Type::STR, "type", "The type, eg pubkeyhash"},
1261-
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
1262-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
1263-
{{RPCResult::Type::STR, "address", "bitcoin address"}}},
1260+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
12641261
}},
12651262
{RPCResult::Type::BOOL, "coinbase", "Coinbase or not"},
12661263
}},
@@ -1933,16 +1930,6 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
19331930
}
19341931
}
19351932

1936-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
1937-
{
1938-
ScriptPubKeyToUniv(scriptPubKey, out, fIncludeHex, IsDeprecatedRPCEnabled("addresses"));
1939-
}
1940-
1941-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
1942-
{
1943-
TxToUniv(tx, hashBlock, IsDeprecatedRPCEnabled("addresses"), entry, include_hex, serialize_flags, txundo);
1944-
}
1945-
19461933
template<typename T>
19471934
static inline bool SetHasKeys(const std::set<T>& set) {return false;}
19481935
template<typename T, typename Tk, typename... Args>

src/rpc/blockchain.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_RPC_BLOCKCHAIN_H
77

88
#include <amount.h>
9-
#include <core_io.h>
109
#include <streams.h>
1110
#include <sync.h>
1211

@@ -53,9 +52,6 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
5352
/** Used by getblockstats to get feerates at different percentiles by weight */
5453
void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
5554

56-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
57-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
58-
5955
NodeContext& EnsureAnyNodeContext(const std::any& context);
6056
CTxMemPool& EnsureMemPool(const NodeContext& node);
6157
CTxMemPool& EnsureAnyMemPool(const std::any& context);

src/rpc/rawtransaction.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,8 @@ static RPCHelpMan getrawtransaction()
131131
{
132132
{RPCResult::Type::STR, "asm", "the asm"},
133133
{RPCResult::Type::STR, "hex", "the hex"},
134-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
135134
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
136-
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
137-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
138-
{
139-
{RPCResult::Type::STR, "address", "bitcoin address"},
140-
}},
135+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
141136
}},
142137
}},
143138
}},
@@ -495,13 +490,8 @@ static RPCHelpMan decoderawtransaction()
495490
{
496491
{RPCResult::Type::STR, "asm", "the asm"},
497492
{RPCResult::Type::STR_HEX, "hex", "the hex"},
498-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
499493
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
500-
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
501-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
502-
{
503-
{RPCResult::Type::STR, "address", "bitcoin address"},
504-
}},
494+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
505495
}},
506496
}},
507497
}},
@@ -554,24 +544,14 @@ static RPCHelpMan decodescript()
554544
{
555545
{RPCResult::Type::STR, "asm", "Script public key"},
556546
{RPCResult::Type::STR, "type", "The output type (e.g. "+GetAllOutputTypes()+")"},
557-
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
558-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
559-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
560-
{
561-
{RPCResult::Type::STR, "address", "bitcoin address"},
562-
}},
547+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
563548
{RPCResult::Type::STR, "p2sh", /* optional */ true, "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
564549
{RPCResult::Type::OBJ, "segwit", /* optional */ true, "Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness)",
565550
{
566551
{RPCResult::Type::STR, "asm", "String representation of the script public key"},
567552
{RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"},
568553
{RPCResult::Type::STR, "type", "The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"},
569-
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
570-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
571-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
572-
{
573-
{RPCResult::Type::STR, "address", "segwit address"},
574-
}},
554+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
575555
{RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"},
576556
}},
577557
}
@@ -592,7 +572,7 @@ static RPCHelpMan decodescript()
592572
} else {
593573
// Empty scripts are valid
594574
}
595-
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
575+
ScriptPubKeyToUniv(script, r, /* include_hex */ false);
596576

597577
UniValue type;
598578
type = find_value(r, "type");
@@ -626,7 +606,7 @@ static RPCHelpMan decodescript()
626606
// Newer segwit program versions should be considered when then become available.
627607
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script));
628608
}
629-
ScriptPubKeyToUniv(segwitScr, sr, /* fIncludeHex */ true);
609+
ScriptPubKeyToUniv(segwitScr, sr, /* include_hex */ true);
630610
sr.pushKV("p2sh-segwit", EncodeDestination(ScriptHash(segwitScr)));
631611
r.pushKV("segwit", sr);
632612
}
@@ -1061,7 +1041,7 @@ static RPCHelpMan decodepsbt()
10611041
{RPCResult::Type::STR, "asm", "The asm"},
10621042
{RPCResult::Type::STR_HEX, "hex", "The hex"},
10631043
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
1064-
{RPCResult::Type::STR, "address", /*optional=*/true, "Bitcoin address if there is one"},
1044+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
10651045
}},
10661046
}},
10671047
{RPCResult::Type::OBJ_DYN, "partial_signatures", /* optional */ true, "",
@@ -1181,7 +1161,7 @@ static RPCHelpMan decodepsbt()
11811161
txout = input.witness_utxo;
11821162

11831163
UniValue o(UniValue::VOBJ);
1184-
ScriptToUniv(txout.scriptPubKey, o, true);
1164+
ScriptPubKeyToUniv(txout.scriptPubKey, o, /* include_hex */ true);
11851165

11861166
UniValue out(UniValue::VOBJ);
11871167
out.pushKV("amount", ValueFromAmount(txout.nValue));
@@ -1228,12 +1208,12 @@ static RPCHelpMan decodepsbt()
12281208
// Redeem script and witness script
12291209
if (!input.redeem_script.empty()) {
12301210
UniValue r(UniValue::VOBJ);
1231-
ScriptToUniv(input.redeem_script, r, false);
1211+
ScriptToUniv(input.redeem_script, r);
12321212
in.pushKV("redeem_script", r);
12331213
}
12341214
if (!input.witness_script.empty()) {
12351215
UniValue r(UniValue::VOBJ);
1236-
ScriptToUniv(input.witness_script, r, false);
1216+
ScriptToUniv(input.witness_script, r);
12371217
in.pushKV("witness_script", r);
12381218
}
12391219

@@ -1288,12 +1268,12 @@ static RPCHelpMan decodepsbt()
12881268
// Redeem script and witness script
12891269
if (!output.redeem_script.empty()) {
12901270
UniValue r(UniValue::VOBJ);
1291-
ScriptToUniv(output.redeem_script, r, false);
1271+
ScriptToUniv(output.redeem_script, r);
12921272
out.pushKV("redeem_script", r);
12931273
}
12941274
if (!output.witness_script.empty()) {
12951275
UniValue r(UniValue::VOBJ);
1296-
ScriptToUniv(output.witness_script, r, false);
1276+
ScriptToUniv(output.witness_script, r);
12971277
out.pushKV("witness_script", r);
12981278
}
12991279

src/script/standard.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -266,47 +266,6 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
266266
assert(false);
267267
}
268268

269-
// TODO: from v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
270-
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
271-
{
272-
addressRet.clear();
273-
std::vector<valtype> vSolutions;
274-
typeRet = Solver(scriptPubKey, vSolutions);
275-
if (typeRet == TxoutType::NONSTANDARD) {
276-
return false;
277-
} else if (typeRet == TxoutType::NULL_DATA) {
278-
// This is data, not addresses
279-
return false;
280-
}
281-
282-
if (typeRet == TxoutType::MULTISIG)
283-
{
284-
nRequiredRet = vSolutions.front()[0];
285-
for (unsigned int i = 1; i < vSolutions.size()-1; i++)
286-
{
287-
CPubKey pubKey(vSolutions[i]);
288-
if (!pubKey.IsValid())
289-
continue;
290-
291-
CTxDestination address = PKHash(pubKey);
292-
addressRet.push_back(address);
293-
}
294-
295-
if (addressRet.empty())
296-
return false;
297-
}
298-
else
299-
{
300-
nRequiredRet = 1;
301-
CTxDestination address;
302-
if (!ExtractDestination(scriptPubKey, address))
303-
return false;
304-
addressRet.push_back(address);
305-
}
306-
307-
return true;
308-
}
309-
310269
namespace {
311270
class CScriptVisitor
312271
{

src/script/standard.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,11 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
176176

177177
/**
178178
* Parse a standard scriptPubKey for the destination address. Assigns result to
179-
* the addressRet parameter and returns true if successful. For multisig
180-
* scripts, instead use ExtractDestinations. Currently only works for P2PK,
179+
* the addressRet parameter and returns true if successful. Currently only works for P2PK,
181180
* P2PKH, P2SH, P2WPKH, and P2WSH scripts.
182181
*/
183182
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
184183

185-
/**
186-
* Parse a standard scriptPubKey with one or more destination addresses. For
187-
* multisig scripts, this populates the addressRet vector with the pubkey IDs
188-
* and nRequiredRet with the n required to spend. For other destinations,
189-
* addressRet is populated with a single value and nRequiredRet is set to 1.
190-
* Returns true if successful.
191-
*
192-
* Note: this function confuses destinations (a subset of CScripts that are
193-
* encodable as an address) with key identifiers (of keys involved in a
194-
* CScript), and its use should be phased out.
195-
*
196-
* TODO: from v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
197-
*/
198-
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
199-
200184
/**
201185
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
202186
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty

0 commit comments

Comments
 (0)