Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (!urlEncoded.empty()) { | ||||
if (decoded) { | if (decoded) { | ||||
res = std::string(decoded); | res = std::string(decoded); | ||||
free(decoded); | free(decoded); | ||||
} | } | ||||
} | } | ||||
return res; | return res; | ||||
} | } | ||||
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | std::shared_ptr<CWallet> | ||||
GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | |||||
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | ||||
WALLET_ENDPOINT_BASE) { | WALLET_ENDPOINT_BASE) { | ||||
// wallet endpoint was used | // wallet endpoint was used | ||||
std::string requestedWallet = | std::string requestedWallet = | ||||
urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); | urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); | ||||
CWallet *pwallet = GetWallet(requestedWallet); | std::shared_ptr<CWallet> pwallet = GetWallet(requestedWallet); | ||||
if (!pwallet) { | if (!pwallet) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_NOT_FOUND, | RPC_WALLET_NOT_FOUND, | ||||
"Requested wallet does not exist or is not loaded"); | "Requested wallet does not exist or is not loaded"); | ||||
} | } | ||||
return pwallet; | return pwallet; | ||||
} | } | ||||
std::vector<CWallet *> wallets = GetWallets(); | std::vector<std::shared_ptr<CWallet>> wallets = GetWallets(); | ||||
return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) | return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) | ||||
? wallets[0] | ? wallets[0] | ||||
: nullptr; | : nullptr; | ||||
} | } | ||||
std::string HelpRequiringPassphrase(CWallet *const pwallet) { | std::string HelpRequiringPassphrase(CWallet *const pwallet) { | ||||
return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | ||||
"be set with walletpassphrase " | "be set with walletpassphrase " | ||||
▲ Show 20 Lines • Show All 67 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getnewaddress ( \"label\" )\n" | "getnewaddress ( \"label\" )\n" | ||||
"\nReturns a new Bitcoin address for receiving payments.\n" | "\nReturns a new Bitcoin address for receiving payments.\n" | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (!pwallet->GetLabelDestination(dest, label, bForceNew)) { | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
return dest; | return dest; | ||||
} | } | ||||
static UniValue getlabeladdress(const Config &config, | static UniValue getlabeladdress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getlabeladdress \"label\"\n" | "getlabeladdress \"label\"\n" | ||||
"\nReturns the current Bitcoin address for receiving payments to " | "\nReturns the current Bitcoin address for receiving payments to " | ||||
Show All 20 Lines | static UniValue getlabeladdress(const Config &config, | ||||
UniValue ret(UniValue::VSTR); | UniValue ret(UniValue::VSTR); | ||||
ret = EncodeDestination(GetLabelDestination(pwallet, label), config); | ret = EncodeDestination(GetLabelDestination(pwallet, label), config); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getrawchangeaddress(const Config &config, | static UniValue getrawchangeaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getrawchangeaddress\n" | "getrawchangeaddress\n" | ||||
"\nReturns a new Bitcoin address, for receiving change.\n" | "\nReturns a new Bitcoin address, for receiving change.\n" | ||||
Show All 35 Lines | static UniValue getrawchangeaddress(const Config &config, | ||||
pwallet->LearnRelatedScripts(vchPubKey, output_type); | pwallet->LearnRelatedScripts(vchPubKey, output_type); | ||||
CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); | CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); | ||||
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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"setlabel \"address\" \"label\"\n" | "setlabel \"address\" \"label\"\n" | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (IsMine(*pwallet, dest)) { | ||||
"setlabel can only be used with own address"); | "setlabel can only be used with own address"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue getaccount(const Config &config, | static UniValue getaccount(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getaccount \"address\"\n" | "getaccount \"address\"\n" | ||||
"\nDEPRECATED. Returns the account associated with the given " | "\nDEPRECATED. Returns the account associated with the given " | ||||
Show All 26 Lines | if (mi != pwallet->mapAddressBook.end() && !(*mi).second.name.empty()) { | ||||
strAccount = (*mi).second.name; | strAccount = (*mi).second.name; | ||||
} | } | ||||
return strAccount; | return strAccount; | ||||
} | } | ||||
static UniValue getaddressesbyaccount(const Config &config, | static UniValue getaddressesbyaccount(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getaddressesbyaccount \"account\"\n" | "getaddressesbyaccount \"account\"\n" | ||||
"\nDEPRECATED. Returns the list of addresses for the given " | "\nDEPRECATED. Returns the list of addresses for the given " | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strError); | throw JSONRPCError(RPC_WALLET_ERROR, strError); | ||||
} | } | ||||
return tx; | return tx; | ||||
} | } | ||||
static UniValue sendtoaddress(const Config &config, | static UniValue sendtoaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" " | "sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" " | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | static UniValue sendtoaddress(const Config &config, | ||||
CTransactionRef tx = | CTransactionRef tx = | ||||
SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, | SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, | ||||
std::move(mapValue), {} /* fromAccount */); | std::move(mapValue), {} /* fromAccount */); | ||||
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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listaddressgroupings\n" | "listaddressgroupings\n" | ||||
"\nLists groups of addresses which have had their common " | "\nLists groups of addresses which have had their common " | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 2) { | if (request.fHelp || request.params.size() != 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"signmessage \"address\" \"message\"\n" | "signmessage \"address\" \"message\"\n" | ||||
"\nSign a message with the private key of an address" + | "\nSign a message with the private key of an address" + | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (!key.SignCompact(ss.GetHash(), vchSig)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); | ||||
} | } | ||||
return EncodeBase64(vchSig.data(), vchSig.size()); | return EncodeBase64(vchSig.data(), vchSig.size()); | ||||
} | } | ||||
static UniValue getreceivedbyaddress(const Config &config, | static UniValue getreceivedbyaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getreceivedbyaddress \"address\" ( minconf )\n" | "getreceivedbyaddress \"address\" ( minconf )\n" | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
} | } | ||||
} | } | ||||
return ValueFromAmount(nAmount); | return ValueFromAmount(nAmount); | ||||
} | } | ||||
static UniValue getreceivedbylabel(const Config &config, | static UniValue getreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getreceivedbylabel \"label\" ( minconf )\n" | "getreceivedbylabel \"label\" ( minconf )\n" | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
} | } | ||||
} | } | ||||
return ValueFromAmount(nAmount); | return ValueFromAmount(nAmount); | ||||
} | } | ||||
static UniValue getbalance(const Config &config, | static UniValue getbalance(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 3) { | if (request.fHelp || request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getbalance ( \"account\" minconf include_watchonly )\n" | "getbalance ( \"account\" minconf include_watchonly )\n" | ||||
"\nIf account is not specified, returns the server's total " | "\nIf account is not specified, returns the server's total " | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | static UniValue getbalance(const Config &config, | ||||
} | } | ||||
return ValueFromAmount( | return ValueFromAmount( | ||||
pwallet->GetLegacyBalance(filter, nMinDepth, account)); | pwallet->GetLegacyBalance(filter, nMinDepth, account)); | ||||
} | } | ||||
static UniValue getunconfirmedbalance(const Config &config, | static UniValue getunconfirmedbalance(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getunconfirmedbalance\n" | "getunconfirmedbalance\n" | ||||
"Returns the server's total unconfirmed balance\n"); | "Returns the server's total unconfirmed balance\n"); | ||||
} | } | ||||
// 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(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | return ValueFromAmount(pwallet->GetUnconfirmedBalance()); | ||||
} | } | ||||
static UniValue movecmd(const Config &config, const JSONRPCRequest &request) { | static UniValue movecmd(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 3 || | if (request.fHelp || request.params.size() < 3 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" " | "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" " | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static UniValue movecmd(const Config &config, const JSONRPCRequest &request) { | ||||
if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) { | if (!pwallet->AccountMove(strFrom, strTo, nAmount, strComment)) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); | throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static UniValue sendfrom(const Config &config, const JSONRPCRequest &request) { | static UniValue sendfrom(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 3 || | if (request.fHelp || request.params.size() < 3 || | ||||
request.params.size() > 6) { | request.params.size() > 6) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"sendfrom \"fromaccount\" \"toaddress\" amount ( minconf " | "sendfrom \"fromaccount\" \"toaddress\" amount ( minconf " | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | static UniValue sendfrom(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
CTransactionRef tx = SendMoney(pwallet, dest, nAmount, false, | CTransactionRef tx = SendMoney(pwallet, dest, nAmount, false, | ||||
std::move(mapValue), std::move(label)); | std::move(mapValue), std::move(label)); | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 5) { | request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"sendmany \"fromaccount\" {\"address\":amount,...} ( minconf " | "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf " | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
std::string msg = | std::string msg = | ||||
"addmultisigaddress nrequired [\"key\",...] ( \"label\" )\n" | "addmultisigaddress nrequired [\"key\",...] ( \"label\" )\n" | ||||
▲ Show 20 Lines • Show All 243 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 4) { | if (request.fHelp || request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listreceivedbyaddress ( minconf include_empty include_watchonly " | "listreceivedbyaddress ( minconf include_empty include_watchonly " | ||||
"address_filter )\n" | "address_filter )\n" | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | static UniValue listreceivedbyaddress(const Config &config, | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 3) { | if (request.fHelp || request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listreceivedbylabel ( minconf include_empty include_watchonly)\n" | "listreceivedbylabel ( minconf include_empty include_watchonly)\n" | ||||
"\nList received transactions by label.\n" | "\nList received transactions by label.\n" | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | if (fAllAccounts || acentry.strAccount == strAccount) { | ||||
entry.pushKV("otheraccount", acentry.strOtherAccount); | entry.pushKV("otheraccount", acentry.strOtherAccount); | ||||
entry.pushKV("comment", acentry.strComment); | entry.pushKV("comment", acentry.strComment); | ||||
ret.push_back(entry); | ret.push_back(entry); | ||||
} | } | ||||
} | } | ||||
static UniValue listtransactions(const Config &config, | static UniValue listtransactions(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 4) { | if (request.fHelp || request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listtransactions ( \"account\" count skip include_watchonly)\n" | "listtransactions ( \"account\" count skip include_watchonly)\n" | ||||
"\nReturns up to 'count' most recent transactions skipping the " | "\nReturns up to 'count' most recent transactions skipping the " | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | static UniValue listtransactions(const Config &config, | ||||
ret.setArray(); | ret.setArray(); | ||||
ret.push_backV(arrTmp); | ret.push_backV(arrTmp); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listaccounts(const Config &config, | static UniValue listaccounts(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listaccounts ( minconf include_watchonly)\n" | "listaccounts ( minconf include_watchonly)\n" | ||||
"\nDEPRECATED. Returns Object that has account names as keys, " | "\nDEPRECATED. Returns Object that has account names as keys, " | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | for (const std::pair<const std::string, Amount> &accountBalance : | ||||
ret.pushKV(accountBalance.first, | ret.pushKV(accountBalance.first, | ||||
ValueFromAmount(accountBalance.second)); | ValueFromAmount(accountBalance.second)); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listsinceblock(const Config &config, | static UniValue listsinceblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 4) { | if (request.fHelp || request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listsinceblock ( \"blockhash\" target_confirmations " | "listsinceblock ( \"blockhash\" target_confirmations " | ||||
"include_watchonly include_removed )\n" | "include_watchonly include_removed )\n" | ||||
▲ Show 20 Lines • Show All 191 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"gettransaction \"txid\" ( include_watchonly )\n" | "gettransaction \"txid\" ( include_watchonly )\n" | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static UniValue gettransaction(const Config &config, | ||||
std::string strHex = EncodeHexTx(*wtx.tx, RPCSerializationFlags()); | std::string strHex = EncodeHexTx(*wtx.tx, RPCSerializationFlags()); | ||||
entry.pushKV("hex", strHex); | entry.pushKV("hex", strHex); | ||||
return entry; | return entry; | ||||
} | } | ||||
static UniValue abandontransaction(const Config &config, | static UniValue abandontransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"abandontransaction \"txid\"\n" | "abandontransaction \"txid\"\n" | ||||
"\nMark in-wallet transaction <txid> as abandoned\n" | "\nMark in-wallet transaction <txid> as abandoned\n" | ||||
Show All 35 Lines | if (!pwallet->AbandonTransaction(txid)) { | ||||
"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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"backupwallet \"destination\"\n" | "backupwallet \"destination\"\n" | ||||
"\nSafely copies current wallet file to destination, which can be " | "\nSafely copies current wallet file to destination, which can be " | ||||
Show All 16 Lines | 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"keypoolrefill ( newsize )\n" | "keypoolrefill ( newsize )\n" | ||||
"\nFills the keypool." + | "\nFills the keypool." + | ||||
Show All 33 Lines | |||||
static void LockWallet(CWallet *pWallet) { | static void LockWallet(CWallet *pWallet) { | ||||
LOCK(pWallet->cs_wallet); | LOCK(pWallet->cs_wallet); | ||||
pWallet->nRelockTime = 0; | pWallet->nRelockTime = 0; | ||||
pWallet->Lock(); | pWallet->Lock(); | ||||
} | } | ||||
static UniValue walletpassphrase(const Config &config, | static UniValue walletpassphrase(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"walletpassphrase \"passphrase\" timeout\n" | "walletpassphrase \"passphrase\" timeout\n" | ||||
"\nStores the wallet decryption key in memory for 'timeout' " | "\nStores the wallet decryption key in memory for 'timeout' " | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | static UniValue walletpassphrase(const Config &config, | ||||
RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), | RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), | ||||
std::bind(LockWallet, pwallet), nSleepTime); | std::bind(LockWallet, pwallet), nSleepTime); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue walletpassphrasechange(const Config &config, | static UniValue walletpassphrasechange(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 2)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" | "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" | ||||
"\nChanges the wallet passphrase from 'oldpassphrase' to " | "\nChanges the wallet passphrase from 'oldpassphrase' to " | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { | if (pwallet->IsCrypted() && (request.fHelp || request.params.size() != 0)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"walletlock\n" | "walletlock\n" | ||||
"\nRemoves the wallet encryption key from memory, locking the " | "\nRemoves the wallet encryption key from memory, locking the " | ||||
Show All 28 Lines | static UniValue walletlock(const Config &config, | ||||
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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (!pwallet->IsCrypted() && | if (!pwallet->IsCrypted() && | ||||
(request.fHelp || request.params.size() != 1)) { | (request.fHelp || request.params.size() != 1)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"encryptwallet \"passphrase\"\n" | "encryptwallet \"passphrase\"\n" | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static UniValue encryptwallet(const Config &config, | ||||
return "wallet encrypted; Bitcoin server stopping, restart to run with " | return "wallet encrypted; Bitcoin server stopping, restart to run with " | ||||
"encrypted wallet. The keypool has been flushed and a new HD seed " | "encrypted wallet. 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n" | "lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n" | ||||
▲ Show 20 Lines • Show All 141 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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listlockunspent\n" | "listlockunspent\n" | ||||
"\nReturns list of temporarily unspendable outputs.\n" | "\nReturns list of temporarily unspendable outputs.\n" | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | for (COutPoint &output : vOutpts) { | ||||
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) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 1) { | request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"settxfee amount\n" | "settxfee amount\n" | ||||
Show All 16 Lines | static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | ||||
Amount nAmount = AmountFromValue(request.params[0]); | Amount nAmount = AmountFromValue(request.params[0]); | ||||
pwallet->m_pay_tx_fee = CFeeRate(nAmount, 1000); | pwallet->m_pay_tx_fee = CFeeRate(nAmount, 1000); | ||||
return true; | return true; | ||||
} | } | ||||
static UniValue getwalletinfo(const Config &config, | static UniValue getwalletinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getwalletinfo\n" | "getwalletinfo\n" | ||||
"Returns an object containing various wallet state info.\n" | "Returns an object containing various wallet state info.\n" | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("listwallets", "") + | HelpExampleCli("listwallets", "") + | ||||
HelpExampleRpc("listwallets", "")); | HelpExampleRpc("listwallets", "")); | ||||
} | } | ||||
UniValue obj(UniValue::VARR); | UniValue obj(UniValue::VARR); | ||||
for (CWallet *pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &wallet : GetWallets()) { | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(wallet.get(), request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
obj.push_back(pwallet->GetName()); | obj.push_back(wallet->GetName()); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
UniValue loadwallet(const Config &config, const JSONRPCRequest &request) { | UniValue loadwallet(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
Show All 30 Lines | UniValue loadwallet(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
std::string warning; | std::string warning; | ||||
if (!CWallet::Verify(chainParams, wallet_file, false, error, warning)) { | if (!CWallet::Verify(chainParams, wallet_file, false, error, warning)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet file verification failed: " + error); | "Wallet file verification failed: " + error); | ||||
} | } | ||||
CWallet *const wallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | ||||
chainParams, wallet_file, fs::absolute(wallet_file, GetWalletDir())); | chainParams, wallet_file, fs::absolute(wallet_file, GetWalletDir())); | ||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed."); | throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed."); | ||||
} | } | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->postInitProcess(); | wallet->postInitProcess(); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue resendwallettransactions(const Config &config, | static UniValue resendwallettransactions(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"resendwallettransactions\n" | "resendwallettransactions\n" | ||||
"Immediately re-broadcast unconfirmed wallet transactions to all " | "Immediately re-broadcast unconfirmed wallet transactions to all " | ||||
Show All 26 Lines | for (const uint256 &txid : txids) { | ||||
result.push_back(txid.ToString()); | result.push_back(txid.ToString()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue listunspent(const Config &config, | static UniValue listunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 5) { | if (request.fHelp || request.params.size() > 5) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listunspent ( minconf maxconf [\"addresses\",...] " | "listunspent ( minconf maxconf [\"addresses\",...] " | ||||
"[include_unsafe] [query_options])\n" | "[include_unsafe] [query_options])\n" | ||||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
results.push_back(entry); | results.push_back(entry); | ||||
} | } | ||||
return results; | return results; | ||||
} | } | ||||
static UniValue fundrawtransaction(const Config &config, | static UniValue fundrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"fundrawtransaction \"hexstring\" ( options )\n" | "fundrawtransaction \"hexstring\" ( options )\n" | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | static UniValue fundrawtransaction(const Config &config, | ||||
result.pushKV("changepos", changePosition); | result.pushKV("changepos", changePosition); | ||||
result.pushKV("fee", ValueFromAmount(nFeeOut)); | result.pushKV("fee", ValueFromAmount(nFeeOut)); | ||||
return result; | return result; | ||||
} | } | ||||
UniValue signrawtransactionwithwallet(const Config &config, | UniValue signrawtransactionwithwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"signrawtransactionwithwallet \"hexstring\" ( " | "signrawtransactionwithwallet \"hexstring\" ( " | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | UniValue signrawtransactionwithwallet(const Config &config, | ||||
// Sign the transaction | // Sign the transaction | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
return SignTransaction(mtx, request.params[1], pwallet, false, | return SignTransaction(mtx, request.params[1], pwallet, false, | ||||
request.params[2]); | request.params[2]); | ||||
} | } | ||||
static UniValue generate(const Config &config, const JSONRPCRequest &request) { | static UniValue generate(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
Show All 33 Lines | if (coinbase_script->reserveScript.empty()) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); | ||||
} | } | ||||
return generateBlocks(config, coinbase_script, num_generate, max_tries, | return generateBlocks(config, coinbase_script, num_generate, max_tries, | ||||
true); | true); | ||||
} | } | ||||
UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"rescanblockchain (\"start_height\") (\"stop_height\")\n" | "rescanblockchain (\"start_height\") (\"stop_height\")\n" | ||||
"\nRescan the local blockchain for wallet related transactions.\n" | "\nRescan the local blockchain for wallet related transactions.\n" | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | static UniValue DescribeWalletAddress(CWallet *pwallet, | ||||
UniValue detail = DescribeAddress(dest); | UniValue detail = DescribeAddress(dest); | ||||
ret.pushKVs(detail); | ret.pushKVs(detail); | ||||
ret.pushKVs( | ret.pushKVs( | ||||
boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest)); | boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest)); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | UniValue getaddressinfo(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | |||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getaddressinfo \"address\"\n" | "getaddressinfo \"address\"\n" | ||||
"\nReturn information about the given bitcoin address. Some " | "\nReturn information about the given bitcoin address. Some " | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |