Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
entry.pushKV("time", wtx.GetTxTime()); | entry.pushKV("time", wtx.GetTxTime()); | ||||
entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | entry.pushKV("timereceived", (int64_t)wtx.nTimeReceived); | ||||
for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | ||||
entry.pushKV(item.first, item.second); | entry.pushKV(item.first, item.second); | ||||
} | } | ||||
} | } | ||||
std::string AccountFromValue(const UniValue &value) { | std::string LabelFromValue(const UniValue &value) { | ||||
std::string strAccount = value.get_str(); | std::string label = value.get_str(); | ||||
if (strAccount == "*") { | if (label == "*") { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name"); | ||||
"Invalid account name"); | |||||
} | } | ||||
return strAccount; | 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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
"getnewaddress ( \"account\" )\n" | "getnewaddress ( \"label\" )\n" | ||||
"\nReturns a new Bitcoin address for receiving payments.\n" | "\nReturns a new Bitcoin address for receiving payments.\n" | ||||
"If 'account' is specified (DEPRECATED), it is added to the " | "If 'label' is specified, it is added to the address book \n" | ||||
"address book \n" | "so payments received with the address will be associated with " | ||||
"so payments received with the address will be credited to " | "'label'.\n" | ||||
"'account'.\n" | "\nArguments:\n" | ||||
"\nArguments:\n" | "1. \"label\" (string, optional) The label name for the " | ||||
"1. \"account\" (string, optional) DEPRECATED. The account " | "address to be linked to. If not provided, the default label \"\" " | ||||
"name for the address to be linked to. If not provided, the " | "is used. It can also be set to the empty string \"\" to represent " | ||||
"default account \"\" is used. It can also be set to the empty " | "the default label. The label does not need to exist, it will be " | ||||
"string \"\" to represent the default account. The account does " | "created if there is no label by the given name.\n" | ||||
"not need to exist, it will be created if there is no account by " | |||||
"the given name.\n" | |||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The new bitcoin address\n" | "\"address\" (string) The new bitcoin address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getnewaddress", "") + | |||||
HelpExampleRpc("getnewaddress", "")); | HelpExampleRpc("getnewaddress", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Parse the account first so we don't generate a key if there's an error | // Parse the account first so we don't generate a key if there's an error | ||||
std::string strAccount; | std::string label; | ||||
if (request.params.size() > 0) { | if (request.params.size() > 0) { | ||||
strAccount = AccountFromValue(request.params[0]); | label = LabelFromValue(request.params[0]); | ||||
} | } | ||||
if (!pwallet->IsLocked()) { | if (!pwallet->IsLocked()) { | ||||
pwallet->TopUpKeyPool(); | pwallet->TopUpKeyPool(); | ||||
} | } | ||||
// Generate a new key that is added to wallet | // Generate a new key that is added to wallet | ||||
CPubKey newKey; | CPubKey newKey; | ||||
if (!pwallet->GetKeyFromPool(newKey)) { | if (!pwallet->GetKeyFromPool(newKey)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
CKeyID keyID = newKey.GetID(); | CKeyID keyID = newKey.GetID(); | ||||
pwallet->SetAddressBook(keyID, strAccount, "receive"); | pwallet->SetAddressBook(keyID, label, "receive"); | ||||
return EncodeDestination(keyID); | return EncodeDestination(keyID); | ||||
} | } | ||||
CTxDestination GetAccountAddress(CWallet *const pwallet, std::string strAccount, | CTxDestination GetLabelAddress(CWallet *const pwallet, const std::string &label, | ||||
bool bForceNew = false) { | bool bForceNew = false) { | ||||
CPubKey pubKey; | CPubKey pubKey; | ||||
if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) { | if (!pwallet->GetLabelAddress(pubKey, label, bForceNew)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
return pubKey.GetID(); | return pubKey.GetID(); | ||||
} | } | ||||
static UniValue getaccountaddress(const Config &config, | UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { | ||||
const JSONRPCRequest &request) { | |||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
"getaccountaddress \"account\"\n" | "getlabeladdress \"label\"\n" | ||||
"\nDEPRECATED. Returns the current Bitcoin address for receiving " | "\nReturns the current Bitcoin address for receiving payments to " | ||||
"payments to this account.\n" | "this label.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"account\" (string, required) The account name for the " | "1. \"label\" (string, required) The label name for the " | ||||
"address. It can also be set to the empty string \"\" to represent " | "address. It can also be set to the empty string \"\" to represent " | ||||
"the default account. The account does not need to exist, it will " | "the default label. The label does not need to exist, it will be " | ||||
"be created and a new address created if there is no account by " | "created and a new address created if there is no label by the " | ||||
"the given name.\n" | "given name.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) The account bitcoin address\n" | "\"address\" (string) The label bitcoin address\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaccountaddress", "") + | HelpExampleCli("getlabeladdress", "") + | ||||
HelpExampleCli("getaccountaddress", "\"\"") + | HelpExampleCli("getlabeladdress", "\"\"") + | ||||
HelpExampleCli("getaccountaddress", "\"myaccount\"") + | HelpExampleCli("getlabeladdress", "\"mylabel\"") + | ||||
HelpExampleRpc("getaccountaddress", "\"myaccount\"")); | HelpExampleRpc("getlabeladdress", "\"mylabel\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Parse the account 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 | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
UniValue ret(UniValue::VSTR); | UniValue ret(UniValue::VSTR); | ||||
ret = EncodeDestination(GetAccountAddress(pwallet, strAccount)); | ret = EncodeDestination(GetLabelAddress(pwallet, label)); | ||||
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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
Show All 27 Lines | static UniValue getrawchangeaddress(const Config &config, | ||||
reservekey.KeepKey(); | reservekey.KeepKey(); | ||||
CKeyID keyID = vchPubKey.GetID(); | CKeyID keyID = vchPubKey.GetID(); | ||||
return EncodeDestination(keyID); | return EncodeDestination(keyID); | ||||
} | } | ||||
static UniValue setaccount(const Config &config, | UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | ||||
const JSONRPCRequest &request) { | |||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
"setaccount \"address\" \"account\"\n" | |||||
"\nDEPRECATED. Sets the account associated with the given " | "setlabel \"address\" \"label\"\n" | ||||
"address.\n" | "\nSets the label associated with the given address.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"address\" (string, required) The bitcoin address to " | "1. \"address\" (string, required) The bitcoin address to " | ||||
"be associated with an account.\n" | "be associated with a label.\n" | ||||
"2. \"account\" (string, required) The account to assign " | "2. \"label\" (string, required) The label to assign the " | ||||
"the address to.\n" | "address to.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("setaccount", | HelpExampleCli("setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"tabby\"") + | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"setaccount", | "setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); | ||||
// clang-format on | |||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
std::string strAccount; | std::string label; | ||||
if (request.params.size() > 1) { | if (!request.params[1].isNull()) { | ||||
strAccount = AccountFromValue(request.params[1]); | label = LabelFromValue(request.params[1]); | ||||
} | } | ||||
// Only add the account if the address is yours. | // Only add the label if the address is yours. | ||||
if (IsMine(*pwallet, dest)) { | if (IsMine(*pwallet, dest)) { | ||||
// Detect when changing the account of an address that is the 'unused | // Detect when changing the account of an address that is the 'unused | ||||
// current key' of another account: | // current key' of another account: | ||||
if (pwallet->mapAddressBook.count(dest)) { | if (pwallet->mapAddressBook.count(dest)) { | ||||
std::string strOldAccount = pwallet->mapAddressBook[dest].name; | std::string old_label = pwallet->mapAddressBook[dest].name; | ||||
if (dest == GetAccountAddress(pwallet, strOldAccount)) { | if (dest == GetLabelAddress(pwallet, old_label)) { | ||||
GetAccountAddress(pwallet, strOldAccount, true); | GetLabelAddress(pwallet, old_label, true); | ||||
} | } | ||||
} | } | ||||
pwallet->SetAddressBook(dest, strAccount, "receive"); | pwallet->SetAddressBook(dest, label, "receive"); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_MISC_ERROR, | throw JSONRPCError(RPC_MISC_ERROR, | ||||
"setaccount 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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getaddressesbyaccount", "\"tabby\"") + | HelpExampleCli("getaddressesbyaccount", "\"tabby\"") + | ||||
HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")); | HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string strAccount = LabelFromValue(request.params[0]); | ||||
// Find all addresses that have the given account | // Find all addresses that have the given account | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const std::pair<CTxDestination, CAddressBookData> &item : | for (const std::pair<CTxDestination, CAddressBookData> &item : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
const CTxDestination &dest = item.first; | const CTxDestination &dest = item.first; | ||||
const std::string &strName = item.second.name; | const std::string &strName = item.second.name; | ||||
if (strName == strAccount) { | if (strName == strAccount) { | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | if (request.fHelp) { | ||||
"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" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" [\n" | " [\n" | ||||
" [\n" | " [\n" | ||||
" \"address\", (string) The bitcoin address\n" | " \"address\", (string) The bitcoin address\n" | ||||
" amount, (numeric) The amount in " + | " amount, (numeric) The amount in " + | ||||
CURRENCY_UNIT + "\n" | CURRENCY_UNIT + | ||||
" \"account\" (string, optional) " | "\n" | ||||
"DEPRECATED. The account\n" | " \"label\" (string, optional) The label\n" | ||||
" ]\n" | " ]\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("listaddressgroupings", "") + | HelpExampleCli("listaddressgroupings", "") + | ||||
HelpExampleRpc("listaddressgroupings", "")); | HelpExampleRpc("listaddressgroupings", "")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
UniValue jsonGroupings(UniValue::VARR); | UniValue jsonGroupings(UniValue::VARR); | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return ValueFromAmount(nAmount); | return ValueFromAmount(nAmount); | ||||
} | } | ||||
static UniValue getreceivedbyaccount(const Config &config, | UniValue getreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
"getreceivedbyaccount \"account\" ( minconf )\n" | "getreceivedbylabel \"label\" ( minconf )\n" | ||||
"\nDEPRECATED. Returns the total amount received by addresses with " | "\nReturns the total amount received by addresses with <label> in " | ||||
"<account> in transactions with at least [minconf] confirmations.\n" | "transactions with at least [minconf] confirmations.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"account\" (string, required) The selected account, may " | "1. \"label\" (string, required) The selected label, may be " | ||||
"be the default account using \"\".\n" | "the default label using \"\".\n" | ||||
"2. minconf (numeric, optional, default=1) Only include " | "2. minconf (numeric, optional, default=1) Only include " | ||||
"transactions confirmed at least this many times.\n" | "transactions confirmed at least this many times.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"amount (numeric) The total amount in " + | "amount (numeric) The total amount in " + | ||||
CURRENCY_UNIT + " received for this account.\n" | CURRENCY_UNIT + " received for this label.\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nAmount received by the default account with at " | "\nAmount received by the default label with at " | ||||
"least 1 confirmation\n" + | "least 1 confirmation\n" + | ||||
HelpExampleCli("getreceivedbyaccount", "\"\"") + | HelpExampleCli("getreceivedbylabel", "\"\"") + | ||||
"\nAmount received at the tabby account including unconfirmed " | "\nAmount received at the tabby label including unconfirmed " | ||||
"amounts with zero confirmations\n" + | "amounts with zero confirmations\n" + | ||||
HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") + | HelpExampleCli("getreceivedbylabel", "\"tabby\" 0") + | ||||
"\nThe amount with at least 6 confirmation, very safe\n" + | "\nThe amount with at least 6 confirmations\n" + | ||||
HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") + | HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") + | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")); | HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Get the set of pub keys assigned to account | // Get the set of pub keys assigned to label | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
std::set<CTxDestination> setAddress = | std::set<CTxDestination> setAddress = pwallet->GetLabelAddresses(label); | ||||
pwallet->GetAccountAddresses(strAccount); | |||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock(config, *wtx.tx, | !ContextualCheckTransactionForCurrentBlock(config, *wtx.tx, | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
HelpExampleRpc( | HelpExampleRpc( | ||||
"move", | "move", | ||||
"\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")); | "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strFrom = AccountFromValue(request.params[0]); | std::string strFrom = LabelFromValue(request.params[0]); | ||||
std::string strTo = AccountFromValue(request.params[1]); | std::string strTo = LabelFromValue(request.params[1]); | ||||
Amount nAmount = AmountFromValue(request.params[2]); | Amount nAmount = AmountFromValue(request.params[2]); | ||||
if (nAmount <= Amount::zero()) { | if (nAmount <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
} | } | ||||
if (request.params.size() > 3) { | if (request.params.size() > 3) { | ||||
// Unused parameter, used to be nMinDepth, keep type-checking it though. | // Unused parameter, used to be nMinDepth, keep type-checking it though. | ||||
(void)request.params[3].get_int(); | (void)request.params[3].get_int(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
HelpExampleRpc("sendfrom", | HelpExampleRpc("sendfrom", | ||||
"\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | ||||
"0.01, 6, \"donation\", \"seans outpost\"")); | "0.01, 6, \"donation\", \"seans outpost\"")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
Amount nAmount = AmountFromValue(request.params[2]); | Amount nAmount = AmountFromValue(request.params[2]); | ||||
if (nAmount <= Amount::zero()) { | if (nAmount <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
} | } | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 3) { | if (request.params.size() > 3) { | ||||
nMinDepth = request.params[3].get_int(); | nMinDepth = request.params[3].get_int(); | ||||
} | } | ||||
CWalletTx wtx; | CWalletTx wtx; | ||||
wtx.strFromAccount = strAccount; | wtx.strFromAccount = label; | ||||
if (request.params.size() > 4 && !request.params[4].isNull() && | if (request.params.size() > 4 && !request.params[4].isNull() && | ||||
!request.params[4].get_str().empty()) { | !request.params[4].get_str().empty()) { | ||||
wtx.mapValue["comment"] = request.params[4].get_str(); | wtx.mapValue["comment"] = request.params[4].get_str(); | ||||
} | } | ||||
if (request.params.size() > 5 && !request.params[5].isNull() && | if (request.params.size() > 5 && !request.params[5].isNull() && | ||||
!request.params[5].get_str().empty()) { | !request.params[5].get_str().empty()) { | ||||
wtx.mapValue["to"] = request.params[5].get_str(); | wtx.mapValue["to"] = request.params[5].get_str(); | ||||
} | } | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
// Check funds | // Check funds | ||||
Amount nBalance = | Amount nBalance = | ||||
pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); | pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &label); | ||||
if (nAmount > nBalance) { | if (nAmount > nBalance) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, | ||||
"Account has insufficient funds"); | "Account has insufficient funds"); | ||||
} | } | ||||
SendMoney(pwallet, dest, nAmount, false, wtx); | SendMoney(pwallet, dest, nAmount, false, wtx); | ||||
return wtx.GetId().GetHex(); | return wtx.GetId().GetHex(); | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
if (pwallet->GetBroadcastTransactions() && !g_connman) { | if (pwallet->GetBroadcastTransactions() && !g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string strAccount = LabelFromValue(request.params[0]); | ||||
UniValue sendTo = request.params[1].get_obj(); | UniValue sendTo = request.params[1].get_obj(); | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 2) { | if (request.params.size() > 2) { | ||||
nMinDepth = request.params[2].get_int(); | nMinDepth = request.params[2].get_int(); | ||||
} | } | ||||
CWalletTx wtx; | CWalletTx wtx; | ||||
wtx.strFromAccount = strAccount; | wtx.strFromAccount = strAccount; | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | static UniValue addmultisigaddress(const Config &config, | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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\",...] ( \"account\" )\n" | "addmultisigaddress nrequired [\"key\",...] ( \"label\" )\n" | ||||
"\nAdd a nrequired-to-sign multisignature address to the wallet. " | "\nAdd a 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" | ||||
"If 'account' is specified (DEPRECATED), assign address to that " | "If 'account' is specified (DEPRECATED), assign address to that " | ||||
"account.\n" | "account.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nrequired (numeric, required) The number of required " | "1. nrequired (numeric, required) The number of required " | ||||
"signatures out of the n keys or addresses.\n" | "signatures out of the n keys or addresses.\n" | ||||
"2. \"keys\" (string, required) A json array of bitcoin " | "2. \"keys\" (string, required) A json array of bitcoin " | ||||
"addresses or hex-encoded public keys\n" | "addresses or hex-encoded public keys\n" | ||||
" [\n" | " [\n" | ||||
" \"address\" (string) bitcoin address or hex-encoded " | " \"address\" (string) bitcoin address or hex-encoded " | ||||
"public key\n" | "public key\n" | ||||
" ...,\n" | " ...,\n" | ||||
" ]\n" | " ]\n" | ||||
"3. \"account\" (string, optional) DEPRECATED. An account to " | "3. \"label\" (string, optional) A label to " | ||||
"assign the addresses to.\n" | "assign the addresses to.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"address\" (string) A bitcoin address associated with " | "\"address\" (string) A bitcoin address associated with " | ||||
"the keys.\n" | "the keys.\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nAdd a multisig address from 2 addresses\n" + | "\nAdd a multisig address from 2 addresses\n" + | ||||
HelpExampleCli("addmultisigaddress", | HelpExampleCli("addmultisigaddress", | ||||
"2 " | "2 " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + | ||||
"\nAs json rpc call\n" + | "\nAs json rpc call\n" + | ||||
HelpExampleRpc("addmultisigaddress", | HelpExampleRpc("addmultisigaddress", | ||||
"2, " | "2, " | ||||
"\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | "\"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\"," | ||||
"\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | "\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\""); | ||||
throw std::runtime_error(msg); | throw std::runtime_error(msg); | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
std::string strAccount; | std::string label; | ||||
if (request.params.size() > 2) { | if (!request.params[2].isNull()) { | ||||
strAccount = AccountFromValue(request.params[2]); | label = LabelFromValue(request.params[2]); | ||||
} | } | ||||
// Construct using pay-to-script-hash: | // Construct using pay-to-script-hash: | ||||
CScript inner = createmultisig_redeemScript(pwallet, request.params); | CScript inner = createmultisig_redeemScript(pwallet, request.params); | ||||
CScriptID innerID(inner); | CScriptID innerID(inner); | ||||
pwallet->AddCScript(inner); | pwallet->AddCScript(inner); | ||||
pwallet->SetAddressBook(innerID, strAccount, "send"); | pwallet->SetAddressBook(innerID, label, "send"); | ||||
return EncodeDestination(innerID); | return EncodeDestination(innerID); | ||||
} | } | ||||
struct tallyitem { | struct tallyitem { | ||||
Amount nAmount; | Amount nAmount; | ||||
int nConf; | int nConf; | ||||
std::vector<uint256> txids; | std::vector<uint256> txids; | ||||
bool fIsWatchonly; | bool fIsWatchonly; | ||||
tallyitem() { | tallyitem() { | ||||
nAmount = Amount::zero(); | nAmount = Amount::zero(); | ||||
nConf = std::numeric_limits<int>::max(); | nConf = std::numeric_limits<int>::max(); | ||||
fIsWatchonly = false; | fIsWatchonly = false; | ||||
} | } | ||||
}; | }; | ||||
static UniValue ListReceived(const Config &config, CWallet *const pwallet, | UniValue ListReceived(const Config &config, CWallet *const pwallet, | ||||
const UniValue ¶ms, bool fByAccounts) { | const UniValue ¶ms, bool by_label) { | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (params.size() > 0) { | if (params.size() > 0) { | ||||
nMinDepth = params[0].get_int(); | nMinDepth = params[0].get_int(); | ||||
} | } | ||||
// Whether to include empty accounts | // Whether to include empty labels | ||||
bool fIncludeEmpty = false; | bool fIncludeEmpty = false; | ||||
if (params.size() > 1) { | if (params.size() > 1) { | ||||
fIncludeEmpty = params[1].get_bool(); | fIncludeEmpty = params[1].get_bool(); | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (params.size() > 2 && params[2].get_bool()) { | if (!params[2].isNull() && params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
bool has_filtered_address = false; | bool has_filtered_address = false; | ||||
CTxDestination filtered_address = CNoDestination(); | CTxDestination filtered_address = CNoDestination(); | ||||
if (!fByAccounts && params.size() > 3) { | if (!by_label && params.size() > 3) { | ||||
if (!IsValidDestinationString(params[3].get_str(), | if (!IsValidDestinationString(params[3].get_str(), | ||||
config.GetChainParams())) { | config.GetChainParams())) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"address_filter parameter was invalid"); | "address_filter parameter was invalid"); | ||||
} | } | ||||
filtered_address = | filtered_address = | ||||
DecodeDestination(params[3].get_str(), config.GetChainParams()); | DecodeDestination(params[3].get_str(), config.GetChainParams()); | ||||
has_filtered_address = true; | has_filtered_address = true; | ||||
Show All 38 Lines | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
if (mine & ISMINE_WATCH_ONLY) { | if (mine & ISMINE_WATCH_ONLY) { | ||||
item.fIsWatchonly = true; | item.fIsWatchonly = true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Reply | // Reply | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
std::map<std::string, tallyitem> mapAccountTally; | std::map<std::string, tallyitem> label_tally; | ||||
// Create mapAddressBook iterator | // Create mapAddressBook iterator | ||||
// If we aren't filtering, go from begin() to end() | // If we aren't filtering, go from begin() to end() | ||||
auto start = pwallet->mapAddressBook.begin(); | auto start = pwallet->mapAddressBook.begin(); | ||||
auto end = pwallet->mapAddressBook.end(); | auto end = pwallet->mapAddressBook.end(); | ||||
// If we are filtering, find() the applicable entry | // If we are filtering, find() the applicable entry | ||||
if (has_filtered_address) { | if (has_filtered_address) { | ||||
start = pwallet->mapAddressBook.find(filtered_address); | start = pwallet->mapAddressBook.find(filtered_address); | ||||
if (start != end) { | if (start != end) { | ||||
end = std::next(start); | end = std::next(start); | ||||
} | } | ||||
} | } | ||||
for (auto item_it = start; item_it != end; ++item_it) { | for (auto item_it = start; item_it != end; ++item_it) { | ||||
const CTxDestination &address = item_it->first; | const CTxDestination &address = item_it->first; | ||||
const std::string &strAccount = item_it->second.name; | const std::string &label = item_it->second.name; | ||||
std::map<CTxDestination, tallyitem>::iterator it = | std::map<CTxDestination, tallyitem>::iterator it = | ||||
mapTally.find(address); | mapTally.find(address); | ||||
if (it == mapTally.end() && !fIncludeEmpty) { | if (it == mapTally.end() && !fIncludeEmpty) { | ||||
continue; | continue; | ||||
} | } | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
int nConf = std::numeric_limits<int>::max(); | int nConf = std::numeric_limits<int>::max(); | ||||
bool fIsWatchonly = false; | bool fIsWatchonly = false; | ||||
if (it != mapTally.end()) { | if (it != mapTally.end()) { | ||||
nAmount = (*it).second.nAmount; | nAmount = (*it).second.nAmount; | ||||
nConf = (*it).second.nConf; | nConf = (*it).second.nConf; | ||||
fIsWatchonly = (*it).second.fIsWatchonly; | fIsWatchonly = (*it).second.fIsWatchonly; | ||||
} | } | ||||
if (fByAccounts) { | if (by_label) { | ||||
tallyitem &_item = mapAccountTally[strAccount]; | tallyitem &_item = label_tally[label]; | ||||
_item.nAmount += nAmount; | _item.nAmount += nAmount; | ||||
_item.nConf = std::min(_item.nConf, nConf); | _item.nConf = std::min(_item.nConf, nConf); | ||||
_item.fIsWatchonly = fIsWatchonly; | _item.fIsWatchonly = fIsWatchonly; | ||||
} else { | } else { | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
if (fIsWatchonly) { | if (fIsWatchonly) { | ||||
obj.pushKV("involvesWatchonly", true); | obj.pushKV("involvesWatchonly", true); | ||||
} | } | ||||
obj.pushKV("address", EncodeDestination(address)); | obj.push_back(Pair("address", EncodeDestination(address))); | ||||
obj.pushKV("account", strAccount); | obj.push_back(Pair("account", label)); | ||||
obj.pushKV("amount", ValueFromAmount(nAmount)); | obj.push_back(Pair("amount", ValueFromAmount(nAmount))); | ||||
obj.push_back( | obj.pushKV("confirmations", | ||||
Pair("confirmations", | (nConf == std::numeric_limits<int>::max() ? 0 : nConf)); | ||||
(nConf == std::numeric_limits<int>::max() ? 0 : nConf))); | obj.pushKV("label", label); | ||||
if (!fByAccounts) { | |||||
obj.pushKV("label", strAccount); | |||||
} | |||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
if (it != mapTally.end()) { | if (it != mapTally.end()) { | ||||
for (const uint256 &_item : (*it).second.txids) { | for (const uint256 &_item : (*it).second.txids) { | ||||
transactions.push_back(_item.GetHex()); | transactions.push_back(_item.GetHex()); | ||||
} | } | ||||
} | } | ||||
obj.pushKV("txids", transactions); | obj.pushKV("txids", transactions); | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
} | } | ||||
if (fByAccounts) { | if (by_label) { | ||||
for (std::map<std::string, tallyitem>::iterator it = | for (const auto &entry : label_tally) { | ||||
mapAccountTally.begin(); | Amount nAmount = entry.second.nAmount; | ||||
it != mapAccountTally.end(); ++it) { | int nConf = entry.second.nConf; | ||||
Amount nAmount = (*it).second.nAmount; | |||||
int nConf = (*it).second.nConf; | |||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
if ((*it).second.fIsWatchonly) { | if (entry.second.fIsWatchonly) { | ||||
obj.pushKV("involvesWatchonly", true); | obj.push_back(Pair("involvesWatchonly", true)); | ||||
} | } | ||||
obj.pushKV("account", (*it).first); | obj.pushKV("account", entry.first); | ||||
obj.pushKV("amount", ValueFromAmount(nAmount)); | obj.pushKV("amount", ValueFromAmount(nAmount)); | ||||
obj.push_back( | obj.push_back( | ||||
Pair("confirmations", | Pair("confirmations", | ||||
(nConf == std::numeric_limits<int>::max() ? 0 : nConf))); | (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); | ||||
obj.push_back(Pair("label", entry.first)); | |||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listreceivedbyaddress(const Config &config, | static UniValue listreceivedbyaddress(const Config &config, | ||||
Show All 19 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
"information on this address.\n" | "information on this address.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"involvesWatchonly\" : true, (bool) Only returned if " | " \"involvesWatchonly\" : true, (bool) Only returned if " | ||||
"imported addresses were involved in transaction\n" | "imported addresses were involved in transaction\n" | ||||
" \"address\" : \"receivingaddress\", (string) The receiving " | " \"address\" : \"receivingaddress\", (string) The receiving " | ||||
"address\n" | "address\n" | ||||
" \"account\" : \"accountname\", (string) DEPRECATED. The " | " \"account\" : \"accountname\", (string) DEPRECATED. " | ||||
"account of the receiving address. The default account is \"\".\n" | "Backwards compatible alias for label.\n \"\".\n" | ||||
" \"amount\" : x.xxx, (numeric) The total " | " \"amount\" : x.xxx, (numeric) The total " | ||||
"amount in " + | "amount in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" received by the address\n" | " received by the address\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations of the most recent transaction included\n" | "confirmations of the most recent transaction included\n" | ||||
" \"label\" : \"label\", (string) A comment for " | " \"label\" : \"label\", (string) The label of " | ||||
"the address/transaction, if any\n" | "the receiving address. The default label is \"\".\n" | ||||
" \"txids\": [\n" | " \"txids\": [\n" | ||||
" n, (numeric) The ids of " | " n, (numeric) The ids of " | ||||
"transactions received with the address \n" | "transactions received with the address \n" | ||||
" ...\n" | " ...\n" | ||||
" ]\n" | " ]\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("listreceivedbyaddress", "") + | HelpExampleCli("listreceivedbyaddress", "") + | ||||
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\"")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
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 listreceivedbyaccount(const Config &config, | UniValue listreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
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( | ||||
"listreceivedbyaccount ( minconf include_empty include_watchonly)\n" | "listreceivedbylabel ( minconf include_empty include_watchonly)\n" | ||||
"\nDEPRECATED. List balances by account.\n" | "\nList received transactions by label.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. minconf (numeric, optional, default=1) The minimum " | "1. minconf (numeric, optional, default=1) The minimum " | ||||
"number of confirmations before payments are included.\n" | "number of confirmations before payments are included.\n" | ||||
"2. include_empty (bool, optional, default=false) Whether to " | "2. include_empty (bool, optional, default=false) Whether to " | ||||
"include accounts that haven't received any payments.\n" | "include labels that haven't received any payments.\n" | ||||
"3. include_watchonly (bool, optional, default=false) Whether to " | "3. include_watchonly (bool, optional, default=false) Whether to " | ||||
"include watch-only addresses (see 'importaddress').\n" | "include watch-only addresses (see 'importaddress').\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"involvesWatchonly\" : true, (bool) Only returned if " | " \"involvesWatchonly\" : true, (bool) Only returned if " | ||||
"imported addresses were involved in transaction\n" | "imported addresses were involved in transaction\n" | ||||
" \"account\" : \"accountname\", (string) The account name of " | " \"account\" : \"accountname\", (string) DEPRECATED. " | ||||
"the receiving account\n" | "Backwards compatible alias for label.\n" | ||||
" \"amount\" : x.xxx, (numeric) The total amount " | " \"amount\" : x.xxx, (numeric) The total amount " | ||||
"received by addresses with this account\n" | "received by addresses with this label\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations of the most recent transaction included\n" | "confirmations of the most recent transaction included\n" | ||||
" \"label\" : \"label\" (string) A comment for the " | " \"label\" : \"label\" (string) The label of the " | ||||
"address/transaction, if any\n" | "receiving address. The default label is \"\".\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("listreceivedbyaccount", "") + | HelpExampleCli("listreceivedbylabel", "") + | ||||
HelpExampleCli("listreceivedbyaccount", "6 true") + | HelpExampleCli("listreceivedbylabel", "6 true") + | ||||
HelpExampleRpc("listreceivedbyaccount", "6, true, true")); | HelpExampleRpc("listreceivedbylabel", "6, true, true")); | ||||
} | } | ||||
ObserveSafeMode(); | ObserveSafeMode(); | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
return ListReceived(config, pwallet, request.params, true); | return ListReceived(config, pwallet, request.params, true); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,475 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 5) { | ||||
"\n" | "\n" | ||||
" }\n" | " }\n" | ||||
"\nResult\n" | "\nResult\n" | ||||
"[ (array of json object)\n" | "[ (array of json object)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"txid\", (string) the transaction id \n" | " \"txid\" : \"txid\", (string) the transaction id \n" | ||||
" \"vout\" : n, (numeric) the vout value\n" | " \"vout\" : n, (numeric) the vout value\n" | ||||
" \"address\" : \"address\", (string) the bitcoin address\n" | " \"address\" : \"address\", (string) the bitcoin address\n" | ||||
" \"account\" : \"account\", (string) DEPRECATED. The " | " \"label\" : \"label\", (string) The associated label, " | ||||
"associated account, or \"\" for the default account\n" | "or \"\" for the default label\n" | ||||
" \"account\" : \"account\", (string) DEPRECATED. Backwards " | |||||
"compatible alias for label.\n" | |||||
" \"scriptPubKey\" : \"key\", (string) the script key\n" | " \"scriptPubKey\" : \"key\", (string) the script key\n" | ||||
" \"amount\" : x.xxx, (numeric) the transaction output " | " \"amount\" : x.xxx, (numeric) the transaction output " | ||||
"amount in " + | "amount in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations\n" | "confirmations\n" | ||||
" \"redeemScript\" : n (string) The redeemScript if " | " \"redeemScript\" : n (string) The redeemScript if " | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
entry.pushKV("txid", out.tx->GetId().GetHex()); | entry.pushKV("txid", out.tx->GetId().GetHex()); | ||||
entry.pushKV("vout", out.i); | entry.pushKV("vout", out.i); | ||||
if (fValidAddress) { | if (fValidAddress) { | ||||
entry.pushKV("address", EncodeDestination(address)); | entry.pushKV("address", EncodeDestination(address)); | ||||
if (pwallet->mapAddressBook.count(address)) { | if (pwallet->mapAddressBook.count(address)) { | ||||
entry.push_back( | entry.push_back( | ||||
Pair("label", pwallet->mapAddressBook[address].name)); | |||||
entry.push_back( | |||||
Pair("account", pwallet->mapAddressBook[address].name)); | Pair("account", pwallet->mapAddressBook[address].name)); | ||||
} | } | ||||
if (scriptPubKey.IsPayToScriptHash()) { | if (scriptPubKey.IsPayToScriptHash()) { | ||||
const CScriptID &hash = boost::get<CScriptID>(address); | const CScriptID &hash = boost::get<CScriptID>(address); | ||||
CScript redeemScript; | CScript redeemScript; | ||||
if (pwallet->GetCScript(hash, redeemScript)) { | if (pwallet->GetCScript(hash, redeemScript)) { | ||||
entry.push_back( | entry.push_back( | ||||
▲ Show 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | |||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, | ||||
{ "hidden", "resendwallettransactions", resendwallettransactions, {} }, | { "hidden", "resendwallettransactions", resendwallettransactions, {} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, {"txid"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","account"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label|account"} }, | ||||
{ "wallet", "backupwallet", backupwallet, {"destination"} }, | { "wallet", "backupwallet", backupwallet, {"destination"} }, | ||||
{ "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, {"passphrase"} }, | ||||
{ "wallet", "getaccountaddress", getaccountaddress, {"account"} }, | { "wallet", "getaccountaddress", getlabeladdress, {"account"} }, | ||||
{ "wallet", "getlabeladdress", getlabeladdress, {"account"} }, | |||||
{ "wallet", "getaccount", getaccount, {"address"} }, | |||||
{ "wallet", "getaccount", getaccount, {"address"} }, | { "wallet", "getaccount", getaccount, {"address"} }, | ||||
{ "wallet", "getaddressesbyaccount", getaddressesbyaccount, {"account"} }, | { "wallet", "getaddressesbyaccount", getaddressesbyaccount, {"account"} }, | ||||
{ "wallet", "getbalance", getbalance, {"account","minconf","include_watchonly"} }, | { "wallet", "getbalance", getbalance, {"account","minconf","include_watchonly"} }, | ||||
{ "wallet", "getnewaddress", getnewaddress, {"account"} }, | { "wallet", "getnewaddress", getnewaddress, {"label|account"} }, | ||||
{ "wallet", "getrawchangeaddress", getrawchangeaddress, {} }, | { "wallet", "getrawchangeaddress", getrawchangeaddress, {} }, | ||||
{ "wallet", "getreceivedbyaccount", getreceivedbyaccount, {"account","minconf"} }, | { "wallet", "getreceivedbylabel", getreceivedbylabel, {"label","minconf"} }, | ||||
{ "wallet", "getreceivedbyaccount", getreceivedbylabel, {"account","minconf"} }, | |||||
{ "wallet", "getreceivedbyaddress", getreceivedbyaddress, {"address","minconf"} }, | { "wallet", "getreceivedbyaddress", getreceivedbyaddress, {"address","minconf"} }, | ||||
{ "wallet", "gettransaction", gettransaction, {"txid","include_watchonly"} }, | { "wallet", "gettransaction", gettransaction, {"txid","include_watchonly"} }, | ||||
{ "wallet", "getunconfirmedbalance", getunconfirmedbalance, {} }, | { "wallet", "getunconfirmedbalance", getunconfirmedbalance, {} }, | ||||
{ "wallet", "getwalletinfo", getwalletinfo, {} }, | { "wallet", "getwalletinfo", getwalletinfo, {} }, | ||||
{ "wallet", "keypoolrefill", keypoolrefill, {"newsize"} }, | { "wallet", "keypoolrefill", keypoolrefill, {"newsize"} }, | ||||
{ "wallet", "listaccounts", listaccounts, {"minconf","include_watchonly"} }, | { "wallet", "listaccounts", listaccounts, {"minconf","include_watchonly"} }, | ||||
{ "wallet", "listaddressgroupings", listaddressgroupings, {} }, | { "wallet", "listaddressgroupings", listaddressgroupings, {} }, | ||||
{ "wallet", "listlockunspent", listlockunspent, {} }, | { "wallet", "listlockunspent", listlockunspent, {} }, | ||||
{ "wallet", "listreceivedbyaccount", listreceivedbyaccount, {"minconf","include_empty","include_watchonly"} }, | { "wallet", "listreceivedbylabel", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | ||||
{ "wallet", "listreceivedbyaccount", listreceivedbylabel, {"minconf","include_empty","include_watchonly"} }, | |||||
{ "wallet", "listreceivedbyaddress", listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, | { "wallet", "listreceivedbyaddress", listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, | ||||
{ "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly"} }, | { "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly"} }, | ||||
{ "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | { "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, | ||||
{ "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | { "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | ||||
{ "wallet", "listwallets", listwallets, {} }, | { "wallet", "listwallets", listwallets, {} }, | ||||
{ "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | { "wallet", "lockunspent", lockunspent, {"unlock","transactions"} }, | ||||
{ "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | { "wallet", "move", movecmd, {"fromaccount","toaccount","amount","minconf","comment"} }, | ||||
{ "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | { "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, | ||||
{ "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | { "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | ||||
{ "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | { "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, | ||||
{ "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | { "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, | ||||
{ "wallet", "setaccount", setaccount, {"address","account"} }, | { "wallet", "setlabel", setlabel, {"address","label"} }, | ||||
{ "wallet", "setaccount", setlabel, {"address","account"} }, | |||||
{ "wallet", "settxfee", settxfee, {"amount"} }, | { "wallet", "settxfee", settxfee, {"amount"} }, | ||||
{ "wallet", "signmessage", signmessage, {"address","message"} }, | { "wallet", "signmessage", signmessage, {"address","message"} }, | ||||
{ "wallet", "walletlock", walletlock, {} }, | { "wallet", "walletlock", walletlock, {} }, | ||||
{ "wallet", "walletpassphrasechange", walletpassphrasechange, {"oldpassphrase","newpassphrase"} }, | { "wallet", "walletpassphrasechange", walletpassphrasechange, {"oldpassphrase","newpassphrase"} }, | ||||
{ "wallet", "walletpassphrase", walletpassphrase, {"passphrase","timeout"} }, | { "wallet", "walletpassphrase", walletpassphrase, {"passphrase","timeout"} }, | ||||
{ "generating", "generate", generate, {"nblocks","maxtries"} }, | { "generating", "generate", generate, {"nblocks","maxtries"} }, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
Show All 10 Lines |