Skip to content

Commit 7f1475c

Browse files
committed
rpc: update validateaddress RPCExamples to bech32
also contains the following changes: - rpc: factor out example bech32 address for RPCExamples - doc: update developer notes wrt RPCExamples addresses (mention the EXAMPLE_ADDRESS constant as an example for an invalid bech32 address suitable for RPCExamples help documentation)
1 parent 98264e2 commit 7f1475c

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
@@ -42,8 +42,8 @@ static UniValue validateaddress(const JSONRPCRequest& request)
4242
"}\n"
4343
},
4444
RPCExamples{
45-
HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
46-
+ HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
45+
HelpExampleCli("validateaddress", EXAMPLE_ADDRESS) +
46+
HelpExampleRpc("validateaddress", EXAMPLE_ADDRESS)
4747
},
4848
}.Check(request);
4949

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
@@ -3737,8 +3737,6 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
37373737
return NullUniValue;
37383738
}
37393739

3740-
const std::string example_address = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
3741-
37423740
RPCHelpMan{"getaddressinfo",
37433741
"\nReturn information about the given bitcoin address.\n"
37443742
"Some of the information will only be present if the address is in the active wallet.\n",
@@ -3791,8 +3789,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
37913789
"}\n"
37923790
},
37933791
RPCExamples{
3794-
HelpExampleCli("getaddressinfo", example_address) +
3795-
HelpExampleRpc("getaddressinfo", example_address)
3792+
HelpExampleCli("getaddressinfo", EXAMPLE_ADDRESS) +
3793+
HelpExampleRpc("getaddressinfo", EXAMPLE_ADDRESS)
37963794
},
37973795
}.Check(request);
37983796

0 commit comments

Comments
 (0)