Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | static std::string LabelFromValue(const UniValue &value) { | ||||
if (label == "*") { | if (label == "*") { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | ||||
} | } | ||||
return label; | return label; | ||||
} | } | ||||
static UniValue getnewaddress(const Config &config, | static UniValue getnewaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getnewaddress", | "getnewaddress", | ||||
"Returns a new Bitcoin address for receiving payments.\n" | "Returns 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, /* default */ "null", | {"label", RPCArg::Type::STR, /* default */ "null", | ||||
"The label name for the address to be linked to. If not provided, " | "The label name for the address to be linked to. If not provided, " | ||||
"the default label \"\" is used. It can also be set to the empty " | "the default label \"\" is used. It can also be set to the empty " | ||||
"string \"\" to represent the default label. The label does not " | "string \"\" to represent the default label. The label does not " | ||||
"need to exist, it will be created if there is no label by the " | "need to exist, it will be created if there is no label by the " | ||||
"given name."}, | "given name."}, | ||||
{"address_type", RPCArg::Type::STR, | {"address_type", RPCArg::Type::STR, | ||||
/* default */ "set by -addresstype", | /* default */ "set by -addresstype", | ||||
"The address type to use. Options are \"legacy\"."}, | "The address type to use. Options are \"legacy\"."}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::STR, "address", "The new bitcoin address"}, | RPCResult{RPCResult::Type::STR, "address", "The new bitcoin address"}, | ||||
RPCExamples{HelpExampleCli("getnewaddress", "") + | RPCExamples{HelpExampleCli("getnewaddress", "") + | ||||
HelpExampleRpc("getnewaddress", "")}, | HelpExampleRpc("getnewaddress", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->CanGetAddresses()) { | if (!pwallet->CanGetAddresses()) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: This wallet has no available keys"); | "Error: This wallet has no available keys"); | ||||
} | } | ||||
// Parse the label first so we don't generate a key if there's an error | // Parse the label first so we don't generate a key if there's an error | ||||
Show All 17 Lines | if (!pwallet->GetNewDestination(output_type, label, dest, error)) { | ||||
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error); | throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error); | ||||
} | } | ||||
return EncodeDestination(dest, config); | return EncodeDestination(dest, config); | ||||
} | } | ||||
static UniValue getrawchangeaddress(const Config &config, | static UniValue getrawchangeaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getrawchangeaddress", | "getrawchangeaddress", | ||||
"Returns a new Bitcoin address, for receiving change.\n" | "Returns 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", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::STR, "address", "The address"}, | RPCResult{RPCResult::Type::STR, "address", "The address"}, | ||||
RPCExamples{HelpExampleCli("getrawchangeaddress", "") + | RPCExamples{HelpExampleCli("getrawchangeaddress", "") + | ||||
HelpExampleRpc("getrawchangeaddress", "")}, | HelpExampleRpc("getrawchangeaddress", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->CanGetAddresses(true)) { | if (!pwallet->CanGetAddresses(true)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error: This wallet has no available keys"); | "Error: This wallet has no available keys"); | ||||
} | } | ||||
OutputType output_type = | OutputType output_type = | ||||
Show All 12 Lines | static UniValue getrawchangeaddress(const Config &config, | ||||
std::string error; | std::string error; | ||||
if (!pwallet->GetNewChangeDestination(output_type, dest, error)) { | if (!pwallet->GetNewChangeDestination(output_type, dest, error)) { | ||||
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error); | throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error); | ||||
} | } | ||||
return EncodeDestination(dest, config); | return EncodeDestination(dest, config); | ||||
} | } | ||||
static UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | static UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"setlabel", | "setlabel", | ||||
"Sets the label associated with the given address.\n", | "Sets the label associated with the given address.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The bitcoin address to be associated with a label."}, | "The bitcoin address to be associated with a label."}, | ||||
{"label", RPCArg::Type::STR, RPCArg::Optional::NO, | {"label", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The label to assign to the address."}, | "The label to assign to the address."}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{ | RPCExamples{ | ||||
HelpExampleCli("setlabel", | HelpExampleCli("setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"setlabel", | "setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")}, | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
CTxDestination dest = DecodeDestination(request.params[0].get_str(), | CTxDestination dest = DecodeDestination(request.params[0].get_str(), | ||||
wallet->GetChainParams()); | wallet->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 49 Lines • ▼ Show 20 Lines | if (!pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, | ||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
} | } | ||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | ||||
return tx; | return tx; | ||||
} | } | ||||
static UniValue sendtoaddress(const Config &config, | static UniValue sendtoaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"sendtoaddress", | "sendtoaddress", | ||||
"Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE, | "Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
{"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"}, | ||||
Show All 30 Lines | RPCHelpMan{ | ||||
HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44" | HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44" | ||||
"Jvaydd\" 0.1 \"\" \"\" true") + | "Jvaydd\" 0.1 \"\" \"\" true") + | ||||
HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | ||||
"dd\", 0.1, \"donation\", \"seans " | "dd\", 0.1, \"donation\", \"seans " | ||||
"outpost\"")}, | "outpost\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
CTxDestination dest = DecodeDestination(request.params[0].get_str(), | CTxDestination dest = DecodeDestination(request.params[0].get_str(), | ||||
wallet->GetChainParams()); | wallet->GetChainParams()); | ||||
Show All 32 Lines | static UniValue sendtoaddress(const Config &config, | ||||
CTransactionRef tx = | CTransactionRef tx = | ||||
SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, coin_control, | SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, coin_control, | ||||
std::move(mapValue)); | std::move(mapValue)); | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue listaddressgroupings(const Config &config, | static UniValue listaddressgroupings(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listaddressgroupings", | "listaddressgroupings", | ||||
"Lists groups of addresses which have had their common ownership\n" | "Lists groups of addresses which have had their common ownership\n" | ||||
"made public by common use as inputs or as the resulting change\n" | "made public by common use as inputs or as the resulting change\n" | ||||
"in past transactions\n", | "in past transactions\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::ARR, | RPCResult{RPCResult::Type::ARR, | ||||
"", | "", | ||||
Show All 16 Lines | RPCHelpMan{ | ||||
}}, | }}, | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("listaddressgroupings", "") + | RPCExamples{HelpExampleCli("listaddressgroupings", "") + | ||||
HelpExampleRpc("listaddressgroupings", "")}, | HelpExampleRpc("listaddressgroupings", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
UniValue jsonGroupings(UniValue::VARR); | UniValue jsonGroupings(UniValue::VARR); | ||||
std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | ||||
Show All 15 Lines | for (const std::set<CTxDestination> &grouping : | ||||
jsonGroupings.push_back(jsonGrouping); | jsonGroupings.push_back(jsonGrouping); | ||||
} | } | ||||
return jsonGroupings; | return jsonGroupings; | ||||
} | } | ||||
static UniValue signmessage(const Config &config, | static UniValue signmessage(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"signmessage", | "signmessage", | ||||
"Sign a message with the private key of an address" + | "Sign a message with the private key of an address" + | ||||
HELP_REQUIRING_PASSPHRASE, | 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, | ||||
Show All 13 Lines | RPCHelpMan{ | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" " | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" " | ||||
"\"signature\" \"my message\"") + | "\"signature\" \"my message\"") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"signmessage", | "signmessage", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")}, | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
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(); | ||||
std::string strMessage = request.params[1].get_str(); | std::string strMessage = request.params[1].get_str(); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | for (const std::pair<const TxId, CWalletTx> &wtx_pair : wallet.mapWallet) { | ||||
} | } | ||||
} | } | ||||
return amount; | return amount; | ||||
} | } | ||||
static UniValue getreceivedbyaddress(const Config &config, | static UniValue getreceivedbyaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getreceivedbyaddress", | "getreceivedbyaddress", | ||||
"Returns the total amount received by the given address in " | "Returns 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, RPCArg::Optional::NO, | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The bitcoin address for transactions."}, | "The bitcoin address for transactions."}, | ||||
{"minconf", RPCArg::Type::NUM, /* default */ "1", | {"minconf", RPCArg::Type::NUM, /* default */ "1", | ||||
Show All 14 Lines | RPCHelpMan{ | ||||
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")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ValueFromAmount(GetReceived(*pwallet, request.params, | return ValueFromAmount(GetReceived(*pwallet, request.params, | ||||
/* by_label */ false)); | /* by_label */ false)); | ||||
} | } | ||||
static UniValue getreceivedbylabel(const Config &config, | static UniValue getreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getreceivedbylabel", | "getreceivedbylabel", | ||||
"Returns the total amount received by addresses with <label> in " | "Returns the total amount received by addresses with <label> in " | ||||
"transactions with at least [minconf] confirmations.\n", | "transactions with at least [minconf] confirmations.\n", | ||||
{ | { | ||||
{"label", RPCArg::Type::STR, RPCArg::Optional::NO, | {"label", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The selected label, may be the default label using \"\"."}, | "The selected label, may be the default label using \"\"."}, | ||||
{"minconf", RPCArg::Type::NUM, /* default */ "1", | {"minconf", RPCArg::Type::NUM, /* default */ "1", | ||||
Show All 10 Lines | RPCHelpMan{ | ||||
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")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ValueFromAmount(GetReceived(*pwallet, request.params, | return ValueFromAmount(GetReceived(*pwallet, request.params, | ||||
/* by_label */ true)); | /* by_label */ true)); | ||||
} | } | ||||
static UniValue getbalance(const Config &config, | static UniValue getbalance(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getbalance", | "getbalance", | ||||
"Returns the total available balance.\n" | "Returns the total available balance.\n" | ||||
"The available balance is what the wallet considers currently " | "The available balance is what the wallet considers currently " | ||||
"spendable, and is\n" | "spendable, and is\n" | ||||
"thus affected by options which limit spendability such as " | "thus affected by options which limit spendability such as " | ||||
"-spendzeroconfchange.\n", | "-spendzeroconfchange.\n", | ||||
{ | { | ||||
Show All 19 Lines | RPCHelpMan{ | ||||
"\nThe total amount in the wallet with 0 or more confirmations\n" + | "\nThe total amount in the wallet with 0 or more confirmations\n" + | ||||
HelpExampleCli("getbalance", "") + | HelpExampleCli("getbalance", "") + | ||||
"\nThe total amount in the wallet with at least 6 confirmations\n" + | "\nThe total amount in the wallet with at least 6 confirmations\n" + | ||||
HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a JSON-RPC call\n" + | HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("getbalance", "\"*\", 6")}, | HelpExampleRpc("getbalance", "\"*\", 6")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
const UniValue &dummy_value = request.params[0]; | const UniValue &dummy_value = request.params[0]; | ||||
if (!dummy_value.isNull() && dummy_value.get_str() != "*") { | if (!dummy_value.isNull() && dummy_value.get_str() != "*") { | ||||
Show All 15 Lines | static UniValue getbalance(const Config &config, | ||||
return ValueFromAmount(bal.m_mine_trusted + (include_watchonly | return ValueFromAmount(bal.m_mine_trusted + (include_watchonly | ||||
? bal.m_watchonly_trusted | ? bal.m_watchonly_trusted | ||||
: Amount::zero())); | : Amount::zero())); | ||||
} | } | ||||
static UniValue getunconfirmedbalance(const Config &config, | static UniValue getunconfirmedbalance(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getunconfirmedbalance", | "getunconfirmedbalance", | ||||
"DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n", | "DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::NUM, "", "The balance"}, | RPCResult{RPCResult::Type::NUM, "", "The balance"}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ValueFromAmount(pwallet->GetBalance().m_mine_untrusted_pending); | return ValueFromAmount(pwallet->GetBalance().m_mine_untrusted_pending); | ||||
} | } | ||||
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); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"sendmany", | "sendmany", | ||||
"Send multiple times. Amounts are double-precision " | "Send multiple times. Amounts are double-precision " | ||||
"floating point numbers." + | "floating point numbers." + | ||||
HELP_REQUIRING_PASSPHRASE, | 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.", "\"\""}, | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\"\", " | "\"\", " | ||||
"{\"bchtest:qplljx455cznj2yrtdhj0jcm7syxlzqnaqt0ku5kjl\":0.01," | "{\"bchtest:qplljx455cznj2yrtdhj0jcm7syxlzqnaqt0ku5kjl\":0.01," | ||||
"\"bchtest:qzmnuh8t24yrxq4mvjakt84r7j3f9tunlvm2p7qef9\":0.02}, " | "\"bchtest:qzmnuh8t24yrxq4mvjakt84r7j3f9tunlvm2p7qef9\":0.02}, " | ||||
"6, " | "6, " | ||||
"\"testing\"")}, | "\"testing\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { | if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (!fCreated) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); | ||||
} | } | ||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue addmultisigaddress(const Config &config, | static UniValue addmultisigaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"addmultisigaddress", | "addmultisigaddress", | ||||
"Add an nrequired-to-sign multisignature address to the wallet. " | "Add an nrequired-to-sign multisignature address to the wallet. " | ||||
"Requires a new wallet backup.\n" | "Requires a new wallet backup.\n" | ||||
"Each key is a Bitcoin address or hex-encoded public key.\n" | "Each key is a Bitcoin address or hex-encoded public key.\n" | ||||
"This functionality is only intended for use with non-watchonly " | "This functionality is only intended for use with non-watchonly " | ||||
"addresses.\n" | "addresses.\n" | ||||
"See `importaddress` for watchonly p2sh address support.\n" | "See `importaddress` for watchonly p2sh address support.\n" | ||||
Show All 35 Lines | RPCHelpMan{ | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("addmultisigaddress", | HelpExampleRpc("addmultisigaddress", | ||||
"2, " | "2, " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")}, | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*pwallet); | LegacyScriptPubKeyMan &spk_man = EnsureLegacyScriptPubKeyMan(*pwallet); | ||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore); | LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore); | ||||
std::string label; | std::string label; | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
label = LabelFromValue(request.params[2]); | label = LabelFromValue(request.params[2]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | if (by_label) { | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listreceivedbyaddress(const Config &config, | static UniValue listreceivedbyaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listreceivedbyaddress", | "listreceivedbyaddress", | ||||
"List balances by receiving address.\n", | "List balances by receiving address.\n", | ||||
{ | { | ||||
{"minconf", RPCArg::Type::NUM, /* default */ "1", | {"minconf", RPCArg::Type::NUM, /* default */ "1", | ||||
"The minimum number of confirmations before payments are " | "The minimum number of confirmations before payments are " | ||||
"included."}, | "included."}, | ||||
{"include_empty", RPCArg::Type::BOOL, /* default */ "false", | {"include_empty", RPCArg::Type::BOOL, /* default */ "false", | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
HelpExampleCli("listreceivedbyaddress", "6 true") + | HelpExampleCli("listreceivedbyaddress", "6 true") + | ||||
HelpExampleRpc("listreceivedbyaddress", "6, true, true") + | HelpExampleRpc("listreceivedbyaddress", "6, true, true") + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"listreceivedbyaddress", | "listreceivedbyaddress", | ||||
"6, true, true, \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")}, | "6, true, true, \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ListReceived(config, pwallet, request.params, false); | return ListReceived(config, pwallet, request.params, false); | ||||
} | } | ||||
static UniValue listreceivedbylabel(const Config &config, | static UniValue listreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listreceivedbylabel", | "listreceivedbylabel", | ||||
"List received transactions by label.\n", | "List received transactions by label.\n", | ||||
{ | { | ||||
{"minconf", RPCArg::Type::NUM, /* default */ "1", | {"minconf", RPCArg::Type::NUM, /* default */ "1", | ||||
"The minimum number of confirmations before payments are " | "The minimum number of confirmations before payments are " | ||||
"included."}, | "included."}, | ||||
{"include_empty", RPCArg::Type::BOOL, /* default */ "false", | {"include_empty", RPCArg::Type::BOOL, /* default */ "false", | ||||
Show All 25 Lines | RPCHelpMan{ | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("listreceivedbylabel", "") + | RPCExamples{HelpExampleCli("listreceivedbylabel", "") + | ||||
HelpExampleCli("listreceivedbylabel", "6 true") + | HelpExampleCli("listreceivedbylabel", "6 true") + | ||||
HelpExampleRpc("listreceivedbylabel", "6, true, true")}, | HelpExampleRpc("listreceivedbylabel", "6, true, true")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ListReceived(config, pwallet, request.params, true); | return ListReceived(config, pwallet, request.params, true); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | return { | ||||
"The time received expressed in " + UNIX_EPOCH_TIME + "."}, | "The time received expressed in " + UNIX_EPOCH_TIME + "."}, | ||||
{RPCResult::Type::STR, "comment", | {RPCResult::Type::STR, "comment", | ||||
"If a comment is associated with the transaction, only present if not " | "If a comment is associated with the transaction, only present if not " | ||||
"empty."}, | "empty."}, | ||||
}; | }; | ||||
} | } | ||||
UniValue listtransactions(const Config &config, const JSONRPCRequest &request) { | UniValue listtransactions(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listtransactions", | "listtransactions", | ||||
"If a label name is provided, this will return only incoming " | "If a label name is provided, this will return only incoming " | ||||
"transactions paying to addresses with the specified label.\n" | "transactions paying to addresses with the specified label.\n" | ||||
"\nReturns up to 'count' most recent transactions skipping the first " | "\nReturns up to 'count' most recent transactions skipping the first " | ||||
"'from' transactions.\n", | "'from' transactions.\n", | ||||
{ | { | ||||
{"label|dummy", RPCArg::Type::STR, | {"label|dummy", RPCArg::Type::STR, | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
HelpExampleCli("listtransactions", "") + | HelpExampleCli("listtransactions", "") + | ||||
"\nList transactions 100 to 120\n" + | "\nList transactions 100 to 120\n" + | ||||
HelpExampleCli("listtransactions", "\"*\" 20 100") + | HelpExampleCli("listtransactions", "\"*\" 20 100") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("listtransactions", "\"*\", 20, 100")}, | HelpExampleRpc("listtransactions", "\"*\", 20, 100")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
const std::string *filter_label = nullptr; | const std::string *filter_label = nullptr; | ||||
if (!request.params[0].isNull() && request.params[0].get_str() != "*") { | if (!request.params[0].isNull() && request.params[0].get_str() != "*") { | ||||
filter_label = &request.params[0].get_str(); | filter_label = &request.params[0].get_str(); | ||||
if (filter_label->empty()) { | if (filter_label->empty()) { | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | UniValue listtransactions(const Config &config, const JSONRPCRequest &request) { | ||||
UniValue result{UniValue::VARR}; | UniValue result{UniValue::VARR}; | ||||
// Return oldest to newest | // Return oldest to newest | ||||
result.push_backV({txs.rend() - nFrom - nCount, txs.rend() - nFrom}); | result.push_backV({txs.rend() - nFrom - nCount, txs.rend() - nFrom}); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue listsinceblock(const Config &config, | static UniValue listsinceblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const pwallet = | |||||
GetWalletForJSONRPCRequest(request); | |||||
if (!pwallet) { | |||||
return NullUniValue; | |||||
} | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listsinceblock", | "listsinceblock", | ||||
"Get all transactions in blocks since block [blockhash], or all " | "Get all transactions in blocks since block [blockhash], or all " | ||||
"transactions if omitted.\n" | "transactions if omitted.\n" | ||||
"If \"blockhash\" is no longer a part of the main chain, transactions " | "If \"blockhash\" is no longer a part of the main chain, transactions " | ||||
"from the fork point onward are included.\n" | "from the fork point onward are included.\n" | ||||
"Additionally, if include_removed is set, transactions affecting the " | "Additionally, if include_removed is set, transactions affecting the " | ||||
"wallet which were removed are returned in the \"removed\" array.\n", | "wallet which were removed are returned in the \"removed\" array.\n", | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\"000000000000000bacf66f7497b7dc45ef753ee9a" | "\"000000000000000bacf66f7497b7dc45ef753ee9a" | ||||
"7d38571037cdb1a57f663ad\" 6") + | "7d38571037cdb1a57f663ad\" 6") + | ||||
HelpExampleRpc("listsinceblock", | HelpExampleRpc("listsinceblock", | ||||
"\"000000000000000bacf66f7497b7dc45ef753ee9a" | "\"000000000000000bacf66f7497b7dc45ef753ee9a" | ||||
"7d38571037cdb1a57f663ad\", 6")}, | "7d38571037cdb1a57f663ad\", 6")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const pwallet = | |||||
GetWalletForJSONRPCRequest(request); | |||||
if (!pwallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet &wallet = *pwallet; | const CWallet &wallet = *pwallet; | ||||
// 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 | ||||
wallet.BlockUntilSyncedToCurrentChain(); | wallet.BlockUntilSyncedToCurrentChain(); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
// Height of the specified block or the common ancestor, if the block | // Height of the specified block or the common ancestor, if the block | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
} | } | ||||
ret.pushKV("lastblock", lastblock.GetHex()); | ret.pushKV("lastblock", lastblock.GetHex()); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue gettransaction(const Config &config, | static UniValue gettransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"gettransaction", | "gettransaction", | ||||
"Get detailed information about in-wallet transaction <txid>\n", | "Get detailed information about in-wallet transaction <txid>\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, | {"txid", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The transaction id"}, | "The transaction id"}, | ||||
{"include_watchonly", RPCArg::Type::BOOL, | {"include_watchonly", RPCArg::Type::BOOL, | ||||
/* default */ "true for watch-only wallets, otherwise false", | /* default */ "true for watch-only wallets, otherwise false", | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\"1075db55d416d3ca199f55b6084e2115b9345e16c" | "\"1075db55d416d3ca199f55b6084e2115b9345e16c" | ||||
"5cf302fc80e9d5fbf5d48d\" false true") + | "5cf302fc80e9d5fbf5d48d\" false true") + | ||||
HelpExampleRpc("gettransaction", | HelpExampleRpc("gettransaction", | ||||
"\"1075db55d416d3ca199f55b6084e2115b9345e16c" | "\"1075db55d416d3ca199f55b6084e2115b9345e16c" | ||||
"5cf302fc80e9d5fbf5d48d\"")}, | "5cf302fc80e9d5fbf5d48d\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
TxId txid(ParseHashV(request.params[0], "txid")); | TxId txid(ParseHashV(request.params[0], "txid")); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (verbose) { | ||||
entry.pushKV("decoded", decoded); | entry.pushKV("decoded", decoded); | ||||
} | } | ||||
return entry; | return entry; | ||||
} | } | ||||
static UniValue abandontransaction(const Config &config, | static UniValue abandontransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"abandontransaction", | "abandontransaction", | ||||
"Mark in-wallet transaction <txid> as abandoned\n" | "Mark in-wallet transaction <txid> as abandoned\n" | ||||
"This will mark this transaction and all its in-wallet descendants as " | "This will mark this transaction and all its in-wallet descendants as " | ||||
"abandoned which will allow\n" | "abandoned which will allow\n" | ||||
"for their inputs to be respent. It can be used to replace \"stuck\" " | "for their inputs to be respent. It can be used to replace \"stuck\" " | ||||
"or evicted transactions.\n" | "or evicted transactions.\n" | ||||
"It only works on transactions which are not included in a block and " | "It only works on transactions which are not included in a block and " | ||||
"are not currently in the mempool.\n" | "are not currently in the mempool.\n" | ||||
"It has no effect on transactions which are already abandoned.\n", | "It has no effect on transactions which are already abandoned.\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | ||||
"The transaction id"}, | "The transaction id"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("abandontransaction", | RPCExamples{HelpExampleCli("abandontransaction", | ||||
"\"1075db55d416d3ca199f55b6084e2115b9345e16c" | "\"1075db55d416d3ca199f55b6084e2115b9345e16c" | ||||
"5cf302fc80e9d5fbf5d48d\"") + | "5cf302fc80e9d5fbf5d48d\"") + | ||||
HelpExampleRpc("abandontransaction", | HelpExampleRpc("abandontransaction", | ||||
"\"1075db55d416d3ca199f55b6084e2115b9345e16c" | "\"1075db55d416d3ca199f55b6084e2115b9345e16c" | ||||
"5cf302fc80e9d5fbf5d48d\"")}, | "5cf302fc80e9d5fbf5d48d\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
TxId txid(ParseHashV(request.params[0], "txid")); | TxId txid(ParseHashV(request.params[0], "txid")); | ||||
if (!pwallet->mapWallet.count(txid)) { | if (!pwallet->mapWallet.count(txid)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid or non-wallet transaction id"); | "Invalid or non-wallet transaction id"); | ||||
} | } | ||||
if (!pwallet->AbandonTransaction(txid)) { | if (!pwallet->AbandonTransaction(txid)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not eligible for abandonment"); | "Transaction not eligible for abandonment"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue backupwallet(const Config &config, | static UniValue backupwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"backupwallet", | "backupwallet", | ||||
"Safely copies current wallet file to destination, which can be a " | "Safely copies current wallet file to destination, which can be a " | ||||
"directory or a path with filename.\n", | "directory or a path with filename.\n", | ||||
{ | { | ||||
{"destination", RPCArg::Type::STR, RPCArg::Optional::NO, | {"destination", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The destination directory or file"}, | "The destination directory or file"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("backupwallet", "\"backup.dat\"") + | RPCExamples{HelpExampleCli("backupwallet", "\"backup.dat\"") + | ||||
HelpExampleRpc("backupwallet", "\"backup.dat\"")}, | HelpExampleRpc("backupwallet", "\"backup.dat\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::string strDest = request.params[0].get_str(); | std::string strDest = request.params[0].get_str(); | ||||
if (!pwallet->BackupWallet(strDest)) { | if (!pwallet->BackupWallet(strDest)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); | throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue keypoolrefill(const Config &config, | static UniValue keypoolrefill(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"keypoolrefill", | "keypoolrefill", | ||||
"Fills the keypool." + HELP_REQUIRING_PASSPHRASE, | "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", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
if (pwallet->IsLegacy() && | if (pwallet->IsLegacy() && | ||||
pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | 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"); | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
Show All 15 Lines | if (pwallet->GetKeyPoolSize() < kpSize) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); | throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue walletpassphrase(const Config &config, | static UniValue walletpassphrase(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"walletpassphrase", | "walletpassphrase", | ||||
"Stores the wallet decryption key in memory for 'timeout' seconds.\n" | "Stores the wallet decryption key in memory for 'timeout' seconds.\n" | ||||
"This is needed prior to performing transactions related to private " | "This is needed prior to performing transactions related to private " | ||||
"keys such as sending bitcoins\n" | "keys such as sending bitcoins\n" | ||||
"\nNote:\n" | "\nNote:\n" | ||||
"Issuing the walletpassphrase command while the wallet is already " | "Issuing the walletpassphrase command while the wallet is already " | ||||
"unlocked will set a new unlock\n" | "unlocked will set a new unlock\n" | ||||
Show All 10 Lines | RPCHelpMan{ | ||||
"\nUnlock the wallet for 60 seconds\n" + | "\nUnlock the wallet for 60 seconds\n" + | ||||
HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + | HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + | ||||
"\nLock the wallet again (before 60 seconds)\n" + | "\nLock the wallet again (before 60 seconds)\n" + | ||||
HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")}, | HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
int64_t nSleepTime; | int64_t nSleepTime; | ||||
int64_t relock_time; | int64_t relock_time; | ||||
// Prevent concurrent calls to walletpassphrase with the same wallet. | // Prevent concurrent calls to walletpassphrase with the same wallet. | ||||
LOCK(pwallet->m_unlock_mutex); | LOCK(pwallet->m_unlock_mutex); | ||||
{ | { | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | pwallet->chain().rpcRunLater( | ||||
}, | }, | ||||
nSleepTime); | nSleepTime); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue walletpassphrasechange(const Config &config, | static UniValue walletpassphrasechange(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"walletpassphrasechange", | "walletpassphrasechange", | ||||
"Changes the wallet passphrase from 'oldpassphrase' to " | "Changes the wallet passphrase from 'oldpassphrase' to " | ||||
"'newpassphrase'.\n", | "'newpassphrase'.\n", | ||||
{ | { | ||||
{"oldpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, | {"oldpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The current passphrase"}, | "The current passphrase"}, | ||||
{"newpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, | {"newpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The new passphrase"}, | "The new passphrase"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("walletpassphrasechange", | RPCExamples{HelpExampleCli("walletpassphrasechange", | ||||
"\"old one\" \"new one\"") + | "\"old one\" \"new one\"") + | ||||
HelpExampleRpc("walletpassphrasechange", | HelpExampleRpc("walletpassphrasechange", | ||||
"\"old one\", \"new one\"")}, | "\"old one\", \"new one\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an unencrypted wallet, but " | "Error: running with an unencrypted wallet, but " | ||||
"walletpassphrasechange was called."); | "walletpassphrasechange was called."); | ||||
} | } | ||||
Show All 20 Lines | if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) { | ||||
"Error: The wallet passphrase entered was incorrect."); | "Error: The wallet passphrase entered was incorrect."); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue walletlock(const Config &config, | static UniValue walletlock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"walletlock", | "walletlock", | ||||
"Removes the wallet encryption key from memory, locking the wallet.\n" | "Removes the wallet encryption key from memory, locking the wallet.\n" | ||||
"After calling this method, you will need to call walletpassphrase " | "After calling this method, you will need to call walletpassphrase " | ||||
"again\n" | "again\n" | ||||
"before being able to call any methods which require the wallet to be " | "before being able to call any methods which require the wallet to be " | ||||
"unlocked.\n", | "unlocked.\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{ | 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", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (!pwallet->IsCrypted()) { | if (!pwallet->IsCrypted()) { | ||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, | ||||
"Error: running with an unencrypted wallet, but " | "Error: running with an unencrypted wallet, but " | ||||
"walletlock was called."); | "walletlock was called."); | ||||
} | } | ||||
pwallet->Lock(); | pwallet->Lock(); | ||||
pwallet->nRelockTime = 0; | pwallet->nRelockTime = 0; | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue encryptwallet(const Config &config, | static UniValue encryptwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"encryptwallet", | "encryptwallet", | ||||
"Encrypts the wallet with 'passphrase'. This is for first time " | "Encrypts the wallet with 'passphrase'. This is for first time " | ||||
"encryption.\n" | "encryption.\n" | ||||
"After this, any calls that interact with private keys such as sending " | "After this, any calls that interact with private keys such as sending " | ||||
"or signing \n" | "or signing \n" | ||||
"will require the passphrase to be set prior the making these calls.\n" | "will require the passphrase to be set prior the making these calls.\n" | ||||
"Use the walletpassphrase call for this, and then walletlock call.\n" | "Use the walletpassphrase call for this, and then walletlock call.\n" | ||||
Show All 15 Lines | RPCHelpMan{ | ||||
"\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\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ENCRYPTION_FAILED, | RPC_WALLET_ENCRYPTION_FAILED, | ||||
"Error: wallet does not contain private keys, nothing to encrypt."); | "Error: wallet does not contain private keys, nothing to encrypt."); | ||||
} | } | ||||
Show All 23 Lines | static UniValue encryptwallet(const Config &config, | ||||
return "wallet encrypted; The keypool has been flushed and a new HD seed " | return "wallet encrypted; The keypool has been flushed and a new HD seed " | ||||
"was generated (if you are using HD). You need to make a new " | "was generated (if you are using HD). You need to make a new " | ||||
"backup."; | "backup."; | ||||
} | } | ||||
static UniValue lockunspent(const Config &config, | static UniValue lockunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"lockunspent", | "lockunspent", | ||||
"Updates list of temporarily unspendable outputs.\n" | "Updates list of temporarily unspendable outputs.\n" | ||||
"Temporarily lock (unlock=false) or unlock (unlock=true) specified " | "Temporarily lock (unlock=false) or unlock (unlock=true) specified " | ||||
"transaction outputs.\n" | "transaction outputs.\n" | ||||
"If no transaction outputs are specified when unlocking then all " | "If no transaction outputs are specified when unlocking then 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 coin " | "A locked transaction output will not be chosen by automatic coin " | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
HelpExampleRpc("lockunspent", "false, " | HelpExampleRpc("lockunspent", "false, " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"txid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"")}, | ",\\\"vout\\\":1}]\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
RPCTypeCheckArgument(request.params[0], UniValue::VBOOL); | RPCTypeCheckArgument(request.params[0], UniValue::VBOOL); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | for (const COutPoint &output : outputs) { | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static UniValue listlockunspent(const Config &config, | static UniValue listlockunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listlockunspent", | "listlockunspent", | ||||
"Returns list of temporarily unspendable outputs.\n" | "Returns list of temporarily unspendable outputs.\n" | ||||
"See the lockunspent call to lock and unlock transactions for " | "See the lockunspent call to lock and unlock transactions for " | ||||
"spending.\n", | "spending.\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::ARR, | RPCResult{RPCResult::Type::ARR, | ||||
"", | "", | ||||
Show All 24 Lines | RPCHelpMan{ | ||||
"\"[{\\\"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", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::vector<COutPoint> vOutpts; | std::vector<COutPoint> vOutpts; | ||||
pwallet->ListLockedCoins(vOutpts); | pwallet->ListLockedCoins(vOutpts); | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const COutPoint &output : vOutpts) { | for (const COutPoint &output : vOutpts) { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
o.pushKV("txid", output.GetTxId().GetHex()); | o.pushKV("txid", output.GetTxId().GetHex()); | ||||
o.pushKV("vout", int(output.GetN())); | o.pushKV("vout", int(output.GetN())); | ||||
ret.push_back(o); | ret.push_back(o); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"settxfee", | "settxfee", | ||||
"Set the transaction fee per kB for this wallet. Overrides the " | "Set the transaction fee per kB for this wallet. Overrides the " | ||||
"global -paytxfee command line parameter.\n" | "global -paytxfee command line parameter.\n" | ||||
"Can be deactivated by passing 0 as the fee. In that case automatic " | "Can be deactivated by passing 0 as the fee. In that case automatic " | ||||
"fee selection will be used by default.\n", | "fee selection will be used by default.\n", | ||||
{ | { | ||||
{"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, | {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, | ||||
"The transaction fee in " + CURRENCY_UNIT + "/kB"}, | "The transaction fee in " + CURRENCY_UNIT + "/kB"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::BOOL, "", "Returns true if successful"}, | RPCResult{RPCResult::Type::BOOL, "", "Returns true if successful"}, | ||||
RPCExamples{HelpExampleCli("settxfee", "0.00001") + | RPCExamples{HelpExampleCli("settxfee", "0.00001") + | ||||
HelpExampleRpc("settxfee", "0.00001")}, | HelpExampleRpc("settxfee", "0.00001")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
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); | ||||
CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000); | CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000); | ||||
if (tx_fee_rate == CFeeRate()) { | if (tx_fee_rate == CFeeRate()) { | ||||
// automatic selection | // automatic selection | ||||
} else if (tx_fee_rate < pwallet->chain().relayMinFee()) { | } else if (tx_fee_rate < pwallet->chain().relayMinFee()) { | ||||
Show All 14 Lines | static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
pwallet->m_pay_tx_fee = tx_fee_rate; | pwallet->m_pay_tx_fee = tx_fee_rate; | ||||
return true; | return true; | ||||
} | } | ||||
static UniValue getbalances(const Config &config, | static UniValue getbalances(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const rpc_wallet = | |||||
GetWalletForJSONRPCRequest(request); | |||||
if (!rpc_wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet &wallet = *rpc_wallet; | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getbalances", | "getbalances", | ||||
"Returns an object with all balances in " + CURRENCY_UNIT + ".\n", | "Returns an object with all balances in " + CURRENCY_UNIT + ".\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::OBJ, | RPCResult{RPCResult::Type::OBJ, | ||||
"", | "", | ||||
"", | "", | ||||
{ | { | ||||
Show All 29 Lines | RPCHelpMan{ | ||||
"balance from immature coinbase outputs"}, | "balance from immature coinbase outputs"}, | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("getbalances", "") + | RPCExamples{HelpExampleCli("getbalances", "") + | ||||
HelpExampleRpc("getbalances", "")}, | HelpExampleRpc("getbalances", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const rpc_wallet = | |||||
GetWalletForJSONRPCRequest(request); | |||||
if (!rpc_wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet &wallet = *rpc_wallet; | |||||
// 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 | ||||
wallet.BlockUntilSyncedToCurrentChain(); | wallet.BlockUntilSyncedToCurrentChain(); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
const auto bal = wallet.GetBalance(); | const auto bal = wallet.GetBalance(); | ||||
UniValue balances{UniValue::VOBJ}; | UniValue balances{UniValue::VOBJ}; | ||||
Show All 28 Lines | if (spk_man && spk_man->HaveWatchOnly()) { | ||||
ValueFromAmount(bal.m_watchonly_immature)); | ValueFromAmount(bal.m_watchonly_immature)); | ||||
balances.pushKV("watchonly", balances_watchonly); | balances.pushKV("watchonly", balances_watchonly); | ||||
} | } | ||||
return balances; | return balances; | ||||
} | } | ||||
static UniValue getwalletinfo(const Config &config, | static UniValue getwalletinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getwalletinfo", | "getwalletinfo", | ||||
"Returns an object containing various wallet state info.\n", | "Returns an object containing various wallet state info.\n", | ||||
{}, | {}, | ||||
RPCResult{ | RPCResult{ | ||||
RPCResult::Type::OBJ, | RPCResult::Type::OBJ, | ||||
"", | "", | ||||
"", | "", | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"management"}, | "management"}, | ||||
}}, | }}, | ||||
}, | }, | ||||
RPCExamples{HelpExampleCli("getwalletinfo", "") + | RPCExamples{HelpExampleCli("getwalletinfo", "") + | ||||
HelpExampleRpc("getwalletinfo", "")}, | HelpExampleRpc("getwalletinfo", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
// 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(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | static UniValue loadwallet(const Config &config, | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); | obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue setwalletflag(const Config &config, | static UniValue setwalletflag(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
std::string flags = ""; | std::string flags = ""; | ||||
for (auto &it : WALLET_FLAG_MAP) { | for (auto &it : WALLET_FLAG_MAP) { | ||||
if (it.second & MUTABLE_WALLET_FLAGS) { | if (it.second & MUTABLE_WALLET_FLAGS) { | ||||
flags += (flags == "" ? "" : ", ") + it.first; | flags += (flags == "" ? "" : ", ") + it.first; | ||||
} | } | ||||
} | } | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"setwalletflag", | "setwalletflag", | ||||
Show All 16 Lines | RPCHelpMan{ | ||||
{RPCResult::Type::STR, "warnings", | {RPCResult::Type::STR, "warnings", | ||||
"Any warnings associated with the change"}, | "Any warnings associated with the change"}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("setwalletflag", "avoid_reuse") + | RPCExamples{HelpExampleCli("setwalletflag", "avoid_reuse") + | ||||
HelpExampleRpc("setwalletflag", "\"avoid_reuse\"")}, | HelpExampleRpc("setwalletflag", "\"avoid_reuse\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
std::string flag_str = request.params[0].get_str(); | std::string flag_str = request.params[0].get_str(); | ||||
bool value = request.params[1].isNull() || request.params[1].get_bool(); | bool value = request.params[1].isNull() || request.params[1].get_bool(); | ||||
if (!WALLET_FLAG_MAP.count(flag_str)) { | if (!WALLET_FLAG_MAP.count(flag_str)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
strprintf("Unknown wallet flag: %s", flag_str)); | strprintf("Unknown wallet flag: %s", flag_str)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | static UniValue unloadwallet(const Config &config, | ||||
UnloadWallet(std::move(wallet)); | UnloadWallet(std::move(wallet)); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue listunspent(const Config &config, | static UniValue listunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listunspent", | "listunspent", | ||||
"Returns array of unspent transaction outputs\n" | "Returns array of unspent transaction outputs\n" | ||||
"with between minconf and maxconf (inclusive) confirmations.\n" | "with between minconf and maxconf (inclusive) confirmations.\n" | ||||
"Optionally filter to only include txouts paid to specified " | "Optionally filter to only include txouts paid to specified " | ||||
"addresses.\n", | "addresses.\n", | ||||
{ | { | ||||
{"minconf", RPCArg::Type::NUM, /* default */ "1", | {"minconf", RPCArg::Type::NUM, /* default */ "1", | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"listunspent", | "listunspent", | ||||
"6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'") + | "6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'") + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"listunspent", | "listunspent", | ||||
"6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")}, | "6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM); | RPCTypeCheckArgument(request.params[0], UniValue::VNUM); | ||||
nMinDepth = request.params[0].get_int(); | nMinDepth = request.params[0].get_int(); | ||||
} | } | ||||
int nMaxDepth = 9999999; | int nMaxDepth = 9999999; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | if (!pwallet->FundTransaction(tx, fee_out, change_position, error, | ||||
lockUnspents, setSubtractFeeFromOutputs, | lockUnspents, setSubtractFeeFromOutputs, | ||||
coinControl)) { | coinControl)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
} | } | ||||
} | } | ||||
static UniValue fundrawtransaction(const Config &config, | static UniValue fundrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"fundrawtransaction", | "fundrawtransaction", | ||||
"If the transaction has no inputs, they will be automatically selected " | "If the transaction has no inputs, they will be automatically selected " | ||||
"to meet its out value.\n" | "to meet its out value.\n" | ||||
"It will add at most one change output to the outputs.\n" | "It will add at most one change output to the outputs.\n" | ||||
"No existing outputs will be modified unless " | "No existing outputs will be modified unless " | ||||
"\"subtractFeeFromOutputs\" is specified.\n" | "\"subtractFeeFromOutputs\" is specified.\n" | ||||
"Note that inputs which were signed may need to be resigned after " | "Note that inputs which were signed may need to be resigned after " | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\nSign the transaction\n" + | "\nSign the transaction\n" + | ||||
HelpExampleCli("signrawtransactionwithwallet", | HelpExampleCli("signrawtransactionwithwallet", | ||||
"\"fundedtransactionhex\"") + | "\"fundedtransactionhex\"") + | ||||
"\nSend the transaction\n" + | "\nSend the transaction\n" + | ||||
HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")}, | HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()}); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()}); | ||||
// parse hex string from parameter | // parse hex string from parameter | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
if (!DecodeHexTx(tx, request.params[0].get_str())) { | if (!DecodeHexTx(tx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
Show All 11 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
result.pushKV("fee", ValueFromAmount(fee)); | result.pushKV("fee", ValueFromAmount(fee)); | ||||
result.pushKV("changepos", change_position); | result.pushKV("changepos", change_position); | ||||
return result; | return result; | ||||
} | } | ||||
UniValue signrawtransactionwithwallet(const Config &config, | UniValue signrawtransactionwithwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
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" + | ||||
HELP_REQUIRING_PASSPHRASE, | HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{ | RPCExamples{ | ||||
HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + | HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + | ||||
HelpExampleRpc("signrawtransactionwithwallet", "\"myhex\"")}, | HelpExampleRpc("signrawtransactionwithwallet", "\"myhex\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCTypeCheck(request.params, | RPCTypeCheck(request.params, | ||||
{UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); | {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
Show All 24 Lines | UniValue signrawtransactionwithwallet(const Config &config, | ||||
bool complete = | bool complete = | ||||
pwallet->SignTransaction(mtx, coins, nHashType, input_errors); | pwallet->SignTransaction(mtx, coins, nHashType, input_errors); | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result); | SignTransactionResultToJSON(mtx, complete, coins, input_errors, result); | ||||
return result; | return result; | ||||
} | } | ||||
UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"rescanblockchain", | "rescanblockchain", | ||||
"Rescan the local blockchain for wallet related transactions.\n" | "Rescan the local blockchain for wallet related transactions.\n" | ||||
"Note: Use \"getwalletinfo\" to query the scanning progress.\n", | "Note: Use \"getwalletinfo\" to query the scanning progress.\n", | ||||
{ | { | ||||
{"start_height", RPCArg::Type::NUM, /* default */ "0", | {"start_height", RPCArg::Type::NUM, /* default */ "0", | ||||
"block height where the rescan should start"}, | "block height where the rescan should start"}, | ||||
{"stop_height", RPCArg::Type::NUM, | {"stop_height", RPCArg::Type::NUM, | ||||
Show All 13 Lines | RPCHelpMan{ | ||||
"cases if there was a reorg and the call didn't scan any " | "cases if there was a reorg and the call didn't scan any " | ||||
"blocks because they were already scanned in the background."}, | "blocks because they were already scanned in the background."}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("rescanblockchain", "100000 120000") + | RPCExamples{HelpExampleCli("rescanblockchain", "100000 120000") + | ||||
HelpExampleRpc("rescanblockchain", "100000, 120000")}, | HelpExampleRpc("rescanblockchain", "100000, 120000")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
WalletRescanReserver reserver(*pwallet); | WalletRescanReserver reserver(*pwallet); | ||||
if (!reserver.reserve()) { | if (!reserver.reserve()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Wallet is currently rescanning. Abort existing rescan or wait."); | "Wallet is currently rescanning. Abort existing rescan or wait."); | ||||
} | } | ||||
int start_height = 0; | int start_height = 0; | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | static UniValue AddressBookDataToJSON(const CAddressBookData &data, | ||||
if (verbose) { | if (verbose) { | ||||
ret.pushKV("name", data.GetLabel()); | ret.pushKV("name", data.GetLabel()); | ||||
} | } | ||||
ret.pushKV("purpose", data.purpose); | ret.pushKV("purpose", data.purpose); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getaddressinfo", | "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 " | "Some of the information will only be present if the address is in the " | ||||
"active wallet.\n", | "active wallet.\n", | ||||
{ | { | ||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The bitcoin address for which to get information."}, | "The bitcoin address for which to get information."}, | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
}}, | }}, | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("getaddressinfo", EXAMPLE_ADDRESS) + | RPCExamples{HelpExampleCli("getaddressinfo", EXAMPLE_ADDRESS) + | ||||
HelpExampleRpc("getaddressinfo", EXAMPLE_ADDRESS)}, | HelpExampleRpc("getaddressinfo", EXAMPLE_ADDRESS)}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
CTxDestination dest = DecodeDestination(request.params[0].get_str(), | CTxDestination dest = DecodeDestination(request.params[0].get_str(), | ||||
wallet->GetChainParams()); | wallet->GetChainParams()); | ||||
// Make sure the destination is valid | // Make sure the destination is valid | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
ret.pushKV("labels", std::move(labels)); | ret.pushKV("labels", std::move(labels)); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getaddressesbylabel(const Config &config, | UniValue getaddressesbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getaddressesbylabel", | "getaddressesbylabel", | ||||
"Returns the list of addresses assigned the specified label.\n", | "Returns the list of addresses assigned the specified label.\n", | ||||
{ | { | ||||
{"label", RPCArg::Type::STR, RPCArg::Optional::NO, "The label."}, | {"label", RPCArg::Type::STR, RPCArg::Optional::NO, "The label."}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::OBJ_DYN, | RPCResult{RPCResult::Type::OBJ_DYN, | ||||
"", | "", | ||||
"json object with addresses as keys", | "json object with addresses as keys", | ||||
{ | { | ||||
{RPCResult::Type::OBJ, | {RPCResult::Type::OBJ, | ||||
"address", | "address", | ||||
"Information about address", | "Information about address", | ||||
{ | { | ||||
{RPCResult::Type::STR, "purpose", | {RPCResult::Type::STR, "purpose", | ||||
"Purpose of address (\"send\" for sending address, " | "Purpose of address (\"send\" for sending address, " | ||||
"\"receive\" for receiving address)"}, | "\"receive\" for receiving address)"}, | ||||
}}, | }}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("getaddressesbylabel", "\"tabby\"") + | RPCExamples{HelpExampleCli("getaddressesbylabel", "\"tabby\"") + | ||||
HelpExampleRpc("getaddressesbylabel", "\"tabby\"")}, | HelpExampleRpc("getaddressesbylabel", "\"tabby\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
// Find all addresses that have the given label | // Find all addresses that have the given label | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
std::set<std::string> addresses; | std::set<std::string> addresses; | ||||
for (const std::pair<const CTxDestination, CAddressBookData> &item : | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
Show All 20 Lines | if (ret.empty()) { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | ||||
std::string("No addresses with label " + label)); | std::string("No addresses with label " + label)); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue listlabels(const Config &config, const JSONRPCRequest &request) { | UniValue listlabels(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"listlabels", | "listlabels", | ||||
"Returns the list of all labels, or labels that are assigned to " | "Returns the list of all labels, or labels that are assigned to " | ||||
"addresses with a specific purpose.\n", | "addresses with a specific purpose.\n", | ||||
{ | { | ||||
{"purpose", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, | {"purpose", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, | ||||
"Address purpose to list labels for ('send','receive'). An empty " | "Address purpose to list labels for ('send','receive'). An empty " | ||||
"string is the same as not providing this argument."}, | "string is the same as not providing this argument."}, | ||||
Show All 9 Lines | RPCHelpMan{ | ||||
HelpExampleCli("listlabels", "receive") + | HelpExampleCli("listlabels", "receive") + | ||||
"\nList labels that have sending addresses\n" + | "\nList labels that have sending addresses\n" + | ||||
HelpExampleCli("listlabels", "send") + | HelpExampleCli("listlabels", "send") + | ||||
"\nAs a JSON-RPC call\n" + | "\nAs a JSON-RPC call\n" + | ||||
HelpExampleRpc("listlabels", "receive")}, | HelpExampleRpc("listlabels", "receive")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::string purpose; | std::string purpose; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
purpose = request.params[0].get_str(); | purpose = request.params[0].get_str(); | ||||
} | } | ||||
// Add to a set to sort by label name, then insert into Univalue array | // Add to a set to sort by label name, then insert into Univalue array | ||||
Show All 12 Lines | UniValue listlabels(const Config &config, const JSONRPCRequest &request) { | ||||
for (const std::string &name : label_set) { | for (const std::string &name : label_set) { | ||||
ret.push_back(name); | ret.push_back(name); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
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" + | ||||
Show All 19 Lines | RPCHelpMan{ | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("sethdseed", "") + | RPCExamples{HelpExampleCli("sethdseed", "") + | ||||
HelpExampleCli("sethdseed", "false") + | HelpExampleCli("sethdseed", "false") + | ||||
HelpExampleCli("sethdseed", "true \"wifkey\"") + | HelpExampleCli("sethdseed", "true \"wifkey\"") + | ||||
HelpExampleRpc("sethdseed", "true, \"wifkey\"")}, | HelpExampleRpc("sethdseed", "true, \"wifkey\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
LegacyScriptPubKeyMan &spk_man = | LegacyScriptPubKeyMan &spk_man = | ||||
EnsureLegacyScriptPubKeyMan(*pwallet, true); | EnsureLegacyScriptPubKeyMan(*pwallet, true); | ||||
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"Cannot set a HD seed to a wallet with private keys disabled"); | "Cannot set a HD seed to a wallet with private keys disabled"); | ||||
} | } | ||||
Show All 39 Lines | if (flush_key_pool) { | ||||
spk_man.NewKeyPool(); | spk_man.NewKeyPool(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue walletprocesspsbt(const Config &config, | static UniValue walletprocesspsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
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." + | ||||
HELP_REQUIRING_PASSPHRASE, | 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"}, | ||||
Show All 20 Lines | RPCHelpMan{ | ||||
"The base64-encoded partially signed transaction"}, | "The base64-encoded partially signed transaction"}, | ||||
{RPCResult::Type::BOOL, "complete", | {RPCResult::Type::BOOL, "complete", | ||||
"If the transaction has a complete set of signatures"}, | "If the transaction has a complete set of signatures"}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("walletprocesspsbt", "\"psbt\"")}, | RPCExamples{HelpExampleCli("walletprocesspsbt", "\"psbt\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
const CWallet *const pwallet = wallet.get(); | |||||
RPCTypeCheck(request.params, | RPCTypeCheck(request.params, | ||||
{UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR}); | {UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR}); | ||||
// Unserialize the transaction | // Unserialize the transaction | ||||
PartiallySignedTransaction psbtx; | PartiallySignedTransaction psbtx; | ||||
std::string error; | std::string error; | ||||
if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) { | if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
Show All 25 Lines | static UniValue walletprocesspsbt(const Config &config, | ||||
result.pushKV("psbt", EncodeBase64(ssTx.str())); | result.pushKV("psbt", EncodeBase64(ssTx.str())); | ||||
result.pushKV("complete", complete); | result.pushKV("complete", complete); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue walletcreatefundedpsbt(const Config &config, | static UniValue walletcreatefundedpsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"walletcreatefundedpsbt", | "walletcreatefundedpsbt", | ||||
"Creates and funds a transaction in the Partially Signed Transaction " | "Creates and funds a transaction in the Partially Signed Transaction " | ||||
"format.\n" | "format.\n" | ||||
"Implements the Creator and Updater roles.\n", | "Implements the Creator and Updater roles.\n", | ||||
{ | { | ||||
{ | { | ||||
"inputs", | "inputs", | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
RPCExamples{ | RPCExamples{ | ||||
"\nCreate a transaction with no inputs\n" + | "\nCreate a transaction with no inputs\n" + | ||||
HelpExampleCli("walletcreatefundedpsbt", | HelpExampleCli("walletcreatefundedpsbt", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | ||||
"\"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, | "\"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCTypeCheck(request.params, | RPCTypeCheck(request.params, | ||||
{UniValue::VARR, | {UniValue::VARR, | ||||
UniValueType(), // ARR or OBJ, checked later | UniValueType(), // ARR or OBJ, checked later | ||||
UniValue::VNUM, UniValue::VOBJ}, | UniValue::VNUM, UniValue::VOBJ}, | ||||
true); | true); | ||||
Amount fee; | Amount fee; | ||||
int change_position; | int change_position; | ||||
Show All 28 Lines | static UniValue walletcreatefundedpsbt(const Config &config, | ||||
result.pushKV("psbt", EncodeBase64(ssTx.str())); | result.pushKV("psbt", EncodeBase64(ssTx.str())); | ||||
result.pushKV("fee", ValueFromAmount(fee)); | result.pushKV("fee", ValueFromAmount(fee)); | ||||
result.pushKV("changepos", change_position); | result.pushKV("changepos", change_position); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue upgradewallet(const Config &config, | static UniValue upgradewallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCHelpMan{"upgradewallet", | RPCHelpMan{"upgradewallet", | ||||
"\nUpgrade the wallet. Upgrades to the latest version if no " | "\nUpgrade the wallet. Upgrades to the latest version if no " | ||||
"version number is specified\n" | "version number is specified\n" | ||||
"New keys may be generated and a new wallet backup will need to " | "New keys may be generated and a new wallet backup will need to " | ||||
"be made.", | "be made.", | ||||
{{"version", RPCArg::Type::NUM, | {{"version", RPCArg::Type::NUM, | ||||
/* default */ strprintf("%d", FEATURE_LATEST), | /* default */ strprintf("%d", FEATURE_LATEST), | ||||
"The version number to upgrade to. Default is the latest " | "The version number to upgrade to. Default is the latest " | ||||
"wallet version"}}, | "wallet version"}}, | ||||
RPCResult{RPCResult::Type::NONE, "", ""}, | RPCResult{RPCResult::Type::NONE, "", ""}, | ||||
RPCExamples{HelpExampleCli("upgradewallet", "200300") + | RPCExamples{HelpExampleCli("upgradewallet", "200300") + | ||||
HelpExampleRpc("upgradewallet", "200300")}} | HelpExampleRpc("upgradewallet", "200300")}} | ||||
.Check(request); | .Check(request); | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
RPCTypeCheck(request.params, {UniValue::VNUM}, true); | RPCTypeCheck(request.params, {UniValue::VNUM}, true); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
int version = 0; | int version = 0; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
version = request.params[0].get_int(); | version = request.params[0].get_int(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |