Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show All 37 Lines | |||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <event2/http.h> | #include <event2/http.h> | ||||
using interfaces::FoundBlock; | using interfaces::FoundBlock; | ||||
static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | ||||
static const std::string HELP_REQUIRING_PASSPHRASE{ | |||||
"\nRequires wallet passphrase to be set with walletpassphrase call if " | |||||
"wallet is encrypted.\n"}; | |||||
static inline bool GetAvoidReuseFlag(const CWallet *const pwallet, | static inline bool GetAvoidReuseFlag(const CWallet *const pwallet, | ||||
const UniValue ¶m) { | const UniValue ¶m) { | ||||
bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | ||||
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | ||||
if (avoid_reuse && !can_avoid_reuse) { | if (avoid_reuse && !can_avoid_reuse) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | ||||
} | } | ||||
std::vector<std::shared_ptr<CWallet>> wallets = GetWallets(); | std::vector<std::shared_ptr<CWallet>> wallets = GetWallets(); | ||||
return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) | return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) | ||||
? wallets[0] | ? wallets[0] | ||||
: nullptr; | : nullptr; | ||||
} | } | ||||
std::string HelpRequiringPassphrase(const CWallet *pwallet) { | |||||
return pwallet && pwallet->IsCrypted() | |||||
? "\nRequires wallet passphrase to be set with walletpassphrase " | |||||
"call." | |||||
: ""; | |||||
} | |||||
bool EnsureWalletIsAvailable(const CWallet *pwallet, bool avoidException) { | bool EnsureWalletIsAvailable(const CWallet *pwallet, bool avoidException) { | ||||
if (pwallet) { | if (pwallet) { | ||||
return true; | return true; | ||||
} | } | ||||
if (avoidException) { | if (avoidException) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!HasWallets()) { | if (!HasWallets()) { | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | static UniValue sendtoaddress(const Config &config, | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"sendtoaddress", | "sendtoaddress", | ||||
"Send an amount to a given address.\n" + | "Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE, | ||||
HelpRequiringPassphrase(pwallet) + "\n", | |||||
{ | { | ||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The bitcoin address to send to."}, | "The bitcoin address to send to."}, | ||||
{"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, | {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, | ||||
"The amount in " + CURRENCY_UNIT + " to send. eg 0.1"}, | "The amount in " + CURRENCY_UNIT + " to send. eg 0.1"}, | ||||
{"comment", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, | {"comment", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, | ||||
"A comment used to store what the transaction is for.\n" | "A comment used to store what the transaction is for.\n" | ||||
" This is not part of the " | " This is not part of the " | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | static UniValue signmessage(const Config &config, | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"signmessage", | "signmessage", | ||||
"Sign a message with the private key of an address" + | "Sign a message with the private key of an address" + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The bitcoin address to use for the private key."}, | "The bitcoin address to use for the private key."}, | ||||
{"message", RPCArg::Type::STR, RPCArg::Optional::NO, | {"message", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The message to create a signature of."}, | "The message to create a signature of."}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::STR, "signature", | RPCResult{RPCResult::Type::STR, "signature", | ||||
"The signature of the message encoded in base 64"}, | "The signature of the message encoded in base 64"}, | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"sendmany", | "sendmany", | ||||
"Send multiple times. Amounts are double-precision " | "Send multiple times. Amounts are double-precision " | ||||
"floating point numbers." + | "floating point numbers." + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"dummy", RPCArg::Type::STR, RPCArg::Optional::NO, | {"dummy", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"Must be set to \"\" for backwards compatibility.", "\"\""}, | "Must be set to \"\" for backwards compatibility.", "\"\""}, | ||||
{ | { | ||||
"amounts", | "amounts", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
RPCArg::Optional::NO, | RPCArg::Optional::NO, | ||||
"The addresses and amounts", | "The addresses and amounts", | ||||
▲ Show 20 Lines • Show All 1,323 Lines • ▼ Show 20 Lines | static UniValue keypoolrefill(const Config &config, | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"keypoolrefill", | "keypoolrefill", | ||||
"Fills the keypool." + HelpRequiringPassphrase(pwallet) + "\n", | "Fills the keypool." + HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"newsize", RPCArg::Type::NUM, /* default */ "100", | {"newsize", RPCArg::Type::NUM, /* default */ "100", | ||||
"The new keypool size"}, | "The new keypool size"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("keypoolrefill", "") + | RPCExamples{HelpExampleCli("keypoolrefill", "") + | ||||
HelpExampleRpc("keypoolrefill", "")}, | HelpExampleRpc("keypoolrefill", "")}, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,703 Lines • ▼ Show 20 Lines | UniValue signrawtransactionwithwallet(const Config &config, | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"signrawtransactionwithwallet", | "signrawtransactionwithwallet", | ||||
"Sign inputs for raw transaction (serialized, hex-encoded).\n" | "Sign inputs for raw transaction (serialized, hex-encoded).\n" | ||||
"The second optional argument (may be null) is an array of previous " | "The second optional argument (may be null) is an array of previous " | ||||
"transaction outputs that\n" | "transaction outputs that\n" | ||||
"this transaction depends on but may not yet be in the block chain.\n" + | "this transaction depends on but may not yet be in the block chain.\n" + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, | {"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The transaction hex string"}, | "The transaction hex string"}, | ||||
{ | { | ||||
"prevtxs", | "prevtxs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
RPCArg::Optional::OMITTED_NAMED_ARG, | RPCArg::Optional::OMITTED_NAMED_ARG, | ||||
"The previous dependent transaction outputs", | "The previous dependent transaction outputs", | ||||
▲ Show 20 Lines • Show All 644 Lines • ▼ Show 20 Lines | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"sethdseed", | "sethdseed", | ||||
"Set or generate a new HD wallet seed. Non-HD wallets will not be " | "Set or generate a new HD wallet seed. Non-HD wallets will not be " | ||||
"upgraded to being a HD wallet. Wallets that are already\n" | "upgraded to being a HD wallet. Wallets that are already\n" | ||||
"HD will have a new HD seed set so that new keys added to the keypool " | "HD will have a new HD seed set so that new keys added to the keypool " | ||||
"will be derived from this new seed.\n" | "will be derived from this new seed.\n" | ||||
"\nNote that you will need to MAKE A NEW BACKUP of your wallet after " | "\nNote that you will need to MAKE A NEW BACKUP of your wallet after " | ||||
"setting the HD wallet seed.\n" + | "setting the HD wallet seed.\n" + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"newkeypool", RPCArg::Type::BOOL, /* default */ "true", | {"newkeypool", RPCArg::Type::BOOL, /* default */ "true", | ||||
"Whether to flush old unused addresses, including change " | "Whether to flush old unused addresses, including change " | ||||
"addresses, from the keypool and regenerate it.\n" | "addresses, from the keypool and regenerate it.\n" | ||||
" If true, the next address from " | " If true, the next address from " | ||||
"getnewaddress and change address from getrawchangeaddress will " | "getnewaddress and change address from getrawchangeaddress will " | ||||
"be from this new seed.\n" | "be from this new seed.\n" | ||||
" If false, addresses (including " | " If false, addresses (including " | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static UniValue walletprocesspsbt(const Config &config, | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"walletprocesspsbt", | "walletprocesspsbt", | ||||
"Update a PSBT with input information from our wallet and then sign " | "Update a PSBT with input information from our wallet and then sign " | ||||
"inputs that we can sign for." + | "inputs that we can sign for." + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, | {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The transaction base64 string"}, | "The transaction base64 string"}, | ||||
{"sign", RPCArg::Type::BOOL, /* default */ "true", | {"sign", RPCArg::Type::BOOL, /* default */ "true", | ||||
"Also sign the transaction when updating"}, | "Also sign the transaction when updating"}, | ||||
{"sighashtype", RPCArg::Type::STR, /* default */ "ALL|FORKID", | {"sighashtype", RPCArg::Type::STR, /* default */ "ALL|FORKID", | ||||
"The signature hash type to sign with if not specified by " | "The signature hash type to sign with if not specified by " | ||||
"the PSBT. Must be one of\n" | "the PSBT. Must be one of\n" | ||||
▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines |