Skip to content

Commit 8721638

Browse files
committed
rpc: remove deprecated addresses and reqSigs from rpc outputs
1 parent 03cb2b4 commit 8721638

14 files changed

+35
-291
lines changed

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: 2 additions & 2 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);
47+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
4848
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);
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: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,41 +156,24 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
156156
}
157157
}
158158

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)
159+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
163160
{
164-
TxoutType type;
165161
CTxDestination address;
166-
std::vector<CTxDestination> addresses;
167-
int nRequired;
168162

169163
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
170164
if (fIncludeHex)
171165
out.pushKV("hex", HexStr(scriptPubKey));
172166

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

178-
if (ExtractDestination(scriptPubKey, address)) {
170+
if (ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
179171
out.pushKV("address", EncodeDestination(address));
180172
}
181173
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-
}
191174
}
192175

193-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
176+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
194177
{
195178
entry.pushKV("txid", tx.GetHash().GetHex());
196179
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
@@ -249,7 +232,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add
249232
out.pushKV("n", (int64_t)i);
250233

251234
UniValue o(UniValue::VOBJ);
252-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
235+
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
253236
out.pushKV("scriptPubKey", o);
254237
vout.push_back(out);
255238

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: 5 additions & 25 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
}
@@ -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, "",

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

src/test/fuzz/script.cpp

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,46 +56,8 @@ FUZZ_TARGET_INIT(script, initialize_script)
5656
assert(script == decompressed_script);
5757
}
5858

59-
CTxDestination address;
60-
TxoutType type_ret;
61-
std::vector<CTxDestination> addresses;
62-
int required_ret;
63-
bool extract_destinations_ret = ExtractDestinations(script, type_ret, addresses, required_ret);
64-
bool extract_destination_ret = ExtractDestination(script, address);
65-
if (!extract_destinations_ret) {
66-
assert(!extract_destination_ret);
67-
if (type_ret == TxoutType::MULTISIG) {
68-
assert(addresses.empty() && required_ret == 0);
69-
} else {
70-
assert(type_ret == TxoutType::PUBKEY ||
71-
type_ret == TxoutType::NONSTANDARD ||
72-
type_ret == TxoutType::NULL_DATA);
73-
}
74-
} else {
75-
assert(required_ret >= 1 && required_ret <= 16);
76-
assert((unsigned long)required_ret == addresses.size());
77-
assert(type_ret == TxoutType::MULTISIG || required_ret == 1);
78-
}
79-
if (type_ret == TxoutType::NONSTANDARD || type_ret == TxoutType::NULL_DATA) {
80-
assert(!extract_destinations_ret);
81-
}
82-
if (!extract_destination_ret) {
83-
assert(type_ret == TxoutType::PUBKEY ||
84-
type_ret == TxoutType::NONSTANDARD ||
85-
type_ret == TxoutType::NULL_DATA ||
86-
type_ret == TxoutType::MULTISIG);
87-
} else {
88-
assert(address == addresses[0]);
89-
}
90-
if (type_ret == TxoutType::NONSTANDARD ||
91-
type_ret == TxoutType::NULL_DATA ||
92-
type_ret == TxoutType::MULTISIG) {
93-
assert(!extract_destination_ret);
94-
}
95-
9659
TxoutType which_type;
9760
bool is_standard_ret = IsStandard(script, which_type);
98-
assert(type_ret == which_type);
9961
if (!is_standard_ret) {
10062
assert(which_type == TxoutType::NONSTANDARD ||
10163
which_type == TxoutType::NULL_DATA ||
@@ -112,6 +74,20 @@ FUZZ_TARGET_INIT(script, initialize_script)
11274
which_type == TxoutType::NONSTANDARD);
11375
}
11476

77+
CTxDestination address;
78+
bool extract_destination_ret = ExtractDestination(script, address);
79+
if (!extract_destination_ret) {
80+
assert(which_type == TxoutType::PUBKEY ||
81+
which_type == TxoutType::NONSTANDARD ||
82+
which_type == TxoutType::NULL_DATA ||
83+
which_type == TxoutType::MULTISIG);
84+
}
85+
if (which_type == TxoutType::NONSTANDARD ||
86+
which_type == TxoutType::NULL_DATA ||
87+
which_type == TxoutType::MULTISIG) {
88+
assert(!extract_destination_ret);
89+
}
90+
11591
const FlatSigningProvider signing_provider;
11692
(void)InferDescriptor(script, signing_provider);
11793
(void)IsSegWitOutput(signing_provider, script);
@@ -133,11 +109,9 @@ FUZZ_TARGET_INIT(script, initialize_script)
133109
(void)ScriptToAsmStr(script, true);
134110

135111
UniValue o1(UniValue::VOBJ);
136-
ScriptPubKeyToUniv(script, o1, true, true);
137-
ScriptPubKeyToUniv(script, o1, true, false);
112+
ScriptPubKeyToUniv(script, o1, true);
138113
UniValue o2(UniValue::VOBJ);
139-
ScriptPubKeyToUniv(script, o2, false, true);
140-
ScriptPubKeyToUniv(script, o2, false, false);
114+
ScriptPubKeyToUniv(script, o2, false);
141115
UniValue o3(UniValue::VOBJ);
142116
ScriptToUniv(script, o3, true);
143117
UniValue o4(UniValue::VOBJ);

src/test/fuzz/transaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
103103
(void)IsWitnessStandard(tx, coins_view_cache);
104104

105105
UniValue u(UniValue::VOBJ);
106-
TxToUniv(tx, /* hashBlock */ uint256::ZERO, /* include_addresses */ true, u);
107-
TxToUniv(tx, /* hashBlock */ uint256::ONE, /* include_addresses */ false, u);
106+
TxToUniv(tx, /* hashBlock */ uint256::ZERO, u);
107+
TxToUniv(tx, /* hashBlock */ uint256::ONE, u);
108108
}

0 commit comments

Comments
 (0)