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)
This commit is contained in:
Sebastian Falbesoner 2020-02-11 23:03:19 +01:00
parent 98264e2ccb
commit 7f1475c711
5 changed files with 13 additions and 7 deletions

View file

@ -1089,7 +1089,8 @@ A few guidelines for introducing and reviewing new RPC interfaces:
new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly
showing up in the command list. showing up in the command list.
- Use *invalid* bech32 addresses for `RPCExamples` help documentation. - Use *invalid* bech32 addresses (e.g. the constant `EXAMPLE_ADDRESS`) for
`RPCExamples` help documentation.
- *Rationale*: Prevent accidental transactions by users and encourage the use - *Rationale*: Prevent accidental transactions by users and encourage the use
of bech32 addresses by default. of bech32 addresses by default.

View file

@ -42,8 +42,8 @@ static UniValue validateaddress(const JSONRPCRequest& request)
"}\n" "}\n"
}, },
RPCExamples{ RPCExamples{
HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") HelpExampleCli("validateaddress", EXAMPLE_ADDRESS) +
+ HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") HelpExampleRpc("validateaddress", EXAMPLE_ADDRESS)
}, },
}.Check(request); }.Check(request);

View file

@ -14,6 +14,7 @@
#include <tuple> #include <tuple>
const std::string UNIX_EPOCH_TIME = "UNIX epoch time"; const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
void RPCTypeCheck(const UniValue& params, void RPCTypeCheck(const UniValue& params,
const std::list<UniValueType>& typesExpected, const std::list<UniValueType>& typesExpected,

View file

@ -28,6 +28,12 @@
*/ */
extern const std::string UNIX_EPOCH_TIME; extern const std::string UNIX_EPOCH_TIME;
/**
* Example bech32 address used in multiple RPCExamples. The address is intentionally
* invalid to prevent accidental transactions by users.
*/
extern const std::string EXAMPLE_ADDRESS;
class FillableSigningProvider; class FillableSigningProvider;
class CPubKey; class CPubKey;
class CScript; class CScript;

View file

@ -3737,8 +3737,6 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
const std::string example_address = "\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\"";
RPCHelpMan{"getaddressinfo", RPCHelpMan{"getaddressinfo",
"\nReturn information about the given bitcoin address.\n" "\nReturn information about the given bitcoin address.\n"
"Some of the information will only be present if the address is in the active wallet.\n", "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)
"}\n" "}\n"
}, },
RPCExamples{ RPCExamples{
HelpExampleCli("getaddressinfo", example_address) + HelpExampleCli("getaddressinfo", EXAMPLE_ADDRESS) +
HelpExampleRpc("getaddressinfo", example_address) HelpExampleRpc("getaddressinfo", EXAMPLE_ADDRESS)
}, },
}.Check(request); }.Check(request);