diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-01-23 09:58:42 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2017-04-26 06:36:38 -0400 |
commit | 82b7dc373afff277d3083d09e68c6b69778f312f (patch) | |
tree | 0359a2ebea49e644a60ef76f2e65c37bb6da3a28 /src/wallet/rpcwallet.cpp | |
parent | bd9ec0ef1ea73209ba9e491e4b7847c895ca7a2f (diff) | |
download | bitcoin-82b7dc373afff277d3083d09e68c6b69778f312f.tar.xz |
[wallet] Add GetLegacyBalance method to simplify getbalance RPC
This adds a simpler new implementation of getbalance logic along with asserts
to confirm it behaves identically to the old logic. The old logic is removed in
the next commit.
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r-- | src/wallet/rpcwallet.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f8006a6255..98efb8bf6d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -729,6 +729,8 @@ UniValue getbalance(const JSONRPCRequest& request) if (request.params.size() == 0) return ValueFromAmount(pwallet->GetBalance()); + const std::string* account = request.params[0].get_str() != "*" ? &request.params[0].get_str() : nullptr; + int nMinDepth = 1; if (request.params.size() > 1) nMinDepth = request.params[1].get_int(); @@ -737,6 +739,8 @@ UniValue getbalance(const JSONRPCRequest& request) if(request.params[2].get_bool()) filter = filter | ISMINE_WATCH_ONLY; + CAmount legacyBalance = 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 @@ -764,6 +768,7 @@ UniValue getbalance(const JSONRPCRequest& request) nBalance -= s.amount; nBalance -= allFee; } + assert(nBalance == legacyBalance); return ValueFromAmount(nBalance); } @@ -771,6 +776,7 @@ UniValue getbalance(const JSONRPCRequest& request) CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, filter); + assert(nBalance == legacyBalance); return ValueFromAmount(nBalance); } @@ -902,6 +908,8 @@ UniValue sendfrom(const JSONRPCRequest& request) // Check funds CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); + assert(nBalance == legacyBalance); if (nAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); @@ -1011,6 +1019,8 @@ UniValue sendmany(const JSONRPCRequest& request) // Check funds CAmount nBalance = pwallet->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount legacyBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount); + assert(nBalance == legacyBalance); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); |