Skip to content

Commit 56fc2df

Browse files
committed
Merge #18122: rpc: update validateaddress RPCExamples to bech32
7f1475c rpc: update validateaddress RPCExamples to bech32 (Sebastian Falbesoner) Pull request description: Another small step to get rid of legacy addresses in the RPC help texts and by that encourage the use of bech32 addresses by default. The (invalid) address is the same as in the `getaddressinfo` RPC (see 2ee0cb3, kudos to jonatack!), I don't think it adds any value to have a different example address per RPC. ACKs for top commit: fanquake: ACK 7f1475c MarcoFalke: ACK 7f1475c Tree-SHA512: 2350f61fa942a9053f9f5c860ea446965dc7209c71c81bdb98a859d03ca23b225ad72c9c506e4a55c8d8988823d9cfbe808c1a452a1eeadb70ab186b146dd4ca
2 parents eddcbfb + 7f1475c commit 56fc2df

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

doc/developer-notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,8 @@ A few guidelines for introducing and reviewing new RPC interfaces:
10891089
new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly
10901090
showing up in the command list.
10911091

1092-
- Use *invalid* bech32 addresses for `RPCExamples` help documentation.
1092+
- Use *invalid* bech32 addresses (e.g. the constant `EXAMPLE_ADDRESS`) for
1093+
`RPCExamples` help documentation.
10931094

10941095
- *Rationale*: Prevent accidental transactions by users and encourage the use
10951096
of bech32 addresses by default.

src/rpc/misc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static UniValue validateaddress(const JSONRPCRequest& request)
4444
"}\n"
4545
},
4646
RPCExamples{
47-
HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
48-
+ HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
47+
HelpExampleCli("validateaddress", EXAMPLE_ADDRESS) +
48+
HelpExampleRpc("validateaddress", EXAMPLE_ADDRESS)
4949
},
5050
}.Check(request);
5151

src/rpc/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <tuple>
1515

1616
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
17+
const std::string EXAMPLE_ADDRESS = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
1718

1819
void RPCTypeCheck(const UniValue& params,
1920
const std::list<UniValueType>& typesExpected,

src/rpc/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
*/
2929
extern const std::string UNIX_EPOCH_TIME;
3030

31+
/**
32+
* Example bech32 address used in multiple RPCExamples. The address is intentionally
33+
* invalid to prevent accidental transactions by users.
34+
*/
35+
extern const std::string EXAMPLE_ADDRESS;
36+
3137
class FillableSigningProvider;
3238
class CPubKey;
3339
class CScript;

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,8 +3724,6 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
37243724
return NullUniValue;
37253725
}
37263726

3727-
const std::string example_address = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
3728-
37293727
RPCHelpMan{"getaddressinfo",
37303728
"\nReturn information about the given bitcoin address.\n"
37313729
"Some of the information will only be present if the address is in the active wallet.\n",
@@ -3778,8 +3776,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
37783776
"}\n"
37793777
},
37803778
RPCExamples{
3781-
HelpExampleCli("getaddressinfo", example_address) +
3782-
HelpExampleRpc("getaddressinfo", example_address)
3779+
HelpExampleCli("getaddressinfo", EXAMPLE_ADDRESS) +
3780+
HelpExampleRpc("getaddressinfo", EXAMPLE_ADDRESS)
37833781
},
37843782
}.Check(request);
37853783

0 commit comments

Comments
 (0)