Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
| Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | 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, strAccount, "receive"); | ||||
| return EncodeDestination(keyID); | return EncodeDestination(keyID, config); | ||||
| } | } | ||||
| CTxDestination GetAccountAddress(CWallet *const pwallet, std::string strAccount, | CTxDestination GetAccountAddress(CWallet *const pwallet, std::string strAccount, | ||||
| bool bForceNew = false) { | bool bForceNew = false) { | ||||
| CPubKey pubKey; | CPubKey pubKey; | ||||
| if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) { | if (!pwallet->GetAccountPubkey(pubKey, strAccount, bForceNew)) { | ||||
| throw JSONRPCError( | throw JSONRPCError( | ||||
| RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
| Show All 32 Lines | static UniValue getaccountaddress(const Config &config, | ||||
| 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 = AccountFromValue(request.params[0]); | std::string strAccount = AccountFromValue(request.params[0]); | ||||
| UniValue ret(UniValue::VSTR); | UniValue ret(UniValue::VSTR); | ||||
| ret = EncodeDestination(GetAccountAddress(pwallet, strAccount)); | ret = EncodeDestination(GetAccountAddress(pwallet, strAccount), 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); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
| if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
| return NullUniValue; | return NullUniValue; | ||||
| Show All 24 Lines | if (!reservekey.GetReservedKey(vchPubKey, true)) { | ||||
| 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"); | ||||
| } | } | ||||
| reservekey.KeepKey(); | reservekey.KeepKey(); | ||||
| CKeyID keyID = vchPubKey.GetID(); | CKeyID keyID = vchPubKey.GetID(); | ||||
| return EncodeDestination(keyID); | return EncodeDestination(keyID, config); | ||||
| } | } | ||||
| static UniValue setaccount(const Config &config, | static UniValue setaccount(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 15 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
| HelpExampleRpc( | HelpExampleRpc( | ||||
| "setaccount", | "setaccount", | ||||
| "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")); | ||||
| } | } | ||||
| 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); | ||||
| 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 strAccount; | ||||
| if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
| strAccount = AccountFromValue(request.params[1]); | strAccount = AccountFromValue(request.params[1]); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
| "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"") + | ||||
| HelpExampleRpc("getaccount", | HelpExampleRpc("getaccount", | ||||
| "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\"")); | ||||
| } | } | ||||
| 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); | ||||
| 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 strAccount; | ||||
| std::map<CTxDestination, CAddressBookData>::iterator mi = | std::map<CTxDestination, CAddressBookData>::iterator mi = | ||||
| pwallet->mapAddressBook.find(dest); | pwallet->mapAddressBook.find(dest); | ||||
| Show All 35 Lines | static UniValue getaddressesbyaccount(const Config &config, | ||||
| // 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) { | ||||
| ret.push_back(EncodeDestination(dest)); | ret.push_back(EncodeDestination(dest, config)); | ||||
| } | } | ||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| static void SendMoney(CWallet *const pwallet, const CTxDestination &address, | static void SendMoney(CWallet *const pwallet, const CTxDestination &address, | ||||
| Amount nValue, bool fSubtractFeeFromAmount, | Amount nValue, bool fSubtractFeeFromAmount, | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
| HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | HelpExampleRpc("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | ||||
| "dd\", 0.1, \"donation\", \"seans " | "dd\", 0.1, \"donation\", \"seans " | ||||
| "outpost\"")); | "outpost\"")); | ||||
| } | } | ||||
| 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); | ||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | ||||
| } | } | ||||
| // Amount | // Amount | ||||
| Amount nAmount = AmountFromValue(request.params[1]); | Amount nAmount = AmountFromValue(request.params[1]); | ||||
| if (nAmount <= Amount(0)) { | if (nAmount <= Amount(0)) { | ||||
| throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | static UniValue listaddressgroupings(const Config &config, | ||||
| UniValue jsonGroupings(UniValue::VARR); | UniValue jsonGroupings(UniValue::VARR); | ||||
| std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | std::map<CTxDestination, Amount> balances = pwallet->GetAddressBalances(); | ||||
| for (const std::set<CTxDestination> &grouping : | for (const std::set<CTxDestination> &grouping : | ||||
| pwallet->GetAddressGroupings()) { | pwallet->GetAddressGroupings()) { | ||||
| UniValue jsonGrouping(UniValue::VARR); | UniValue jsonGrouping(UniValue::VARR); | ||||
| for (const CTxDestination &address : grouping) { | for (const CTxDestination &address : grouping) { | ||||
| UniValue addressInfo(UniValue::VARR); | UniValue addressInfo(UniValue::VARR); | ||||
| addressInfo.push_back(EncodeDestination(address)); | addressInfo.push_back(EncodeDestination(address, config)); | ||||
| addressInfo.push_back(ValueFromAmount(balances[address])); | addressInfo.push_back(ValueFromAmount(balances[address])); | ||||
| if (pwallet->mapAddressBook.find(address) != | if (pwallet->mapAddressBook.find(address) != | ||||
| pwallet->mapAddressBook.end()) { | pwallet->mapAddressBook.end()) { | ||||
| addressInfo.push_back( | addressInfo.push_back( | ||||
| pwallet->mapAddressBook.find(address)->second.name); | pwallet->mapAddressBook.find(address)->second.name); | ||||
| } | } | ||||
| jsonGrouping.push_back(addressInfo); | jsonGrouping.push_back(addressInfo); | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static UniValue signmessage(const Config &config, | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
| std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
| std::string strMessage = request.params[1].get_str(); | std::string strMessage = request.params[1].get_str(); | ||||
| CTxDestination dest = | CTxDestination dest = DecodeDestination(strAddress, config); | ||||
| DecodeDestination(strAddress, config.GetChainParams()); | |||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | ||||
| } | } | ||||
| const CKeyID *keyID = boost::get<CKeyID>(&dest); | const CKeyID *keyID = boost::get<CKeyID>(&dest); | ||||
| if (!keyID) { | if (!keyID) { | ||||
| throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
| HelpExampleRpc("getreceivedbyaddress", | HelpExampleRpc("getreceivedbyaddress", | ||||
| "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")); | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6")); | ||||
| } | } | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| // Bitcoin address | // Bitcoin address | ||||
| CTxDestination dest = | CTxDestination dest = | ||||
| DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), config); | ||||
| 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"); | ||||
| } | } | ||||
| CScript scriptPubKey = GetScriptForDestination(dest); | CScript scriptPubKey = GetScriptForDestination(dest); | ||||
| if (!IsMine(*pwallet, scriptPubKey)) { | if (!IsMine(*pwallet, scriptPubKey)) { | ||||
| return ValueFromAmount(Amount(0)); | return ValueFromAmount(Amount(0)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
| "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", " | ||||
| "0.01, 6, \"donation\", \"seans outpost\"")); | "0.01, 6, \"donation\", \"seans outpost\"")); | ||||
| } | } | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| std::string strAccount = AccountFromValue(request.params[0]); | std::string strAccount = AccountFromValue(request.params[0]); | ||||
| CTxDestination dest = | CTxDestination dest = | ||||
| DecodeDestination(request.params[1].get_str(), config.GetChainParams()); | DecodeDestination(request.params[1].get_str(), config); | ||||
| 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(0)) { | if (nAmount <= Amount(0)) { | ||||
| throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
| } | } | ||||
| std::set<CTxDestination> destinations; | std::set<CTxDestination> destinations; | ||||
| std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
| Amount totalAmount(0); | Amount totalAmount(0); | ||||
| std::vector<std::string> keys = sendTo.getKeys(); | std::vector<std::string> keys = sendTo.getKeys(); | ||||
| for (const std::string &name_ : keys) { | for (const std::string &name_ : keys) { | ||||
| CTxDestination dest = DecodeDestination(name_, config.GetChainParams()); | CTxDestination dest = DecodeDestination(name_, config); | ||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| std::string("Invalid Bitcoin address: ") + | std::string("Invalid Bitcoin address: ") + | ||||
| name_); | name_); | ||||
| } | } | ||||
| if (destinations.count(dest)) { | if (destinations.count(dest)) { | ||||
| throw JSONRPCError( | throw JSONRPCError( | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | static UniValue addmultisigaddress(const Config &config, | ||||
| LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
| std::string strAccount; | std::string strAccount; | ||||
| if (request.params.size() > 2) { | if (request.params.size() > 2) { | ||||
| strAccount = AccountFromValue(request.params[2]); | strAccount = AccountFromValue(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(config, pwallet, request.params); | |||||
| CScriptID innerID(inner); | CScriptID innerID(inner); | ||||
| pwallet->AddCScript(inner); | pwallet->AddCScript(inner); | ||||
| pwallet->SetAddressBook(innerID, strAccount, "send"); | pwallet->SetAddressBook(innerID, strAccount, "send"); | ||||
| return EncodeDestination(innerID); | return EncodeDestination(innerID, config); | ||||
| } | } | ||||
| 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() { | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | for (const std::pair<CTxDestination, CAddressBookData> &item : | ||||
| _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.push_back(Pair("involvesWatchonly", true)); | obj.push_back(Pair("involvesWatchonly", true)); | ||||
| } | } | ||||
| obj.push_back(Pair("address", EncodeDestination(dest))); | obj.push_back(Pair("address", EncodeDestination(dest, config))); | ||||
| obj.push_back(Pair("account", strAccount)); | obj.push_back(Pair("account", strAccount)); | ||||
| obj.push_back(Pair("amount", ValueFromAmount(nAmount))); | obj.push_back(Pair("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))); | ||||
| if (!fByAccounts) { | if (!fByAccounts) { | ||||
| obj.push_back(Pair("label", strAccount)); | obj.push_back(Pair("label", strAccount)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 3) { | ||||
| HelpExampleRpc("listreceivedbyaccount", "6, true, true")); | HelpExampleRpc("listreceivedbyaccount", "6, true, true")); | ||||
| } | } | ||||
| 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); | ||||
| } | } | ||||
| static void MaybePushAddress(UniValue &entry, const CTxDestination &dest) { | static void MaybePushAddress(UniValue &entry, const CTxDestination &dest, | ||||
| const Config &config) { | |||||
| if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
| entry.push_back(Pair("address", EncodeDestination(dest))); | entry.push_back(Pair("address", EncodeDestination(dest, config))); | ||||
| } | } | ||||
| } | } | ||||
| void ListTransactions(CWallet *const pwallet, const CWalletTx &wtx, | void ListTransactions(CWallet *const pwallet, const CWalletTx &wtx, | ||||
| const std::string &strAccount, int nMinDepth, bool fLong, | const std::string &strAccount, int nMinDepth, bool fLong, | ||||
| UniValue &ret, const isminefilter &filter) { | UniValue &ret, const isminefilter &filter, | ||||
| const Config &config) { | |||||
| Amount nFee; | Amount nFee; | ||||
| std::string strSentAccount; | std::string strSentAccount; | ||||
| std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
| std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
| wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter); | ||||
| bool fAllAccounts = (strAccount == std::string("*")); | bool fAllAccounts = (strAccount == std::string("*")); | ||||
| bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); | bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY); | ||||
| // Sent | // Sent | ||||
| if ((!listSent.empty() || nFee != Amount(0)) && | if ((!listSent.empty() || nFee != Amount(0)) && | ||||
| (fAllAccounts || strAccount == strSentAccount)) { | (fAllAccounts || strAccount == strSentAccount)) { | ||||
| for (const COutputEntry &s : listSent) { | for (const COutputEntry &s : listSent) { | ||||
| UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
| if (involvesWatchonly || | if (involvesWatchonly || | ||||
| (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { | (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { | ||||
| entry.push_back(Pair("involvesWatchonly", true)); | entry.push_back(Pair("involvesWatchonly", true)); | ||||
| } | } | ||||
| entry.push_back(Pair("account", strSentAccount)); | entry.push_back(Pair("account", strSentAccount)); | ||||
| MaybePushAddress(entry, s.destination); | MaybePushAddress(entry, s.destination, config); | ||||
| entry.push_back(Pair("category", "send")); | entry.push_back(Pair("category", "send")); | ||||
| entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); | entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); | ||||
| if (pwallet->mapAddressBook.count(s.destination)) { | if (pwallet->mapAddressBook.count(s.destination)) { | ||||
| entry.push_back( | entry.push_back( | ||||
| Pair("label", pwallet->mapAddressBook[s.destination].name)); | Pair("label", pwallet->mapAddressBook[s.destination].name)); | ||||
| } | } | ||||
| entry.push_back(Pair("vout", s.vout)); | entry.push_back(Pair("vout", s.vout)); | ||||
| entry.push_back(Pair("fee", ValueFromAmount(-1 * nFee))); | entry.push_back(Pair("fee", ValueFromAmount(-1 * nFee))); | ||||
| Show All 14 Lines | if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
| } | } | ||||
| if (fAllAccounts || (account == strAccount)) { | if (fAllAccounts || (account == strAccount)) { | ||||
| UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
| if (involvesWatchonly || | if (involvesWatchonly || | ||||
| (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) { | (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) { | ||||
| entry.push_back(Pair("involvesWatchonly", true)); | entry.push_back(Pair("involvesWatchonly", true)); | ||||
| } | } | ||||
| entry.push_back(Pair("account", account)); | entry.push_back(Pair("account", account)); | ||||
| MaybePushAddress(entry, r.destination); | MaybePushAddress(entry, r.destination, config); | ||||
| if (wtx.IsCoinBase()) { | if (wtx.IsCoinBase()) { | ||||
| if (wtx.GetDepthInMainChain() < 1) { | if (wtx.GetDepthInMainChain() < 1) { | ||||
| entry.push_back(Pair("category", "orphan")); | entry.push_back(Pair("category", "orphan")); | ||||
| } else if (wtx.GetBlocksToMaturity() > 0) { | } else if (wtx.GetBlocksToMaturity() > 0) { | ||||
| entry.push_back(Pair("category", "immature")); | entry.push_back(Pair("category", "immature")); | ||||
| } else { | } else { | ||||
| entry.push_back(Pair("category", "generate")); | entry.push_back(Pair("category", "generate")); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | static UniValue listtransactions(const Config &config, | ||||
| const CWallet::TxItems &txOrdered = pwallet->wtxOrdered; | const CWallet::TxItems &txOrdered = pwallet->wtxOrdered; | ||||
| // iterate backwards until we have nCount items to return: | // iterate backwards until we have nCount items to return: | ||||
| for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); | for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); | ||||
| it != txOrdered.rend(); ++it) { | it != txOrdered.rend(); ++it) { | ||||
| CWalletTx *const pwtx = (*it).second.first; | CWalletTx *const pwtx = (*it).second.first; | ||||
| if (pwtx != 0) { | if (pwtx != 0) { | ||||
| ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter); | ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter, | ||||
| config); | |||||
| } | } | ||||
| CAccountingEntry *const pacentry = (*it).second.second; | CAccountingEntry *const pacentry = (*it).second.second; | ||||
| if (pacentry != 0) { | if (pacentry != 0) { | ||||
| AcentryToJSON(*pacentry, strAccount, ret); | AcentryToJSON(*pacentry, strAccount, ret); | ||||
| } | } | ||||
| if ((int)ret.size() >= (nCount + nFrom)) { | if ((int)ret.size() >= (nCount + nFrom)) { | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
| int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | ||||
| UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
| for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<uint256, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
| CWalletTx tx = pairWtx.second; | CWalletTx tx = pairWtx.second; | ||||
| if (depth == -1 || tx.GetDepthInMainChain() < depth) { | if (depth == -1 || tx.GetDepthInMainChain() < depth) { | ||||
| ListTransactions(pwallet, tx, "*", 0, true, transactions, filter); | ListTransactions(pwallet, tx, "*", 0, true, transactions, filter, | ||||
| config); | |||||
| } | } | ||||
| } | } | ||||
| CBlockIndex *pblockLast = | CBlockIndex *pblockLast = | ||||
| chainActive[chainActive.Height() + 1 - target_confirms]; | chainActive[chainActive.Height() + 1 - target_confirms]; | ||||
| uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256(); | uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256(); | ||||
| UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | static UniValue gettransaction(const Config &config, | ||||
| entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); | entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); | ||||
| if (wtx.IsFromMe(filter)) { | if (wtx.IsFromMe(filter)) { | ||||
| entry.push_back(Pair("fee", ValueFromAmount(nFee))); | entry.push_back(Pair("fee", ValueFromAmount(nFee))); | ||||
| } | } | ||||
| WalletTxToJSON(wtx, entry); | WalletTxToJSON(wtx, entry); | ||||
| UniValue details(UniValue::VARR); | UniValue details(UniValue::VARR); | ||||
| ListTransactions(pwallet, wtx, "*", 0, false, details, filter); | ListTransactions(pwallet, wtx, "*", 0, false, details, filter, config); | ||||
| entry.push_back(Pair("details", details)); | entry.push_back(Pair("details", details)); | ||||
| std::string strHex = | std::string strHex = | ||||
| EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags()); | EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags()); | ||||
| entry.push_back(Pair("hex", strHex)); | entry.push_back(Pair("hex", strHex)); | ||||
| return entry; | return entry; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 844 Lines • ▼ Show 20 Lines | static UniValue listunspent(const Config &config, | ||||
| } | } | ||||
| std::set<CTxDestination> destinations; | std::set<CTxDestination> destinations; | ||||
| if (request.params.size() > 2 && !request.params[2].isNull()) { | if (request.params.size() > 2 && !request.params[2].isNull()) { | ||||
| RPCTypeCheckArgument(request.params[2], UniValue::VARR); | RPCTypeCheckArgument(request.params[2], UniValue::VARR); | ||||
| UniValue inputs = request.params[2].get_array(); | UniValue inputs = request.params[2].get_array(); | ||||
| for (size_t idx = 0; idx < inputs.size(); idx++) { | for (size_t idx = 0; idx < inputs.size(); idx++) { | ||||
| const UniValue &input = inputs[idx]; | const UniValue &input = inputs[idx]; | ||||
| CTxDestination dest = | CTxDestination dest = DecodeDestination(input.get_str(), config); | ||||
| DecodeDestination(input.get_str(), config.GetChainParams()); | |||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
| std::string("Invalid Bitcoin address: ") + | std::string("Invalid Bitcoin address: ") + | ||||
| input.get_str()); | input.get_str()); | ||||
| } | } | ||||
| if (!destinations.insert(dest).second) { | if (!destinations.insert(dest).second) { | ||||
| throw JSONRPCError( | throw JSONRPCError( | ||||
| RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
| Show All 28 Lines | for (const COutput &out : vecOutputs) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
| entry.push_back(Pair("txid", out.tx->GetId().GetHex())); | entry.push_back(Pair("txid", out.tx->GetId().GetHex())); | ||||
| entry.push_back(Pair("vout", out.i)); | entry.push_back(Pair("vout", out.i)); | ||||
| if (fValidAddress) { | if (fValidAddress) { | ||||
| entry.push_back(Pair("address", EncodeDestination(address))); | entry.push_back( | ||||
| Pair("address", EncodeDestination(address, config))); | |||||
| if (pwallet->mapAddressBook.count(address)) { | if (pwallet->mapAddressBook.count(address)) { | ||||
| entry.push_back( | 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); | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | if (request.params.size() > 1) { | ||||
| {"reserveChangeKey", UniValueType(UniValue::VBOOL)}, | {"reserveChangeKey", UniValueType(UniValue::VBOOL)}, | ||||
| // will be checked below | // will be checked below | ||||
| {"feeRate", UniValueType()}, | {"feeRate", UniValueType()}, | ||||
| {"subtractFeeFromOutputs", UniValueType(UniValue::VARR)}, | {"subtractFeeFromOutputs", UniValueType(UniValue::VARR)}, | ||||
| }, | }, | ||||
| true, true); | true, true); | ||||
| if (options.exists("changeAddress")) { | if (options.exists("changeAddress")) { | ||||
| CTxDestination dest = | CTxDestination dest = DecodeDestination( | ||||
| DecodeDestination(options["changeAddress"].get_str(), | options["changeAddress"].get_str(), config); | ||||
| config.GetChainParams()); | |||||
| if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
| throw JSONRPCError( | throw JSONRPCError( | ||||
| RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
| "changeAddress must be a valid bitcoin address"); | "changeAddress must be a valid bitcoin address"); | ||||
| } | } | ||||
| changeAddress = dest; | changeAddress = dest; | ||||
| ▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines | |||||