Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (confirms > 0) { | ||||
entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex()); | entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex()); | ||||
entry.pushKV("blockheight", wtx.m_confirm.block_height); | entry.pushKV("blockheight", wtx.m_confirm.block_height); | ||||
entry.pushKV("blockindex", wtx.m_confirm.nIndex); | entry.pushKV("blockindex", wtx.m_confirm.nIndex); | ||||
int64_t block_time; | int64_t block_time; | ||||
CHECK_NONFATAL(chain.findBlock(wtx.m_confirm.hashBlock, | CHECK_NONFATAL(chain.findBlock(wtx.m_confirm.hashBlock, | ||||
FoundBlock().time(block_time))); | FoundBlock().time(block_time))); | ||||
entry.pushKV("blocktime", block_time); | entry.pushKV("blocktime", block_time); | ||||
} else { | } else { | ||||
entry.pushKV("trusted", wtx.IsTrusted(locked_chain)); | 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()); | ||||
} | } | ||||
entry.pushKV("walletconflicts", conflicts); | entry.pushKV("walletconflicts", conflicts); | ||||
▲ Show 20 Lines • Show All 457 Lines • ▼ Show 20 Lines | static UniValue signmessage(const Config &config, | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
if (!key.SignCompact(ss.GetHash(), vchSig)) { | if (!key.SignCompact(ss.GetHash(), vchSig)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); | ||||
} | } | ||||
return EncodeBase64(vchSig.data(), vchSig.size()); | return EncodeBase64(vchSig.data(), vchSig.size()); | ||||
} | } | ||||
static Amount GetReceived(interfaces::Chain::Lock &locked_chain, | static Amount GetReceived(const CWallet &wallet, const UniValue ¶ms, | ||||
const CWallet &wallet, const UniValue ¶ms, | |||||
bool by_label) | bool by_label) | ||||
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { | EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { | ||||
std::set<CTxDestination> address_set; | std::set<CTxDestination> address_set; | ||||
if (by_label) { | if (by_label) { | ||||
// Get the set of addresses assigned to label | // Get the set of addresses assigned to label | ||||
std::string label = LabelFromValue(params[0]); | std::string label = LabelFromValue(params[0]); | ||||
address_set = wallet.GetLabelAddresses(label); | address_set = wallet.GetLabelAddresses(label); | ||||
Show All 19 Lines | static Amount GetReceived(const CWallet &wallet, const UniValue ¶ms, | ||||
} | } | ||||
// Tally | // Tally | ||||
Amount amount = Amount::zero(); | Amount amount = Amount::zero(); | ||||
for (const std::pair<const TxId, CWalletTx> &wtx_pair : wallet.mapWallet) { | for (const std::pair<const TxId, CWalletTx> &wtx_pair : wallet.mapWallet) { | ||||
const CWalletTx &wtx = wtx_pair.second; | const CWalletTx &wtx = wtx_pair.second; | ||||
TxValidationState txState; | TxValidationState txState; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!locked_chain.contextualCheckTransactionForCurrentBlock( | !wallet.chain().contextualCheckTransactionForCurrentBlock( | ||||
wallet.chainParams.GetConsensus(), *wtx.tx, txState) || | *wtx.tx, txState) || | ||||
wtx.GetDepthInMainChain() < min_depth) { | wtx.GetDepthInMainChain() < min_depth) { | ||||
continue; | continue; | ||||
} | } | ||||
for (const CTxOut &txout : wtx.tx->vout) { | for (const CTxOut &txout : wtx.tx->vout) { | ||||
CTxDestination address; | CTxDestination address; | ||||
if (ExtractDestination(txout.scriptPubKey, address) && | if (ExtractDestination(txout.scriptPubKey, address) && | ||||
wallet.IsMine(address) && address_set.count(address)) { | wallet.IsMine(address) && address_set.count(address)) { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ValueFromAmount(GetReceived(*locked_chain, *pwallet, request.params, | return ValueFromAmount(GetReceived(*pwallet, request.params, | ||||
/* by_label */ false)); | /* by_label */ false)); | ||||
} | } | ||||
static UniValue getreceivedbylabel(const Config &config, | static UniValue getreceivedbylabel(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
Show All 28 Lines | static UniValue getreceivedbylabel(const Config &config, | ||||
// Make sure the results are valid at least up to the most recent block | // Make sure the results are valid at least up to the most recent block | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
return ValueFromAmount(GetReceived(*locked_chain, *pwallet, request.params, | return ValueFromAmount(GetReceived(*pwallet, request.params, | ||||
/* by_label */ true)); | /* by_label */ true)); | ||||
} | } | ||||
static UniValue getbalance(const Config &config, | static UniValue getbalance(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
▲ Show 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | ListReceived(const Config &config, interfaces::Chain::Lock &locked_chain, | ||||
// Tally | // Tally | ||||
std::map<CTxDestination, tallyitem> mapTally; | std::map<CTxDestination, tallyitem> mapTally; | ||||
for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
TxValidationState state; | TxValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!locked_chain.contextualCheckTransactionForCurrentBlock( | !pwallet->chain().contextualCheckTransactionForCurrentBlock( | ||||
pwallet->chainParams.GetConsensus(), *wtx.tx, state)) { | *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
if (nDepth < nMinDepth) { | if (nDepth < nMinDepth) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,282 Lines • ▼ Show 20 Lines | static UniValue listunspent(const Config &config, | ||||
std::vector<COutput> vecOutputs; | std::vector<COutput> vecOutputs; | ||||
{ | { | ||||
CCoinControl cctl; | CCoinControl cctl; | ||||
cctl.m_avoid_address_reuse = false; | cctl.m_avoid_address_reuse = false; | ||||
cctl.m_min_depth = nMinDepth; | cctl.m_min_depth = nMinDepth; | ||||
cctl.m_max_depth = nMaxDepth; | cctl.m_max_depth = nMaxDepth; | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
pwallet->AvailableCoins(*locked_chain, vecOutputs, !include_unsafe, | pwallet->AvailableCoins(vecOutputs, !include_unsafe, &cctl, | ||||
&cctl, nMinimumAmount, nMaximumAmount, | nMinimumAmount, nMaximumAmount, | ||||
nMinimumSumAmount, nMaximumCount); | nMinimumSumAmount, nMaximumCount); | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
const bool avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | const bool avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | ||||
for (const COutput &out : vecOutputs) { | for (const COutput &out : vecOutputs) { | ||||
▲ Show 20 Lines • Show All 1,401 Lines • Show Last 20 Lines |