Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
int confirms = wtx.GetDepthInMainChain(); | int confirms = wtx.GetDepthInMainChain(); | ||||
entry.pushKV("confirmations", confirms); | entry.pushKV("confirmations", confirms); | ||||
if (wtx.IsCoinBase()) { | if (wtx.IsCoinBase()) { | ||||
entry.pushKV("generated", true); | entry.pushKV("generated", true); | ||||
} | } | ||||
if (confirms > 0) { | if (confirms > 0) { | ||||
entry.pushKV("blockhash", wtx.hashBlock.GetHex()); | entry.pushKV("blockhash", wtx.hashBlock.GetHex()); | ||||
entry.pushKV("blockindex", wtx.nIndex); | entry.pushKV("blockindex", wtx.nIndex); | ||||
entry.push_back( | entry.pushKV("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()); | ||||
Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); | |||||
} else { | } else { | ||||
entry.pushKV("trusted", wtx.IsTrusted()); | entry.pushKV("trusted", wtx.IsTrusted()); | ||||
} | } | ||||
uint256 hash = wtx.GetId(); | uint256 hash = wtx.GetId(); | ||||
entry.pushKV("txid", hash.GetHex()); | entry.pushKV("txid", hash.GetHex()); | ||||
UniValue conflicts(UniValue::VARR); | UniValue conflicts(UniValue::VARR); | ||||
for (const uint256 &conflict : wtx.GetConflicts()) { | for (const uint256 &conflict : wtx.GetConflicts()) { | ||||
conflicts.push_back(conflict.GetHex()); | conflicts.push_back(conflict.GetHex()); | ||||
▲ Show 20 Lines • Show All 1,380 Lines • ▼ Show 20 Lines | for (auto item_it = start; item_it != end; ++item_it) { | ||||
} 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.pushKV("address", EncodeDestination(address)); | ||||
obj.pushKV("account", strAccount); | obj.pushKV("account", strAccount); | ||||
obj.pushKV("amount", ValueFromAmount(nAmount)); | obj.pushKV("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))); | |||||
if (!fByAccounts) { | if (!fByAccounts) { | ||||
obj.pushKV("label", strAccount); | 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()); | ||||
} | } | ||||
Show All 10 Lines | if (fByAccounts) { | ||||
Amount nAmount = (*it).second.nAmount; | Amount nAmount = (*it).second.nAmount; | ||||
int nConf = (*it).second.nConf; | int nConf = (*it).second.nConf; | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
if ((*it).second.fIsWatchonly) { | if ((*it).second.fIsWatchonly) { | ||||
obj.pushKV("involvesWatchonly", true); | obj.pushKV("involvesWatchonly", true); | ||||
} | } | ||||
obj.pushKV("account", (*it).first); | obj.pushKV("account", (*it).first); | ||||
obj.pushKV("amount", ValueFromAmount(nAmount)); | obj.pushKV("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))); | |||||
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 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | if ((!listSent.empty() || nFee != Amount::zero()) && | ||||
(::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { | (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { | ||||
entry.pushKV("involvesWatchonly", true); | entry.pushKV("involvesWatchonly", true); | ||||
} | } | ||||
entry.pushKV("account", strSentAccount); | entry.pushKV("account", strSentAccount); | ||||
MaybePushAddress(entry, s.destination); | MaybePushAddress(entry, s.destination); | ||||
entry.pushKV("category", "send"); | entry.pushKV("category", "send"); | ||||
entry.pushKV("amount", ValueFromAmount(-s.amount)); | entry.pushKV("amount", ValueFromAmount(-s.amount)); | ||||
if (pwallet->mapAddressBook.count(s.destination)) { | if (pwallet->mapAddressBook.count(s.destination)) { | ||||
entry.push_back( | entry.pushKV("label", | ||||
Pair("label", pwallet->mapAddressBook[s.destination].name)); | pwallet->mapAddressBook[s.destination].name); | ||||
} | } | ||||
entry.pushKV("vout", s.vout); | entry.pushKV("vout", s.vout); | ||||
entry.pushKV("fee", ValueFromAmount(-1 * nFee)); | entry.pushKV("fee", ValueFromAmount(-1 * nFee)); | ||||
if (fLong) { | if (fLong) { | ||||
WalletTxToJSON(wtx, entry); | WalletTxToJSON(wtx, entry); | ||||
} | } | ||||
entry.pushKV("abandoned", wtx.isAbandoned()); | entry.pushKV("abandoned", wtx.isAbandoned()); | ||||
ret.push_back(entry); | ret.push_back(entry); | ||||
▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | static UniValue listaccounts(const Config &config, | ||||
const std::list<CAccountingEntry> &acentries = pwallet->laccentries; | const std::list<CAccountingEntry> &acentries = pwallet->laccentries; | ||||
for (const CAccountingEntry &entry : acentries) { | for (const CAccountingEntry &entry : acentries) { | ||||
mapAccountBalances[entry.strAccount] += entry.nCreditDebit; | mapAccountBalances[entry.strAccount] += entry.nCreditDebit; | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
for (const std::pair<std::string, Amount> &accountBalance : | for (const std::pair<std::string, Amount> &accountBalance : | ||||
mapAccountBalances) { | mapAccountBalances) { | ||||
ret.push_back( | ret.pushKV(accountBalance.first, | ||||
Pair(accountBalance.first, ValueFromAmount(accountBalance.second))); | ValueFromAmount(accountBalance.second)); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue listsinceblock(const Config &config, | static UniValue listsinceblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
▲ Show 20 Lines • Show All 931 Lines • ▼ Show 20 Lines | static UniValue getwalletinfo(const Config &config, | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | ||||
obj.pushKV("walletname", pwallet->GetName()); | obj.pushKV("walletname", pwallet->GetName()); | ||||
obj.pushKV("walletversion", pwallet->GetVersion()); | obj.pushKV("walletversion", pwallet->GetVersion()); | ||||
obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | ||||
obj.push_back(Pair("unconfirmed_balance", | obj.pushKV("unconfirmed_balance", | ||||
ValueFromAmount(pwallet->GetUnconfirmedBalance()))); | ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ||||
obj.push_back(Pair("immature_balance", | obj.pushKV("immature_balance", | ||||
ValueFromAmount(pwallet->GetImmatureBalance()))); | ValueFromAmount(pwallet->GetImmatureBalance())); | ||||
obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | ||||
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | ||||
obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | ||||
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | ||||
if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
obj.push_back( | obj.pushKV("keypoolsize_hd_internal", | ||||
Pair("keypoolsize_hd_internal", | int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | ||||
int64_t(pwallet->GetKeyPoolSize() - kpExternalSize))); | |||||
} | } | ||||
if (pwallet->IsCrypted()) { | if (pwallet->IsCrypted()) { | ||||
obj.pushKV("unlocked_until", pwallet->nRelockTime); | obj.pushKV("unlocked_until", pwallet->nRelockTime); | ||||
} | } | ||||
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())); | obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())); | ||||
if (!masterKeyID.IsNull()) { | if (!masterKeyID.IsNull()) { | ||||
obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); | obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
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.pushKV("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.pushKV("redeemScript", HexStr(redeemScript.begin(), | ||||
Pair("redeemScript", | redeemScript.end())); | ||||
HexStr(redeemScript.begin(), redeemScript.end()))); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
entry.push_back(Pair("scriptPubKey", | entry.pushKV("scriptPubKey", | ||||
HexStr(scriptPubKey.begin(), scriptPubKey.end()))); | HexStr(scriptPubKey.begin(), scriptPubKey.end())); | ||||
entry.push_back( | entry.pushKV("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue)); | ||||
Pair("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue))); | |||||
entry.pushKV("confirmations", out.nDepth); | entry.pushKV("confirmations", out.nDepth); | ||||
entry.pushKV("spendable", out.fSpendable); | entry.pushKV("spendable", out.fSpendable); | ||||
entry.pushKV("solvable", out.fSolvable); | entry.pushKV("solvable", out.fSolvable); | ||||
entry.pushKV("safe", out.fSafe); | entry.pushKV("safe", out.fSafe); | ||||
results.push_back(entry); | results.push_back(entry); | ||||
} | } | ||||
return results; | return results; | ||||
▲ Show 20 Lines • Show All 410 Lines • Show Last 20 Lines |