Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | static UniValue getnewaddress(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() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getnewaddress", | "getnewaddress", | ||||
"\nReturns a new Bitcoin address for receiving payments.\n" | "\nReturns a new Bitcoin address for receiving payments.\n" | ||||
"If 'label' is specified, it is added to the address book \n" | "If 'label' is specified, it is added to the address book \n" | ||||
"so payments received with the address will be associated with " | "so payments received with the address will be associated with " | ||||
"'label'.\n", | "'label'.\n", | ||||
{ | { | ||||
{"label", RPCArg::Type::STR, /* opt */ true, | {"label", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The label name for the address to be linked to. If not " | "The label name for the address to be linked to. If not " | ||||
"provided, the default label \"\" is used. It can also be " | "provided, the default label \"\" is used. It can also be " | ||||
"set to the empty string \"\" to represent the default " | "set to the empty string \"\" to represent the default " | ||||
"label. The label does not need to exist, it will be " | "label. The label does not need to exist, it will be " | ||||
"created if there is no label by the given name."}, | "created if there is no label by the given name."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"address\" (string) The new bitcoin address\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getnewaddress", "") + | ||||
"\"address\" (string) The new bitcoin address\n" | HelpExampleRpc("getnewaddress", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleRpc("getnewaddress", "")); | .ToStringWithResultsAndExamples()); | ||||
} | } | ||||
// Belt and suspenders check for disabled private keys | // Belt and suspenders check for disabled private keys | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: Private keys are disabled for this wallet"); | "Error: Private keys are disabled for this wallet"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | static UniValue getrawchangeaddress(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() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getrawchangeaddress", | "getrawchangeaddress", | ||||
"\nReturns a new Bitcoin address, for receiving change.\n" | "\nReturns a new Bitcoin address, for receiving change.\n" | ||||
"This is for use with raw transactions, NOT normal use.\n", | "This is for use with raw transactions, NOT normal use.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"\"address\" (string) The address\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getrawchangeaddress", "") + | ||||
"\"address\" (string) The address\n" | HelpExampleRpc("getrawchangeaddress", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getrawchangeaddress", "") + | .ToStringWithResultsAndExamples()); | ||||
HelpExampleRpc("getrawchangeaddress", "")); | |||||
} | } | ||||
// Belt and suspenders check for disabled private keys | // Belt and suspenders check for disabled private keys | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: Private keys are disabled for this wallet"); | "Error: Private keys are disabled for this wallet"); | ||||
} | } | ||||
Show All 40 Lines | static UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | ||||
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() != 2) { | if (request.fHelp || request.params.size() != 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"setlabel", | "setlabel", | ||||
"\nSets the label associated with the given address.\n", | "\nSets the label associated with the given address.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The bitcoin address to be associated with a label."}, | "The bitcoin address to be associated with a label."}, | ||||
{"label", RPCArg::Type::STR, /* opt */ false, | {"label", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The label to assign to the address."}, | ||||
"The label to assign to the address."}, | }, | ||||
}} | RPCResults{}, | ||||
.ToString() + | RPCExamples{ | ||||
"\nExamples:\n" + | HelpExampleCli( | ||||
HelpExampleCli("setlabel", | "setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"setlabel", | "setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
▲ Show 20 Lines • Show All 74 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; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"sendtoaddress", | "sendtoaddress", | ||||
"\nSend an amount to a given address.\n" + | "\nSend an amount to a given address.\n" + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HelpRequiringPassphrase(pwallet) + "\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The bitcoin address to send to."}, | /* default_val */ "", "The bitcoin address to send to."}, | ||||
{"amount", RPCArg::Type::AMOUNT, /* opt */ false, | {"amount", RPCArg::Type::AMOUNT, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The amount in " + CURRENCY_UNIT + " to send. eg 0.1"}, | "The amount in " + CURRENCY_UNIT + " to send. eg 0.1"}, | ||||
{"comment", RPCArg::Type::STR, /* opt */ true, | {"comment", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"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 " | ||||
"transaction, just kept in your wallet."}, | "transaction, just kept in your wallet."}, | ||||
{"comment_to", RPCArg::Type::STR, /* opt */ true, | {"comment_to", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A comment to store the name of the person or " | "A comment to store the name of the person or " | ||||
"organization\n" | "organization\n" | ||||
" to which you're sending the " | " to which you're sending the " | ||||
"transaction. This is not part of the \n" | "transaction. This is not part of the \n" | ||||
" transaction, just kept in " | " transaction, just kept in " | ||||
"your wallet."}, | "your wallet."}, | ||||
{"subtractfeefromamount", RPCArg::Type::BOOL, | {"subtractfeefromamount", RPCArg::Type::BOOL, | ||||
/* opt */ true, /* default_val */ "false", | /* opt */ true, /* default_val */ "false", | ||||
"The fee will be deducted from the amount being sent.\n" | "The fee will be deducted from the amount being sent.\n" | ||||
" The recipient will receive " | " The recipient will receive " | ||||
"less bitcoins than you enter in the amount field."}, | "less bitcoins than you enter in the amount field."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | "\"txid\" (string) The transaction id.\n"}, | ||||
"\"txid\" (string) The transaction id.\n" | RPCExamples{ | ||||
"\nExamples:\n" + | |||||
HelpExampleCli("sendtoaddress", | HelpExampleCli("sendtoaddress", | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + | "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + | ||||
HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | HelpExampleCli("sendtoaddress", | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | |||||
"dd\" 0.1 \"donation\" \"seans " | "dd\" 0.1 \"donation\" \"seans " | ||||
"outpost\"") + | "outpost\"") + | ||||
HelpExampleCli( | HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44" | ||||
"sendtoaddress", | "Jvaydd\" 0.1 \"\" \"\" true") + | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true") + | HelpExampleRpc("sendtoaddress", | ||||
HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | ||||
"dd\", 0.1, \"donation\", \"seans " | "dd\", 0.1, \"donation\", \"seans " | ||||
"outpost\"")); | "outpost\"")}, | ||||
} | |||||
.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 36 Lines | static UniValue listaddressgroupings(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{"listaddressgroupings", | "listaddressgroupings", | ||||
"\nLists groups of addresses which have had their " | "\nLists groups of addresses which have had their " | ||||
"common ownership\n" | "common ownership\n" | ||||
"made public by common use as inputs or as the " | "made public by common use as inputs or as the " | ||||
"resulting change\n" | "resulting change\n" | ||||
"in past transactions\n", | "in past transactions\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"[\n" | "[\n" | ||||
" [\n" | " [\n" | ||||
" [\n" | " [\n" | ||||
" \"address\", (string) The bitcoin address\n" | " \"address\", (string) The bitcoin address\n" | ||||
" amount, (numeric) The amount in " + | " amount, (numeric) The amount in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"label\" (string, optional) The label\n" | " \"label\" (string, optional) The label\n" | ||||
" ]\n" | " ]\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("listaddressgroupings", "") + | ||||
HelpExampleCli("listaddressgroupings", "") + | HelpExampleRpc("listaddressgroupings", "")}, | ||||
HelpExampleRpc("listaddressgroupings", "")); | } | ||||
.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 signmessage(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() != 2) { | if (request.fHelp || request.params.size() != 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"signmessage", | "signmessage", | ||||
"\nSign a message with the private key of an address" + | "\nSign a message with the private key of an address" + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HelpRequiringPassphrase(pwallet) + "\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The bitcoin address to use for the private key."}, | "The bitcoin address to use for the private key."}, | ||||
{"message", RPCArg::Type::STR, /* opt */ false, | {"message", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The message to create a signature of."}, | ||||
"The message to create a signature of."}, | }, | ||||
}} | RPCResult{ | ||||
.ToString() + | |||||
"\nResult:\n" | |||||
"\"signature\" (string) The signature of the message " | "\"signature\" (string) The signature of the message " | ||||
"encoded in base 64\n" | "encoded in base 64\n"}, | ||||
"\nExamples:\n" | RPCExamples{ | ||||
"\nUnlock the wallet for 30 seconds\n" + | "\nUnlock the wallet for 30 seconds\n" + | ||||
HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + | HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + | ||||
"\nCreate the signature\n" + | "\nCreate the signature\n" + | ||||
HelpExampleCli( | HelpExampleCli( | ||||
"signmessage", | "signmessage", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + | ||||
"\nVerify the signature\n" + | "\nVerify the signature\n" + | ||||
HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" | HelpExampleCli("verifymessage", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4" | |||||
"XX\" \"signature\" \"my " | "XX\" \"signature\" \"my " | ||||
"message\"") + | "message\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"signmessage", | "signmessage", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
Show All 33 Lines | static UniValue getreceivedbyaddress(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{ | |||||
"getreceivedbyaddress", | "getreceivedbyaddress", | ||||
"\nReturns the total amount received by the given address in " | "\nReturns the total amount received by the given address in " | ||||
"transactions with at least minconf confirmations.\n", | "transactions with at least minconf confirmations.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The bitcoin address for transactions."}, | ||||
"The bitcoin address for transactions."}, | |||||
{"minconf", RPCArg::Type::NUM, /* opt */ true, | {"minconf", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1", | /* default_val */ "1", | ||||
"Only include transactions confirmed at least this many " | "Only include transactions confirmed at least this many " | ||||
"times."}, | "times."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"amount (numeric) The total amount in " + | ||||
"\nResult:\n" | CURRENCY_UNIT + " received at this address.\n"}, | ||||
"amount (numeric) The total amount in " + | RPCExamples{ | ||||
CURRENCY_UNIT + | "\nThe amount from transactions with at least 1 " | ||||
" received at this address.\n" | "confirmation\n" + | ||||
"\nExamples:\n" | |||||
"\nThe amount from transactions with at least 1 confirmation\n" + | |||||
HelpExampleCli("getreceivedbyaddress", | HelpExampleCli("getreceivedbyaddress", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | ||||
"\nThe amount including unconfirmed transactions, zero " | "\nThe amount including unconfirmed transactions, zero " | ||||
"confirmations\n" + | "confirmations\n" + | ||||
HelpExampleCli("getreceivedbyaddress", | HelpExampleCli("getreceivedbyaddress", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 0") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 0") + | ||||
"\nThe amount with at least 6 confirmations\n" + | "\nThe amount with at least 6 confirmations\n" + | ||||
HelpExampleCli("getreceivedbyaddress", | HelpExampleCli("getreceivedbyaddress", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 6") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 6") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("getreceivedbyaddress", | HelpExampleRpc("getreceivedbyaddress", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")}, | ||||
} | |||||
.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 46 Lines • ▼ Show 20 Lines | static UniValue getreceivedbylabel(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{ | |||||
"getreceivedbylabel", | "getreceivedbylabel", | ||||
"\nReturns the total amount received by addresses with <label> " | "\nReturns the total amount received by addresses with <label> " | ||||
"in transactions with at least [minconf] confirmations.\n", | "in transactions with at least [minconf] confirmations.\n", | ||||
{ | { | ||||
{"label", RPCArg::Type::STR, /* opt */ false, | {"label", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The selected label, may be the default label " | "The selected label, may be the default label " | ||||
"using \"\"."}, | "using \"\"."}, | ||||
{"minconf", RPCArg::Type::NUM, /* opt */ true, | {"minconf", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1", | /* default_val */ "1", | ||||
"Only include transactions confirmed at least this " | "Only include transactions confirmed at least this " | ||||
"many times."}, | "many times."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"amount (numeric) The total amount in " + | ||||
"\nResult:\n" | CURRENCY_UNIT + " received for this label.\n"}, | ||||
"amount (numeric) The total amount in " + | RPCExamples{ | ||||
CURRENCY_UNIT + | |||||
" received for this label.\n" | |||||
"\nExamples:\n" | |||||
"\nAmount received by the default label with at least 1 " | "\nAmount received by the default label with at least 1 " | ||||
"confirmation\n" + | "confirmation\n" + | ||||
HelpExampleCli("getreceivedbylabel", "\"\"") + | HelpExampleCli("getreceivedbylabel", "\"\"") + | ||||
"\nAmount received at the tabby label including unconfirmed " | "\nAmount received at the tabby label including unconfirmed " | ||||
"amounts with zero confirmations\n" + | "amounts with zero confirmations\n" + | ||||
HelpExampleCli("getreceivedbylabel", "\"tabby\" 0") + | HelpExampleCli("getreceivedbylabel", "\"tabby\" 0") + | ||||
"\nThe amount with at least 6 confirmations\n" + | "\nThe amount with at least 6 confirmations\n" + | ||||
HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") + | HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")); | HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")}, | ||||
} | |||||
.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 38 Lines | static UniValue getbalance(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() > 3)) { | if (request.fHelp || (request.params.size() > 3)) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getbalance", | "getbalance", | ||||
"\nReturns the total available balance.\n" | "\nReturns the total available balance.\n" | ||||
"The available balance is what the wallet considers " | "The available balance is what the wallet considers " | ||||
"currently spendable, and is\n" | "currently spendable, and is\n" | ||||
"thus affected by options which limit spendability such " | "thus affected by options which limit spendability such " | ||||
"as -spendzeroconfchange.\n", | "as -spendzeroconfchange.\n", | ||||
{ | { | ||||
{"dummy", RPCArg::Type::STR, /* opt */ true, | {"dummy", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Remains for backward compatibility. Must be " | "Remains for backward compatibility. Must be " | ||||
"excluded or set to \"*\"."}, | "excluded or set to \"*\"."}, | ||||
{"minconf", RPCArg::Type::NUM, /* opt */ true, | {"minconf", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Only include transactions confirmed at least this " | "Only include transactions confirmed at least this " | ||||
"many times."}, | "many times."}, | ||||
{"include_watchonly", RPCArg::Type::BOOL, | {"include_watchonly", RPCArg::Type::BOOL, | ||||
/* opt */ true, /* default_val */ "false", | /* opt */ true, /* default_val */ "false", | ||||
"Also include balance in watch-only addresses (see " | "Also include balance in watch-only addresses (see " | ||||
"'importaddress')"}, | "'importaddress')"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"amount (numeric) The total amount in " + | ||||
"\nResult:\n" | CURRENCY_UNIT + " received for this wallet.\n"}, | ||||
"amount (numeric) The total amount in " + | RPCExamples{"\nThe total amount in the wallet with 1 or more " | ||||
CURRENCY_UNIT + | "confirmations\n" + | ||||
" received for this wallet.\n" | |||||
"\nExamples:\n" | |||||
"\nThe total amount in the wallet with 1 or more confirmations\n" + | |||||
HelpExampleCli("getbalance", "") + | HelpExampleCli("getbalance", "") + | ||||
"\nThe total amount in the wallet at least 6 blocks confirmed\n" + | "\nThe total amount in the wallet at least 6 blocks " | ||||
HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a JSON-RPC call\n" + | "confirmed\n" + | ||||
HelpExampleRpc("getbalance", "\"*\", 6")); | HelpExampleCli("getbalance", "\"*\" 6") + | ||||
"\nAs a JSON-RPC call\n" + | |||||
HelpExampleRpc("getbalance", "\"*\", 6")}, | |||||
} | |||||
.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 26 Lines | static UniValue getunconfirmedbalance(const Config &config, | ||||
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(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"getunconfirmedbalance", | "getunconfirmedbalance", | ||||
"Returns the server's total unconfirmed balance\n", | "Returns the server's total unconfirmed balance\n", | ||||
{}}.ToString()); | {}, | ||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.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); | ||||
return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | ||||
} | } | ||||
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
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() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"sendmany", | "sendmany", | ||||
"\nSend multiple times. Amounts are double-precision " | "\nSend multiple times. Amounts are double-precision " | ||||
"floating point numbers." + | "floating point numbers." + | ||||
HelpRequiringPassphrase(pwallet) + "\n", | HelpRequiringPassphrase(pwallet) + "\n", | ||||
{ | { | ||||
{"dummy", RPCArg::Type::STR, /* opt */ false, | {"dummy", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Must be set to \"\" for backwards compatibility.", | "Must be set to \"\" for backwards compatibility.", "\"\""}, | ||||
"\"\""}, | |||||
{ | { | ||||
"amounts", | "amounts", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json object with addresses and amounts", | "A json object with addresses and amounts", | ||||
{ | { | ||||
{"address", RPCArg::Type::AMOUNT, /* opt */ false, | {"address", RPCArg::Type::AMOUNT, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The bitcoin address is the key, the numeric " | "The bitcoin address is the key, the numeric " | ||||
"amount (can be string) in " + | "amount (can be string) in " + | ||||
CURRENCY_UNIT + " is the value"}, | CURRENCY_UNIT + " is the value"}, | ||||
}, | }, | ||||
}, | }, | ||||
{"minconf", RPCArg::Type::NUM, /* opt */ true, | {"minconf", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1", | /* default_val */ "1", | ||||
"Only use the balance confirmed at least this many " | "Only use the balance confirmed at least this many " | ||||
"times."}, | "times."}, | ||||
{"comment", RPCArg::Type::STR, /* opt */ true, | {"comment", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", "A comment"}, | /* default_val */ "", "A comment"}, | ||||
{ | { | ||||
"subtractfeefrom", | "subtractfeefrom", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array with addresses.\n" | "A json array with addresses.\n" | ||||
" The fee will be equally " | " The fee will be equally " | ||||
"deducted from the amount of each selected address.\n" | "deducted from the amount of each selected address.\n" | ||||
" Those recipients will " | " Those recipients will " | ||||
"receive less bitcoins than you enter in their " | "receive less bitcoins than you enter in their " | ||||
"corresponding amount field.\n" | "corresponding amount field.\n" | ||||
" If no addresses are " | " If no addresses are " | ||||
"specified here, the sender pays the fee.", | "specified here, the sender pays the fee.", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, /* opt */ true, | {"address", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"Subtract fee from this address"}, | "Subtract fee from this address"}, | ||||
}, | }, | ||||
}, | }, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | "\"txid\" (string) The transaction id for " | ||||
"\"txid\" (string) The transaction id for the " | "the send. Only 1 transaction is created regardless of \n" | ||||
"send. Only 1 transaction is created regardless of \n" | " the number of " | ||||
" the number of addresses.\n" | "addresses.\n"}, | ||||
"\nExamples:\n" | RPCExamples{ | ||||
"\nSend two amounts to two different addresses:\n" + | "\nSend two amounts to two different addresses:\n" + | ||||
HelpExampleCli("sendmany", | HelpExampleCli( | ||||
"sendmany", | |||||
"\"\" " | "\"\" " | ||||
"\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}" | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}" | ||||
"\"") + | "\"") + | ||||
"\nSend two amounts to two different addresses setting the " | "\nSend two amounts to two different addresses setting the " | ||||
"confirmation and comment:\n" + | "confirmation and comment:\n" + | ||||
HelpExampleCli("sendmany", | HelpExampleCli( | ||||
"sendmany", | |||||
"\"\" " | "\"\" " | ||||
"\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " | ||||
"6 \"testing\"") + | "6 \"testing\"") + | ||||
"\nSend two amounts to two different addresses, subtract fee from " | "\nSend two amounts to two different addresses, subtract fee " | ||||
"amount:\n" + | "from amount:\n" + | ||||
HelpExampleCli("sendmany", | HelpExampleCli( | ||||
"sendmany", | |||||
"\"\" " | "\"\" " | ||||
"\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " | ||||
"1 \"\" " | "1 \"\" " | ||||
"\"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\"," | "\"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\"," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") + | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("sendmany", | HelpExampleRpc( | ||||
"sendmany", | |||||
"\"\", " | "\"\", " | ||||
"\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"," | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"," | ||||
" 6, \"testing\"")); | " 6, \"testing\"")}, | ||||
} | |||||
.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 3,871 Lines • Show Last 20 Lines |