Skip to content

Commit 169dce7

Browse files
committed
merge bitcoin#20286: deprecate addresses and reqSigs from rpc outputs
1 parent 7cddf70 commit 169dce7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+193
-136
lines changed

doc/REST-interface.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ $ curl localhost:19998/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff76
9898
"scriptPubKey" : {
9999
"asm" : "OP_DUP OP_HASH160 1c7cebb529b86a04c683dfa87be49de35bcf589e OP_EQUALVERIFY OP_CHECKSIG",
100100
"hex" : "76a9141c7cebb529b86a04c683dfa87be49de35bcf589e88ac",
101-
"reqSigs" : 1,
102101
"type" : "pubkeyhash",
103-
"addresses" : [
104-
"mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD"
105-
]
102+
"address" : "mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD"
106103
}
107104
}
108105
]

doc/release-notes-20286.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Updated RPCs
2+
------------
3+
4+
- The following RPCs: `gettxout`, `getrawtransaction`, `decoderawtransaction`,
5+
`decodescript`, `gettransaction`, and REST endpoints: `/rest/tx`,
6+
`/rest/getutxos`, `/rest/block` deprecated the following fields (which are no
7+
longer returned in the responses by default): `addresses`, `reqSigs`.
8+
The `-deprecatedrpc=addresses` flag must be passed for these fields to be
9+
included in the RPC response. Note that these fields are attributes of
10+
the `scriptPubKey` object returned in the RPC response. However, in the response
11+
of `decodescript` these fields are top-level attributes, and included again as attributes
12+
of the `scriptPubKey` object.
13+
14+
- When creating a hex-encoded Dash transaction using the `dash-tx` utility
15+
with the `-json` option set, the following fields: `addresses`, `reqSigs` are no longer
16+
returned in the tx output of the response.

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
676676
static void OutputTxJSON(const CTransaction& tx)
677677
{
678678
UniValue entry(UniValue::VOBJ);
679-
TxToUniv(tx, uint256(), entry);
679+
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
680680

681681
std::string jsonOutput = entry.write(4);
682682
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
@@ -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);
48+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
4949
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
50-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
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);
5151

5252
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
166166
}
167167
}
168168

169+
// TODO: from v21 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option
170+
// this method can also be combined with `ScriptToUniv` as they will overlap
169171
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
170-
UniValue& out, bool fIncludeHex)
172+
UniValue& out, bool fIncludeHex, bool include_addresses)
171173
{
172174
TxoutType type;
175+
CTxDestination address;
173176
std::vector<CTxDestination> addresses;
174177
int nRequired;
175178

@@ -182,17 +185,22 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
182185
return;
183186
}
184187

185-
out.pushKV("reqSigs", nRequired);
188+
if (ExtractDestination(scriptPubKey, address)) {
189+
out.pushKV("address", EncodeDestination(address));
190+
}
186191
out.pushKV("type", GetTxnOutputType(type));
187192

188-
UniValue a(UniValue::VARR);
189-
for (const CTxDestination& addr : addresses) {
190-
a.push_back(EncodeDestination(addr));
193+
if (include_addresses) {
194+
UniValue a(UniValue::VARR);
195+
for (const CTxDestination& addr : addresses) {
196+
a.push_back(EncodeDestination(addr));
197+
}
198+
out.pushKV("addresses", a);
199+
out.pushKV("reqSigs", nRequired);
191200
}
192-
out.pushKV("addresses", a);
193201
}
194202

195-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
203+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
196204
{
197205
uint256 txid = tx.GetHash();
198206
entry.pushKV("txid", txid.GetHex());
@@ -260,7 +268,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
260268
out.pushKV("n", (int64_t)i);
261269

262270
UniValue o(UniValue::VOBJ);
263-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
271+
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
264272
out.pushKV("scriptPubKey", o);
265273

266274
// Add spent information if spentindex is enabled

src/rpc/blockchain.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,12 @@ static RPCHelpMan gettxout()
15131513
{RPCResult::Type::STR_AMOUNT, "value", "The transaction value in " + CURRENCY_UNIT},
15141514
{RPCResult::Type::OBJ, "scriptPubKey", "",
15151515
{
1516-
{RPCResult::Type::STR_HEX, "asm", ""},
1516+
{RPCResult::Type::STR, "asm", ""},
15171517
{RPCResult::Type::STR_HEX, "hex", ""},
1518-
{RPCResult::Type::NUM, "reqSigs", "Number of required signatures"},
1518+
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
15191519
{RPCResult::Type::STR_HEX, "type", "The type, eg pubkeyhash"},
1520-
{RPCResult::Type::ARR, "addresses", "Array of Dash addresses",
1520+
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
1521+
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
15211522
{{RPCResult::Type::STR, "address", "Dash address"}}},
15221523
}},
15231524
{RPCResult::Type::BOOL, "coinbase", "Coinbase or not"},
@@ -2264,6 +2265,16 @@ void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], s
22642265
}
22652266
}
22662267

