Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | static UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static CTransactionRef SendMoney(interfaces::Chain::Lock &locked_chain, | static CTransactionRef SendMoney(interfaces::Chain::Lock &locked_chain, | ||||
CWallet *const pwallet, | CWallet *const pwallet, | ||||
const CTxDestination &address, Amount nValue, | const CTxDestination &address, Amount nValue, | ||||
bool fSubtractFeeFromAmount, | bool fSubtractFeeFromAmount, | ||||
mapValue_t mapValue) { | mapValue_t mapValue) { | ||||
Amount curBalance = pwallet->GetBalance(); | Amount curBalance = pwallet->GetBalance().m_mine_trusted; | ||||
// Check amount | // Check amount | ||||
if (nValue <= Amount::zero()) { | if (nValue <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); | ||||
} | } | ||||
if (nValue > curBalance) { | if (nValue > curBalance) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | ||||
▲ Show 20 Lines • Show All 517 Lines • ▼ Show 20 Lines | if (!dummy_value.isNull() && dummy_value.get_str() != "*") { | ||||
"dummy first argument must be excluded or set to \"*\"."); | "dummy first argument must be excluded or set to \"*\"."); | ||||
} | } | ||||
int min_depth = 0; | int min_depth = 0; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
min_depth = request.params[1].get_int(); | min_depth = request.params[1].get_int(); | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | bool include_watchonly = false; | ||||
if (!request.params[2].isNull() && request.params[2].get_bool()) { | if (!request.params[2].isNull() && request.params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | include_watchonly = true; | ||||
} | } | ||||
return ValueFromAmount(pwallet->GetBalance(filter, min_depth)); | const auto bal = pwallet->GetBalance(min_depth); | ||||
return ValueFromAmount(bal.m_mine_trusted + (include_watchonly | |||||
? bal.m_watchonly_trusted | |||||
: Amount::zero())); | |||||
} | } | ||||
static UniValue getunconfirmedbalance(const Config &config, | static UniValue getunconfirmedbalance(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(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
Show All 13 Lines | static UniValue getunconfirmedbalance(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(pwallet->GetUnconfirmedBalance()); | return ValueFromAmount(pwallet->GetBalance().m_mine_untrusted_pending); | ||||
} | } | ||||
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | static UniValue sendmany(const Config &config, 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(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
▲ Show 20 Lines • Show All 2,004 Lines • ▼ Show 20 Lines | static UniValue getwalletinfo(const Config &config, | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | ||||
const auto bal = pwallet->GetBalance(); | |||||
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(bal.m_mine_trusted)); | ||||
obj.pushKV("unconfirmed_balance", | obj.pushKV("unconfirmed_balance", | ||||
ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ValueFromAmount(bal.m_mine_untrusted_pending)); | ||||
obj.pushKV("immature_balance", | obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); | ||||
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 seed_id = pwallet->GetHDChain().seed_id; | CKeyID seed_id = pwallet->GetHDChain().seed_id; | ||||
if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
obj.pushKV("keypoolsize_hd_internal", | obj.pushKV("keypoolsize_hd_internal", | ||||
int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,838 Lines • Show Last 20 Lines |