Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
if (confirms > 0) { | if (confirms > 0) { | ||||
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); | entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); | ||||
entry.push_back(Pair("blockindex", wtx.nIndex)); | entry.push_back(Pair("blockindex", wtx.nIndex)); | ||||
entry.push_back( | entry.push_back( | ||||
Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); | Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); | ||||
} else { | } else { | ||||
entry.push_back(Pair("trusted", wtx.IsTrusted())); | entry.push_back(Pair("trusted", wtx.IsTrusted())); | ||||
} | } | ||||
uint256 hash = wtx.GetId(); | TxHash hash = wtx.GetHash(); | ||||
entry.push_back(Pair("txid", hash.GetHex())); | entry.push_back(Pair("txid", hash.GetHex())); | ||||
UniValue conflicts(UniValue::VARR); | UniValue conflicts(UniValue::VARR); | ||||
for (const uint256 &conflict : wtx.GetConflicts()) { | for (const TxHash &conflict : wtx.GetConflicts()) { | ||||
conflicts.push_back(conflict.GetHex()); | conflicts.push_back(conflict.GetHex()); | ||||
} | } | ||||
entry.push_back(Pair("walletconflicts", conflicts)); | entry.push_back(Pair("walletconflicts", conflicts)); | ||||
entry.push_back(Pair("time", wtx.GetTxTime())); | entry.push_back(Pair("time", wtx.GetTxTime())); | ||||
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); | entry.push_back(Pair("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.push_back(Pair(item.first, item.second)); | entry.push_back(Pair(item.first, item.second)); | ||||
▲ Show 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | static UniValue sendtoaddress(const Config &config, | ||||
if (request.params.size() > 4) { | if (request.params.size() > 4) { | ||||
fSubtractFeeFromAmount = request.params[4].get_bool(); | fSubtractFeeFromAmount = request.params[4].get_bool(); | ||||
} | } | ||||
EnsureWalletIsUnlocked(); | EnsureWalletIsUnlocked(); | ||||
SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx); | SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx); | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue listaddressgroupings(const Config &config, | static UniValue listaddressgroupings(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
// 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(); | ||||
} | } | ||||
// Tally | // Tally | ||||
Amount nAmount = 0; | Amount nAmount = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaccount(const Config &config, | ||||
// Get the set of pub keys assigned to account | // Get the set of pub keys assigned to account | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string strAccount = AccountFromValue(request.params[0]); | ||||
std::set<CTxDestination> setAddress = | std::set<CTxDestination> setAddress = | ||||
pwalletMain->GetAccountAddresses(strAccount); | pwalletMain->GetAccountAddresses(strAccount); | ||||
// Tally | // Tally | ||||
Amount nAmount = 0; | Amount nAmount = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
config.GetChainParams().GetConsensus())) { | config.GetChainParams().GetConsensus())) { | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | static UniValue getbalance(const Config &config, | ||||
if (request.params[0].get_str() == "*") { | if (request.params[0].get_str() == "*") { | ||||
// Calculate total balance in a very different way from GetBalance(). | // Calculate total balance in a very different way from GetBalance(). | ||||
// The biggest difference is that GetBalance() sums up all unspent | // The biggest difference is that GetBalance() sums up all unspent | ||||
// TxOuts paying to the wallet, while this sums up both spent and | // TxOuts paying to the wallet, while this sums up both spent and | ||||
// unspent TxOuts paying to the wallet, and then subtracts the values of | // unspent TxOuts paying to the wallet, and then subtracts the values of | ||||
// TxIns spending from the wallet. This also has fewer restrictions on | // TxIns spending from the wallet. This also has fewer restrictions on | ||||
// which unconfirmed transactions are considered trusted. | // which unconfirmed transactions are considered trusted. | ||||
Amount nBalance = 0; | Amount nBalance = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock( | if (!ContextualCheckTransactionForCurrentBlock( | ||||
config, wtx, state, | config, wtx, state, | ||||
config.GetChainParams().GetConsensus()) || | config.GetChainParams().GetConsensus()) || | ||||
wtx.GetBlocksToMaturity() > 0 || | wtx.GetBlocksToMaturity() > 0 || | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | Amount nBalance = | ||||
pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); | pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); | ||||
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(dest, nAmount, false, wtx); | SendMoney(dest, nAmount, false, wtx); | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), | if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), | ||||
state)) { | state)) { | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
state.GetRejectReason()); | state.GetRejectReason()); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue addmultisigaddress(const Config &config, | static UniValue addmultisigaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | static UniValue ListReceived(const Config &config, const UniValue ¶ms, | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (params.size() > 2 && params[2].get_bool()) | if (params.size() > 2 && params[2].get_bool()) | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
// Tally | // Tally | ||||
std::map<CTxDestination, tallyitem> mapTally; | std::map<CTxDestination, tallyitem> mapTally; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
Show All 15 Lines | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
isminefilter mine = IsMine(*pwalletMain, address); | isminefilter mine = IsMine(*pwalletMain, address); | ||||
if (!(mine & filter)) { | if (!(mine & filter)) { | ||||
continue; | continue; | ||||
} | } | ||||
tallyitem &item = mapTally[address]; | tallyitem &item = mapTally[address]; | ||||
item.nAmount += txout.nValue; | item.nAmount += txout.nValue; | ||||
item.nConf = std::min(item.nConf, nDepth); | item.nConf = std::min(item.nConf, nDepth); | ||||
item.txids.push_back(wtx.GetId()); | item.txids.push_back(wtx.GetHash()); | ||||
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); | ||||
▲ Show 20 Lines • Show All 510 Lines • ▼ Show 20 Lines | static UniValue listaccounts(const Config &config, | ||||
for (const std::pair<CTxDestination, CAddressBookData> &entry : | for (const std::pair<CTxDestination, CAddressBookData> &entry : | ||||
pwalletMain->mapAddressBook) { | pwalletMain->mapAddressBook) { | ||||
// This address belongs to me | // This address belongs to me | ||||
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) { | if (IsMine(*pwalletMain, entry.first) & includeWatchonly) { | ||||
mapAccountBalances[entry.second.name] = Amount(0); | mapAccountBalances[entry.second.name] = Amount(0); | ||||
} | } | ||||
} | } | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
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; | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
if (request.params.size() > 2 && request.params[2].get_bool()) { | if (request.params.size() > 2 && request.params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
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 (std::map<uint256, CWalletTx>::iterator it = | for (std::map<TxHash, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); it++) { | it != pwalletMain->mapWallet.end(); it++) { | ||||
CWalletTx tx = (*it).second; | CWalletTx tx = (*it).second; | ||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) { | if (depth == -1 || tx.GetDepthInMainChain() < depth) { | ||||
ListTransactions(tx, "*", 0, true, transactions, filter); | ListTransactions(tx, "*", 0, true, transactions, filter); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"\" true") + | "\" true") + | ||||
HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e211" | HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e211" | ||||
"5b9345e16c5cf302fc80e9d5fbf5d48d" | "5b9345e16c5cf302fc80e9d5fbf5d48d" | ||||
"\"")); | "\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
uint256 hash; | TxHash hash; | ||||
hash.SetHex(request.params[0].get_str()); | hash.SetHex(request.params[0].get_str()); | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 1 && request.params[1].get_bool()) { | if (request.params.size() > 1 && request.params[1].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
▲ Show 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | static UniValue resendwallettransactions(const Config &config, | ||||
if (!g_connman) { | if (!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"); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
std::vector<uint256> txids = | std::vector<TxHash> txids = | ||||
pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); | pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); | ||||
UniValue result(UniValue::VARR); | UniValue result(UniValue::VARR); | ||||
for (const uint256 &txid : txids) { | for (const TxHash &txhash : txids) { | ||||
result.push_back(txid.ToString()); | result.push_back(txhash.ToString()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue listunspent(const Config &config, | static UniValue listunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | ||||
bool fValidAddress = ExtractDestination(scriptPubKey, address); | bool fValidAddress = ExtractDestination(scriptPubKey, address); | ||||
if (destinations.size() && | if (destinations.size() && | ||||
(!fValidAddress || !destinations.count(address))) | (!fValidAddress || !destinations.count(address))) | ||||
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->GetHash().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))); | ||||
if (pwalletMain->mapAddressBook.count(address)) { | if (pwalletMain->mapAddressBook.count(address)) { | ||||
entry.push_back( | entry.push_back( | ||||
Pair("account", pwalletMain->mapAddressBook[address].name)); | Pair("account", pwalletMain->mapAddressBook[address].name)); | ||||
▲ Show 20 Lines • Show All 294 Lines • Show Last 20 Lines |