|
|
@ -739,45 +739,7 @@ UniValue getbalance(const JSONRPCRequest& request) |
|
|
|
if(request.params[2].get_bool()) |
|
|
|
if(request.params[2].get_bool()) |
|
|
|
filter = filter | ISMINE_WATCH_ONLY; |
|
|
|
filter = filter | ISMINE_WATCH_ONLY; |
|
|
|
|
|
|
|
|
|
|
|
CAmount legacyBalance = pwallet->GetLegacyBalance(filter, nMinDepth, account); |
|
|
|
return ValueFromAmount(pwallet->GetLegacyBalance(filter, nMinDepth, account)); |
|
|
|
|
|
|
|
|
|
|
|
if (request.params[0].get_str() == "*") { |
|
|
|
|
|
|
|
// Calculate total balance in a very different way from GetBalance().
|
|
|
|
|
|
|
|
// The biggest difference is that GetBalance() sums up all unspent
|
|
|
|
|
|
|
|
// TxOuts paying to the wallet, while this sums up both spent and
|
|
|
|
|
|
|
|
// unspent TxOuts paying to the wallet, and then subtracts the values of
|
|
|
|
|
|
|
|
// TxIns spending from the wallet. This also has fewer restrictions on
|
|
|
|
|
|
|
|
// which unconfirmed transactions are considered trusted.
|
|
|
|
|
|
|
|
CAmount nBalance = 0; |
|
|
|
|
|
|
|
for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { |
|
|
|
|
|
|
|
const CWalletTx& wtx = pairWtx.second; |
|
|
|
|
|
|
|
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CAmount allFee; |
|
|
|
|
|
|
|
std::string strSentAccount; |
|
|
|
|
|
|
|
std::list<COutputEntry> listReceived; |
|
|
|
|
|
|
|
std::list<COutputEntry> listSent; |
|
|
|
|
|
|
|
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); |
|
|
|
|
|
|
|
if (wtx.GetDepthInMainChain() >= nMinDepth) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
BOOST_FOREACH(const COutputEntry& r, listReceived) |
|
|
|
|
|
|
|
nBalance += r.amount; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BOOST_FOREACH(const COutputEntry& s, listSent) |
|
|
|
|
|
|
|
nBalance -= s.amount; |
|
|
|
|
|
|
|
nBalance -= allFee; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assert(nBalance == legacyBalance); |
|
|
|
|
|
|
|
return ValueFromAmount(nBalance); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string strAccount = AccountFromValue(request.params[0]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, filter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(nBalance == legacyBalance); |
|
|
|
|
|
|
|
return ValueFromAmount(nBalance); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UniValue getunconfirmedbalance(const JSONRPCRequest &request) |
|
|
|
UniValue getunconfirmedbalance(const JSONRPCRequest &request) |
|
|
@ -907,9 +869,7 @@ UniValue sendfrom(const JSONRPCRequest& request) |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
// Check funds
|
|
|
|
// Check funds
|
|
|
|
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); |
|
|
|
CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); |
|
|
|
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); |
|
|
|
|
|
|
|
assert(nBalance == legacyBalance); |
|
|
|
|
|
|
|
if (nAmount > nBalance) |
|
|
|
if (nAmount > nBalance) |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |
|
|
|
|
|
|
|
|
|
|
@ -1018,9 +978,7 @@ UniValue sendmany(const JSONRPCRequest& request) |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
EnsureWalletIsUnlocked(pwallet); |
|
|
|
|
|
|
|
|
|
|
|
// Check funds
|
|
|
|
// Check funds
|
|
|
|
CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); |
|
|
|
CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); |
|
|
|
CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); |
|
|
|
|
|
|
|
assert(nBalance == legacyBalance); |
|
|
|
|
|
|
|
if (totalAmount > nBalance) |
|
|
|
if (totalAmount > nBalance) |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |
|
|
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |
|
|
|
|
|
|
|
|
|
|
|