Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 2,501 Lines • ▼ Show 20 Lines | static UniValue walletlock(const Config &config, | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"walletlock", | "walletlock", | ||||
"\nRemoves the wallet encryption key from memory, " | "\nRemoves the wallet encryption key from memory, locking the " | ||||
"locking the wallet.\n" | "wallet.\n" | ||||
"After calling this method, you will need to call " | "After calling this method, you will need to call walletpassphrase " | ||||
"walletpassphrase again\n" | "again\n" | ||||
"before being able to call any methods which require " | "before being able to call any methods which require the wallet to " | ||||
"the wallet to be unlocked.\n", | "be unlocked.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" | RPCExamples{ | ||||
"\nSet the passphrase for 2 minutes to perform a transaction\n" + | "\nSet the passphrase for 2 minutes to perform a " | ||||
"transaction\n" + | |||||
HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + | HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + | ||||
"\nPerform a send (requires passphrase set)\n" + | "\nPerform a send (requires passphrase set)\n" + | ||||
HelpExampleCli("sendtoaddress", | HelpExampleCli("sendtoaddress", | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + | "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + | ||||
"\nClear the passphrase since we are done before 2 minutes is " | "\nClear the passphrase since we are done before 2 minutes is " | ||||
"up\n" + | "up\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("walletlock", "")); | HelpExampleRpc("walletlock", "")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
Show All 15 Lines | static UniValue encryptwallet(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; | ||||
} | } | ||||
if (!pwallet->IsCrypted() && | if (!pwallet->IsCrypted() && | ||||
(request.fHelp || request.params.size() != 1)) { | (request.fHelp || request.params.size() != 1)) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"encryptwallet", | "encryptwallet", | ||||
"\nEncrypts the wallet with 'passphrase'. This is for " | "\nEncrypts the wallet with 'passphrase'. This is for first time " | ||||
"first time encryption.\n" | "encryption.\n" | ||||
"After this, any calls that interact with private keys " | "After this, any calls that interact with private keys such as " | ||||
"such as sending or signing \n" | "sending or signing \n" | ||||
"will require the passphrase to be set prior the making " | "will require the passphrase to be set prior the making these " | ||||
"these calls.\n" | "calls.\n" | ||||
"Use the walletpassphrase call for this, and then " | "Use the walletpassphrase call for this, and then walletlock " | ||||
"walletlock call.\n" | "call.\n" | ||||
"If the wallet is already encrypted, use the " | "If the wallet is already encrypted, use the " | ||||
"walletpassphrasechange call.\n", | "walletpassphrasechange call.\n", | ||||
{ | { | ||||
{"passphrase", RPCArg::Type::STR, /* opt */ false, | {"passphrase", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The pass phrase to encrypt the wallet with. It must be " | "The pass phrase to encrypt the wallet with. It must be " | ||||
"at least 1 character, but should be long."}, | "at least 1 character, but should be long."}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" | RPCExamples{ | ||||
"\nEncrypt your wallet\n" + | "\nEncrypt your wallet\n" + | ||||
HelpExampleCli("encryptwallet", "\"my pass phrase\"") + | HelpExampleCli("encryptwallet", "\"my pass phrase\"") + | ||||
"\nNow set the passphrase to use the wallet, such as for signing " | "\nNow set the passphrase to use the wallet, such as for " | ||||
"or sending bitcoin\n" + | "signing or sending bitcoin\n" + | ||||
HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + | HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + | ||||
"\nNow we can do something like sign\n" + | "\nNow we can do something like sign\n" + | ||||
HelpExampleCli("signmessage", "\"address\" \"test message\"") + | HelpExampleCli("signmessage", "\"address\" \"test message\"") + | ||||
"\nNow lock the wallet again by removing the passphrase\n" + | "\nNow lock the wallet again by removing the passphrase\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("encryptwallet", "\"my pass phrase\"")); | HelpExampleRpc("encryptwallet", "\"my pass phrase\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (request.fHelp) { | if (request.fHelp) { | ||||
return true; | return true; | ||||
} | } | ||||
Show All 32 Lines | static UniValue lockunspent(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; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"lockunspent", | "lockunspent", | ||||
"\nUpdates list of temporarily unspendable outputs.\n" | "\nUpdates list of temporarily unspendable outputs.\n" | ||||
"Temporarily lock (unlock=false) or unlock (unlock=true) " | "Temporarily lock (unlock=false) or unlock (unlock=true) specified " | ||||
"specified transaction outputs.\n" | "transaction outputs.\n" | ||||
"If no transaction outputs are specified when unlocking then " | "If no transaction outputs are specified when unlocking then all " | ||||
"all current locked transaction outputs are unlocked.\n" | "current locked transaction outputs are unlocked.\n" | ||||
"A locked transaction output will not be chosen by automatic " | "A locked transaction output will not be chosen by automatic coin " | ||||
"coin selection, when spending bitcoins.\n" | "selection, when spending bitcoins.\n" | ||||
"Locks are stored in memory only. Nodes start with zero locked " | "Locks are stored in memory only. Nodes start with zero locked " | ||||
"outputs, and the locked output list\n" | "outputs, and the locked output list\n" | ||||
"is always cleared (by virtue of process exit) when a node " | "is always cleared (by virtue of process exit) when a node stops " | ||||
"stops or fails.\n" | "or fails.\n" | ||||
"Also see the listunspent call\n", | "Also see the listunspent call\n", | ||||
{ | { | ||||
{"unlock", RPCArg::Type::BOOL, /* opt */ false, | {"unlock", RPCArg::Type::BOOL, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Whether to unlock (true) or lock (false) the specified " | "Whether to unlock (true) or lock (false) the specified " | ||||
"transactions"}, | "transactions"}, | ||||
{ | { | ||||
"transactions", | "transactions", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of objects. Each object the txid " | "A json array of objects. Each object the txid " | ||||
"(string) vout (numeric)", | "(string) vout (numeric)", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, | {"txid", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"The transaction id"}, | "The transaction id"}, | ||||
{"vout", RPCArg::Type::NUM, /* opt */ false, | {"vout", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "The output number"}, | /* default_val */ "", "The output number"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"true|false (boolean) Whether the command was " | ||||
"\nResult:\n" | "successful or not\n"}, | ||||
"true|false (boolean) Whether the command was successful or " | RPCExamples{"\nList the unspent transactions\n" + | ||||
"not\n" | |||||
"\nExamples:\n" | |||||
"\nList the unspent transactions\n" + | |||||
HelpExampleCli("listunspent", "") + | HelpExampleCli("listunspent", "") + | ||||
"\nLock an unspent transaction\n" + | "\nLock an unspent transaction\n" + | ||||
HelpExampleCli("lockunspent", "false " | HelpExampleCli("lockunspent", | ||||
"false " | |||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nList the locked transactions\n" + | "\nList the locked transactions\n" + | ||||
HelpExampleCli("listlockunspent", "") + | HelpExampleCli("listlockunspent", "") + | ||||
"\nUnlock the transaction again\n" + | "\nUnlock the transaction again\n" + | ||||
HelpExampleCli("lockunspent", "true " | HelpExampleCli("lockunspent", | ||||
"true " | |||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("lockunspent", "false, " | HelpExampleRpc("lockunspent", | ||||
"false, " | |||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"")); | ",\\\"vout\\\":1}]\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static UniValue listlockunspent(const Config &config, | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"listlockunspent", | "listlockunspent", | ||||
"\nReturns list of temporarily unspendable outputs.\n" | "\nReturns list of temporarily unspendable outputs.\n" | ||||
"See the lockunspent call to lock and unlock " | "See the lockunspent call to lock and unlock transactions for " | ||||
"transactions for spending.\n", | "spending.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"[\n" | ||||
"\nResult:\n" | |||||
"[\n" | |||||
" {\n" | " {\n" | ||||
" \"txid\" : \"transactionid\", (string) The transaction id " | " \"txid\" : \"transactionid\", (string) The " | ||||
"locked\n" | "transaction id locked\n" | ||||
" \"vout\" : n (numeric) The vout value\n" | " \"vout\" : n (numeric) The " | ||||
"vout value\n" | |||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nExamples:\n" | RPCExamples{"\nList the unspent transactions\n" + | ||||
"\nList the unspent transactions\n" + | |||||
HelpExampleCli("listunspent", "") + | HelpExampleCli("listunspent", "") + | ||||
"\nLock an unspent transaction\n" + | "\nLock an unspent transaction\n" + | ||||
HelpExampleCli("lockunspent", "false " | HelpExampleCli("lockunspent", | ||||
"false " | |||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nList the locked transactions\n" + | "\nList the locked transactions\n" + | ||||
HelpExampleCli("listlockunspent", "") + | HelpExampleCli("listlockunspent", "") + | ||||
"\nUnlock the transaction again\n" + | "\nUnlock the transaction again\n" + | ||||
HelpExampleCli("lockunspent", "true " | HelpExampleCli("lockunspent", | ||||
"true " | |||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nAs a JSON-RPC call\n" + HelpExampleRpc("listlockunspent", "")); | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("listlockunspent", "")}, | |||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::vector<COutPoint> vOutpts; | std::vector<COutPoint> vOutpts; | ||||
pwallet->ListLockedCoins(vOutpts); | pwallet->ListLockedCoins(vOutpts); | ||||
Show All 15 Lines | static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 1) { | request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"settxfee", | "settxfee", | ||||
"\nSet the transaction fee per kB for this wallet. Overrides " | "\nSet the transaction fee per kB for this wallet. Overrides the " | ||||
"the global -paytxfee command line parameter.\n", | "global -paytxfee command line parameter.\n", | ||||
{ | { | ||||
{"amount", RPCArg::Type::AMOUNT, /* opt */ false, | {"amount", RPCArg::Type::AMOUNT, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The transaction fee in " + CURRENCY_UNIT + "/kB"}, | "The transaction fee in " + CURRENCY_UNIT + "/kB"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult\n" | "true|false (boolean) Returns true if successful\n"}, | ||||
"true|false (boolean) Returns true if successful\n" | RPCExamples{HelpExampleCli("settxfee", "0.00001") + | ||||
"\nExamples:\n" + | HelpExampleRpc("settxfee", "0.00001")}, | ||||
HelpExampleCli("settxfee", "0.00001") + | } | ||||
HelpExampleRpc("settxfee", "0.00001")); | .ToStringWithResultsAndExamples()); | ||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
Amount nAmount = AmountFromValue(request.params[0]); | Amount nAmount = AmountFromValue(request.params[0]); | ||||
CFeeRate tx_fee_rate(nAmount, 1000); | CFeeRate tx_fee_rate(nAmount, 1000); | ||||
if (tx_fee_rate == CFeeRate()) { | if (tx_fee_rate == CFeeRate()) { | ||||
Show All 19 Lines | static UniValue getwalletinfo(const Config &config, | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getwalletinfo", | "getwalletinfo", | ||||
"Returns an object containing various wallet state info.\n", | "Returns an object containing various wallet state info.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"walletname\": xxxxx, (string) the wallet name\n" | " \"walletname\": xxxxx, (string) the wallet " | ||||
"name\n" | |||||
" \"walletversion\": xxxxx, (numeric) the wallet " | " \"walletversion\": xxxxx, (numeric) the wallet " | ||||
"version\n" | "version\n" | ||||
" \"balance\": xxxxxxx, (numeric) the total " | " \"balance\": xxxxxxx, (numeric) the total " | ||||
"confirmed balance of the wallet in " + | "confirmed balance of the wallet in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"unconfirmed_balance\": xxx, (numeric) " | " \"unconfirmed_balance\": xxx, (numeric) the total " | ||||
"the total unconfirmed balance of the wallet in " + | "unconfirmed balance of the wallet in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"immature_balance\": xxxxxx, (numeric) " | " \"immature_balance\": xxxxxx, (numeric) the total " | ||||
"the total immature balance of the wallet in " + | "immature balance of the wallet in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"txcount\": xxxxxxx, (numeric) the total number " | " \"txcount\": xxxxxxx, (numeric) the total " | ||||
"of transactions in the wallet\n" | "number of transactions in the wallet\n" | ||||
" \"keypoololdest\": xxxxxx, (numeric) the timestamp " | " \"keypoololdest\": xxxxxx, (numeric) the timestamp " | ||||
"(seconds since Unix epoch) of the oldest pre-generated key in the " | "(seconds since Unix epoch) of the oldest pre-generated key in " | ||||
"key pool\n" | "the key pool\n" | ||||
" \"keypoolsize\": xxxx, (numeric) how many new keys " | " \"keypoolsize\": xxxx, (numeric) how many new " | ||||
"are pre-generated (only counts external keys)\n" | "keys are pre-generated (only counts external keys)\n" | ||||
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys " | " \"keypoolsize_hd_internal\": xxxx, (numeric) how many new " | ||||
"are pre-generated for internal use (used for change outputs, only " | "keys are pre-generated for internal use (used for change " | ||||
"appears if the wallet is using this feature, otherwise external " | "outputs, only appears if the wallet is using this feature, " | ||||
"keys are used)\n" | "otherwise external keys are used)\n" | ||||
" \"unlocked_until\": ttt, (numeric) the timestamp in " | " \"unlocked_until\": ttt, (numeric) the timestamp " | ||||
"seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is " | "in seconds since epoch (midnight Jan 1 1970 GMT) that the " | ||||
"unlocked for transfers, or 0 if the wallet is locked\n" | "wallet is unlocked for transfers, or 0 if the wallet is " | ||||
" \"paytxfee\": x.xxxx, (numeric) the transaction " | "locked\n" | ||||
"fee configuration, set in " + | " \"paytxfee\": x.xxxx, (numeric) the " | ||||
"transaction fee configuration, set in " + | |||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"/kB\n" | "/kB\n" | ||||
" \"hdseedid\": \"<hash160>\" (string, optional) the " | " \"hdseedid\": \"<hash160>\" (string, optional) the " | ||||
"Hash160 of the HD seed (only present when HD is enabled)\n" | "Hash160 of the HD seed (only present when HD is enabled)\n" | ||||
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias " | " \"hdmasterkeyid\": \"<hash160>\" (string, optional) " | ||||
"for hdseedid retained for backwards-compatibility. Will be " | "alias for hdseedid retained for backwards-compatibility. Will " | ||||
"removed in V0.21.\n" | "be removed in V0.21.\n" | ||||
" \"private_keys_enabled\": true|false (boolean) false if " | " \"private_keys_enabled\": true|false (boolean) false if " | ||||
"privatekeys are disabled for this wallet (enforced watch-only " | "privatekeys are disabled for this wallet (enforced watch-only " | ||||
"wallet)\n" | "wallet)\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getwalletinfo", "") + | ||||
HelpExampleCli("getwalletinfo", "") + | HelpExampleRpc("getwalletinfo", "")}, | ||||
HelpExampleRpc("getwalletinfo", "")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
Show All 27 Lines | static UniValue getwalletinfo(const Config &config, | ||||
obj.pushKV("private_keys_enabled", | obj.pushKV("private_keys_enabled", | ||||
!pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue listwalletdir(const Config &config, | static UniValue listwalletdir(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"listwalletdir", | "listwalletdir", | ||||
"Returns a list of wallets in the wallet directory.\n", | "Returns a list of wallets in the wallet directory.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"{\n" | "{\n" | ||||
" \"wallets\" : [ (json array of objects)\n" | " \"wallets\" : [ (json array of objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"name\" : \"name\" (string) The wallet name\n" | " \"name\" : \"name\" (string) The wallet name\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("listwalletdir", "") + | ||||
HelpExampleCli("listwalletdir", "") + | HelpExampleRpc("listwalletdir", "")}, | ||||
HelpExampleRpc("listwalletdir", "")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
UniValue wallets(UniValue::VARR); | UniValue wallets(UniValue::VARR); | ||||
for (const auto &path : ListWalletDir()) { | for (const auto &path : ListWalletDir()) { | ||||
UniValue wallet(UniValue::VOBJ); | UniValue wallet(UniValue::VOBJ); | ||||
wallet.pushKV("name", path.string()); | wallet.pushKV("name", path.string()); | ||||
wallets.push_back(wallet); | wallets.push_back(wallet); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("wallets", wallets); | result.pushKV("wallets", wallets); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue listwallets(const Config &config, | static UniValue listwallets(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"listwallets", | "listwallets", | ||||
"Returns a list of currently loaded wallets.\n" | "Returns a list of currently loaded wallets.\n" | ||||
"For full information on the wallet, use \"getwalletinfo\"\n", | "For full information on the wallet, use \"getwalletinfo\"\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"[ (json array of strings)\n" | ||||
"\nResult:\n" | |||||
"[ (json array of strings)\n" | |||||
" \"walletname\" (string) the wallet name\n" | " \"walletname\" (string) the wallet name\n" | ||||
" ...\n" | " ...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("listwallets", "") + | ||||
HelpExampleCli("listwallets", "") + | HelpExampleRpc("listwallets", "")}, | ||||
HelpExampleRpc("listwallets", "")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
UniValue obj(UniValue::VARR); | UniValue obj(UniValue::VARR); | ||||
for (const std::shared_ptr<CWallet> &wallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &wallet : GetWallets()) { | ||||
if (!EnsureWalletIsAvailable(wallet.get(), request.fHelp)) { | if (!EnsureWalletIsAvailable(wallet.get(), request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
obj.push_back(wallet->GetName()); | obj.push_back(wallet->GetName()); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue loadwallet(const Config &config, | static UniValue loadwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"loadwallet", | "loadwallet", | ||||
"\nLoads a wallet from a wallet file or directory." | "\nLoads a wallet from a wallet file or directory." | ||||
"\nNote that all wallet command-line options used when " | "\nNote that all wallet command-line options used when starting " | ||||
"starting bitcoind will be" | "bitcoind will be" | ||||
"\napplied to the new wallet (eg -zapwallettxes, " | "\napplied to the new wallet (eg -zapwallettxes, upgradewallet, " | ||||
"upgradewallet, rescan, etc).\n", | "rescan, etc).\n", | ||||
{ | { | ||||
{"filename", RPCArg::Type::STR, /* opt */ false, | {"filename", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The wallet directory or .dat file."}, | ||||
"The wallet directory or .dat file."}, | }, | ||||
}} | RPCResult{"{\n" | ||||
.ToString() + | " \"name\" : <wallet_name>, (string) The " | ||||
"\nResult:\n" | "wallet name if loaded successfully.\n" | ||||
"{\n" | " \"warning\" : <warning>, (string) Warning " | ||||
" \"name\" : <wallet_name>, (string) The wallet name if " | "message if wallet was not loaded cleanly.\n" | ||||
"loaded successfully.\n" | "}\n"}, | ||||
" \"warning\" : <warning>, (string) Warning message if " | RPCExamples{HelpExampleCli("loadwallet", "\"test.dat\"") + | ||||
"wallet was not loaded cleanly.\n" | HelpExampleRpc("loadwallet", "\"test.dat\"")}, | ||||
"}\n" | } | ||||
"\nExamples:\n" + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleCli("loadwallet", "\"test.dat\"") + | |||||
HelpExampleRpc("loadwallet", "\"test.dat\"")); | |||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
WalletLocation location(request.params[0].get_str()); | WalletLocation location(request.params[0].get_str()); | ||||
std::string error; | std::string error; | ||||
if (!location.Exists()) { | if (!location.Exists()) { | ||||
Show All 32 Lines | static UniValue loadwallet(const Config &config, | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue createwallet(const Config &config, | static UniValue createwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"createwallet", | "createwallet", | ||||
"\nCreates and loads a new wallet.\n", | "\nCreates and loads a new wallet.\n", | ||||
{ | { | ||||
{"wallet_name", RPCArg::Type::STR, /* opt */ false, | {"wallet_name", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The name for the new wallet. If this is a path, " | "The name for the new wallet. If this is a path, " | ||||
"the wallet will be created at the path location."}, | "the wallet will be created at the path location."}, | ||||
{"disable_private_keys", RPCArg::Type::BOOL, | {"disable_private_keys", RPCArg::Type::BOOL, | ||||
/* opt */ true, /* default_val */ "false", | /* opt */ true, /* default_val */ "false", | ||||
"Disable the possibility of private keys (only " | "Disable the possibility of private keys (only " | ||||
"watchonlys are possible in this mode)."}, | "watchonlys are possible in this mode)."}, | ||||
{"blank", RPCArg::Type::BOOL, /* opt */ true, | {"blank", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"Create a blank wallet. A blank wallet has no keys " | "Create a blank wallet. A blank wallet has no keys " | ||||
"or HD seed. One can be set using sethdseed.\n"}, | "or HD seed. One can be set using sethdseed.\n"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"name\" : <wallet_name>, (string) The wallet name if " | " \"name\" : <wallet_name>, (string) The wallet " | ||||
"created successfully. If the wallet was created using a full " | "name if created successfully. If the wallet was created using " | ||||
"path, the wallet_name will be the full path.\n" | "a full path, the wallet_name will be the full path.\n" | ||||
" \"warning\" : <warning>, (string) Warning message if " | " \"warning\" : <warning>, (string) Warning " | ||||
"wallet was not loaded cleanly.\n" | "message if wallet was not loaded cleanly.\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("createwallet", "\"testwallet\"") + | ||||
HelpExampleCli("createwallet", "\"testwallet\"") + | HelpExampleRpc("createwallet", "\"testwallet\"")}, | ||||
HelpExampleRpc("createwallet", "\"testwallet\"")); | } | ||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
std::string error; | std::string error; | ||||
std::string warning; | std::string warning; | ||||
uint64_t flags = 0; | uint64_t flags = 0; | ||||
Show All 33 Lines | static UniValue createwallet(const Config &config, | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue unloadwallet(const Config &config, | static UniValue unloadwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"unloadwallet", | "unloadwallet", | ||||
"Unloads the wallet referenced by the request endpoint " | "Unloads the wallet referenced by the request endpoint " | ||||
"otherwise unloads the wallet specified in the argument.\n" | "otherwise unloads the wallet specified in the argument.\n" | ||||
"Specifying the wallet name on a wallet endpoint is invalid.", | "Specifying the wallet name on a wallet endpoint is invalid.", | ||||
{ | { | ||||
{"wallet_name", RPCArg::Type::STR, /* opt */ true, | {"wallet_name", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", "The name of the wallet to unload."}, | /* default_val */ "", "The name of the wallet to unload."}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + HelpExampleCli("unloadwallet", "wallet_name") + | RPCExamples{HelpExampleCli("unloadwallet", "wallet_name") + | ||||
HelpExampleRpc("unloadwallet", "wallet_name")); | HelpExampleRpc("unloadwallet", "wallet_name")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
std::string wallet_name; | std::string wallet_name; | ||||
if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) { | if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) { | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Cannot unload the requested wallet"); | "Cannot unload the requested wallet"); | ||||
} | } | ||||
Show All 24 Lines | static UniValue resendwallettransactions(const Config &config, | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"resendwallettransactions", | "resendwallettransactions", | ||||
"Immediately re-broadcast unconfirmed wallet " | "Immediately re-broadcast unconfirmed wallet transactions to all " | ||||
"transactions to all peers.\n" | "peers.\n" | ||||
"Intended only for testing; the wallet code " | "Intended only for testing; the wallet code periodically " | ||||
"periodically re-broadcasts\n", | "re-broadcasts\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"automatically.\n" | |||||
"Returns an RPC error if -walletbroadcast is set to false.\n" | "Returns an RPC error if -walletbroadcast is set to false.\n" | ||||
"Returns array of transaction ids that were re-broadcast.\n"); | "Returns array of transaction ids that were re-broadcast.\n"}, | ||||
RPCExamples{""}, | |||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
if (!pwallet->chain().p2pEnabled()) { | if (!pwallet->chain().p2pEnabled()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,610 Lines • Show Last 20 Lines |