Skip to content

Commit c5eb76f

Browse files
meshcolliderknst
authored andcommitted
Merge 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 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
1 parent d723975 commit c5eb76f

16 files changed

+53
-305
lines changed

doc/release-notes-22650.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Updated RPCs
2+
------------
3+
4+
- The `-deprecatedrpc=addresses` configuration option has been removed. RPCs
5+
`gettxout`, `getrawtransaction`, `decoderawtransaction`, `decodescript`,
6+
`gettransaction verbose=true` and REST endpoints `/rest/tx`, `/rest/getutxos`,
7+
`/rest/block` no longer return the `addresses` and `reqSigs` fields, which
8+
were previously deprecated in 22.0. (#22650)
9+

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
691691
static void OutputTxJSON(const CTransaction& tx)
692692
{
693693
UniValue entry(UniValue::VOBJ);
694-
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
694+
TxToUniv(tx, uint256(), entry);
695695

696696
std::string jsonOutput = entry.write(4);
697697
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
@@ -45,8 +45,8 @@ UniValue ValueFromAmount(const CAmount amount);
4545
std::string FormatScript(const CScript& script);
4646
std::string EncodeHexTx(const CTransaction& tx);
4747
std::string SighashToStr(unsigned char sighash_type);
48-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
49-
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
50-
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);
48+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
49+
void ScriptToUniv(const CScript& script, UniValue& out);
50+
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);
5151

5252
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -152,56 +152,28 @@ std::string EncodeHexTx(const CTransaction& tx)
152152
return HexStr(ssTx);
153153
}
154154

155-
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
155+
void ScriptToUniv(const CScript& script, UniValue& out)
156156
{
157-
out.pushKV("asm", ScriptToAsmStr(script));
158-
out.pushKV("hex", HexStr(script));
159-
160-
std::vector<std::vector<unsigned char>> solns;
161-
TxoutType type = Solver(script, solns);
162-
out.pushKV("type", GetTxnOutputType(type));
163-
164-
CTxDestination address;
165-
if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
166-
out.pushKV("address", EncodeDestination(address));
167-
}
157+
ScriptPubKeyToUniv(script, out, /* include_hex */ true, /* include_address */ false);
168158
}
169159

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

180164
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
181-
if (fIncludeHex)
182-
out.pushKV("hex", HexStr(scriptPubKey));
165+
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
183166

184-
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired) || type == TxoutType::PUBKEY) {
185-
out.pushKV("type", GetTxnOutputType(type));
186-
return;
187-
}
167+
std::vector<std::vector<unsigned char>> solns;
168+
const TxoutType type{Solver(scriptPubKey, solns)};
188169

189-
if (ExtractDestination(scriptPubKey, address)) {
170+
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
190171
out.pushKV("address", EncodeDestination(address));
191172
}
192173
out.pushKV("type", GetTxnOutputType(type));
193-
194-
if (include_addresses) {
195-
UniValue a(UniValue::VARR);
196-
for (const CTxDestination& addr : addresses) {
197-
a.push_back(EncodeDestination(addr));
198-
}
199-
out.pushKV("addresses", a);
200-
out.pushKV("reqSigs", nRequired);
201-
}
202174
}
203175

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

271243
UniValue o(UniValue::VOBJ);
272-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
244+
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
273245
out.pushKV("scriptPubKey", o);
274246

275247
// Add spent information if spentindex is enabled

src/rpc/blockchain.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
169169
// coinbase transaction (i == 0) doesn't have undo data
170170
const CTxUndo* txundo = (have_undo && i) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
171171
UniValue objTx(UniValue::VOBJ);
172-
TxToUniv(*tx, uint256(), objTx, true, txundo);
172+
TxToUniv(*tx, uint256(), objTx, true, 0, txundo);
173173
bool fLocked = isman.IsLocked(tx->GetHash());
174174
objTx.pushKV("instantlock", fLocked || result["chainlock"].get_bool());
175175
objTx.pushKV("instantlock_internal", fLocked);
@@ -1207,11 +1207,8 @@ static RPCHelpMan gettxout()
12071207
{
12081208
{RPCResult::Type::STR, "asm", ""},
12091209
{RPCResult::Type::STR_HEX, "hex", ""},
1210-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
12111210
{RPCResult::Type::STR_HEX, "type", "The type, eg pubkeyhash"},
12121211
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
1213-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
1214-
{{RPCResult::Type::STR, "address", "Dash address"}}},
12151212
}},
12161213
{RPCResult::Type::BOOL, "coinbase", "Coinbase or not"},
12171214
}},
@@ -1899,16 +1896,6 @@ void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], s
18991896
}
19001897
}
19011898

1902-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
1903-
{
1904-
ScriptPubKeyToUniv(scriptPubKey, out, fIncludeHex, IsDeprecatedRPCEnabled("addresses"));
1905-
}
1906-
1907-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
1908-
{
1909-
TxToUniv(tx, hashBlock, IsDeprecatedRPCEnabled("addresses"), entry, include_hex, txundo, ptxSpentInfo);
1910-
}
1911-
19121899
template<typename T>
19131900
static inline bool SetHasKeys(const std::set<T>& set) {return false;}
19141901
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 <consensus/amount.h>
9-
#include <core_io.h>
109
#include <fs.h>
1110
#include <streams.h>
1211
#include <sync.h>
@@ -49,9 +48,6 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
4948
/** Used by getblockstats to get feerates at different percentiles by weight */
5049
void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_size);
5150

52-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
53-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
54-
5551
/**
5652
* Helper to create UTXO snapshots given a chainstate and a file handle.
5753
* @return a UniValue map containing metadata about the snapshot.

src/rpc/rawtransaction.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool
9696
txSpentInfoPtr = &txSpentInfo;
9797
}
9898

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

101101
bool chainLock = false;
102102
if (!hashBlock.IsNull()) {
@@ -178,13 +178,8 @@ static RPCHelpMan getrawtransaction()
178178
{
179179
{RPCResult::Type::STR, "asm", "the asm"},
180180
{RPCResult::Type::STR, "hex", "the hex"},
181-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
182181
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
183-
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
184-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
185-
{
186-
{RPCResult::Type::STR, "address", "Dash address"},
187-
}},
182+
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
188183
}},
189184
}},
190185
}},
@@ -763,13 +758,8 @@ static RPCHelpMan decoderawtransaction()
763758
{
764759
{RPCResult::Type::STR, "asm", "the asm"},
765760
{RPCResult::Type::STR_HEX, "hex", "the hex"},
766-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
767761
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
768-
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
769-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
770-
{
771-
{RPCResult::Type::STR, "address", "Dash address"},
772-
}},
762+
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
773763
}},
774764
}},
775765
}},
@@ -811,13 +801,7 @@ static RPCHelpMan decodescript()
811801
{
812802
{RPCResult::Type::STR, "asm", "Script public key"},
813803
{RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
814-
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
815-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
816-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
817-
{
818-
{RPCResult::Type::STR, "address", "Dash address"},
819-
}},
820-
{RPCResult::Type::STR, "p2sh", "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
804+
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
821805
},
822806
},
823807
RPCExamples{
@@ -836,7 +820,7 @@ static RPCHelpMan decodescript()
836820
} else {
837821
// Empty scripts are valid
838822
}
839-
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
823+
ScriptPubKeyToUniv(script, r, /* include_hex */ false);
840824

841825
std::vector<std::vector<unsigned char>> solutions_data;
842826
const TxoutType which_type{Solver(script, solutions_data)};
@@ -1490,7 +1474,7 @@ static RPCHelpMan decodepsbt()
14901474
// Redeem script
14911475
if (!input.redeem_script.empty()) {
14921476
UniValue r(UniValue::VOBJ);
1493-
ScriptToUniv(input.redeem_script, r, false);
1477+
ScriptToUniv(input.redeem_script, r);
14941478
in.pushKV("redeem_script", r);
14951479
}
14961480

@@ -1588,7 +1572,7 @@ static RPCHelpMan decodepsbt()
15881572
// Redeem script
15891573
if (!output.redeem_script.empty()) {
15901574
UniValue r(UniValue::VOBJ);
1591-
ScriptToUniv(output.redeem_script, r, false);
1575+
ScriptToUniv(output.redeem_script, r);
15921576
out.pushKV("redeem_script", r);
15931577
}
15941578

src/script/standard.cpp

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

199-
// TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
200-
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
201-
{
202-
addressRet.clear();
203-
std::vector<valtype> vSolutions;
204-
typeRet = Solver(scriptPubKey, vSolutions);
205-
if (typeRet == TxoutType::NONSTANDARD) {
206-
return false;
207-
} else if (typeRet == TxoutType::NULL_DATA) {
208-
// This is data, not addresses
209-
return false;
210-
}
211-
212-
if (typeRet == TxoutType::MULTISIG)
213-
{
214-
nRequiredRet = vSolutions.front()[0];
215-
for (unsigned int i = 1; i < vSolutions.size()-1; i++)
216-
{
217-
CPubKey pubKey(vSolutions[i]);
218-
if (!pubKey.IsValid())
219-
continue;
220-
221-
CTxDestination address = PKHash(pubKey);
222-
addressRet.push_back(address);
223-
}
224-
225-
if (addressRet.empty())
226-
return false;
227-
}
228-
else
229-
{
230-
nRequiredRet = 1;
231-
CTxDestination address;
232-
if (!ExtractDestination(scriptPubKey, address))
233-
return false;
234-
addressRet.push_back(address);
235-
}
236-
237-
return true;
238-
}
239-
240199
namespace {
241200
class CScriptVisitor
242201
{

src/script/standard.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,11 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
122122

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

131-
/**
132-
* Parse a standard scriptPubKey with one or more destination addresses. For
133-
* multisig scripts, this populates the addressRet vector with the pubkey IDs
134-
* and nRequiredRet with the n required to spend. For other destinations,
135-
* addressRet is populated with a single value and nRequiredRet is set to 1.
136-
* Returns true if successful.
137-
*
138-
* TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
139-
*/
140-
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
141-
142130
/**
143131
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
144132
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty

0 commit comments

Comments
 (0)