2268+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
2269+
{
2270+
ScriptPubKeyToUniv(scriptPubKey, out, fIncludeHex, IsDeprecatedRPCEnabled("addresses"));
2271+
}
2272+
2273+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
2274+
{
2275+
TxToUniv(tx, hashBlock, IsDeprecatedRPCEnabled("addresses"), entry, include_hex, txundo, ptxSpentInfo);
2276+
}
2277+
22672278
template<typename T>
22682279
static inline bool SetHasKeys(const std::set<T>& set) {return false;}
22692280
template<typename T, typename Tk, typename... Args>

src/rpc/blockchain.h

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

88
#include <amount.h>
99
#include <context.h>
10+
#include <core_io.h>
1011
#include <streams.h>
1112
#include <sync.h>
1213

@@ -57,6 +58,9 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
5758
/** Used by getblockstats to get feerates at different percentiles by weight */
5859
void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_size);
5960

61+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
62+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
63+
6064
NodeContext& EnsureAnyNodeContext(const CoreContext& context);
6165
CTxMemPool& EnsureMemPool(const NodeContext& node);
6266
CTxMemPool& EnsureAnyMemPool(const CoreContext& context);

src/rpc/rawtransaction.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ static RPCHelpMan getrawtransaction()
168168
{
169169
{RPCResult::Type::STR, "asm", "the asm"},
170170
{RPCResult::Type::STR, "hex", "the hex"},
171-
{RPCResult::Type::NUM, "reqSigs", "The required sigs"},
171+
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
172172
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
173-
{RPCResult::Type::ARR, "addresses", "",
173+
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
174+
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
174175
{
175176
{RPCResult::Type::STR, "address", "Dash address"},
176177
}},
@@ -827,9 +828,10 @@ static RPCHelpMan decoderawtransaction()
827828
{
828829
{RPCResult::Type::STR, "asm", "the asm"},
829830
{RPCResult::Type::STR_HEX, "hex", "the hex"},
830-
{RPCResult::Type::NUM, "reqSigs", "The required sigs"},
831+
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
831832
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
832-
{RPCResult::Type::ARR, "addresses", "",
833+
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
834+
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
833835
{
834836
{RPCResult::Type::STR, "address", "Dash address"},
835837
}},
@@ -883,8 +885,9 @@ static RPCHelpMan decodescript()
883885
{
884886
{RPCResult::Type::STR, "asm", "Script public key"},
885887
{RPCResult::Type::STR, "type", "The output type (e.g. "+GetAllOutputTypes()+")"},
886-
{RPCResult::Type::NUM, "reqSigs", "The required signatures"},
887-
{RPCResult::Type::ARR, "addresses", "",
888+
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
889+
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
890+
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
888891
{
889892
{RPCResult::Type::STR, "address", "Dash address"},
890893
}},

src/script/standard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
189189
return true;
190190
}
191191
case TxoutType::MULTISIG:
192-
// Multisig txns have more than one address...
193192
case TxoutType::NULL_DATA:
194193
case TxoutType::NONSTANDARD:
195194
return false;
196195
} // no default case, so the compiler can warn about missing cases
197196
assert(false);
198197
}
199198

199+
// TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
200200
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
201201
{
202202
addressRet.clear();

src/script/standard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
134134
* and nRequiredRet with the n required to spend. For other destinations,
135135
* addressRet is populated with a single value and nRequiredRet is set to 1.
136136
* Returns true if successful.
137+
*
138+
* TODO: from v21 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
137139
*/
138140
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
139141

0 commit comments

Comments
 (0)