@@ -739,45 +739,7 @@ UniValue getbalance(const JSONRPCRequest& request)
739
739
if (request.params [2 ].get_bool ())
740
740
filter = filter | ISMINE_WATCH_ONLY;
741
741
742
- CAmount legacyBalance = pwallet->GetLegacyBalance (filter, nMinDepth, account);
743
-
744
- if (request.params [0 ].get_str () == " *" ) {
745
- // Calculate total balance in a very different way from GetBalance().
746
- // The biggest difference is that GetBalance() sums up all unspent
747
- // TxOuts paying to the wallet, while this sums up both spent and
748
- // unspent TxOuts paying to the wallet, and then subtracts the values of
749
- // TxIns spending from the wallet. This also has fewer restrictions on
750
- // which unconfirmed transactions are considered trusted.
751
- CAmount nBalance = 0 ;
752
- for (const std::pair<uint256, CWalletTx>& pairWtx : pwallet->mapWallet ) {
753
- const CWalletTx& wtx = pairWtx.second ;
754
- if (!CheckFinalTx (wtx) || wtx.GetBlocksToMaturity () > 0 || wtx.GetDepthInMainChain () < 0 )
755
- continue ;
756
-
757
- CAmount allFee;
758
- std::string strSentAccount;
759
- std::list<COutputEntry> listReceived;
760
- std::list<COutputEntry> listSent;
761
- wtx.GetAmounts (listReceived, listSent, allFee, strSentAccount, filter);
762
- if (wtx.GetDepthInMainChain () >= nMinDepth)
763
- {
764
- BOOST_FOREACH (const COutputEntry& r, listReceived)
765
- nBalance += r.amount ;
766
- }
767
- BOOST_FOREACH (const COutputEntry& s, listSent)
768
- nBalance -= s.amount ;
769
- nBalance -= allFee;
770
- }
771
- assert (nBalance == legacyBalance);
772
- return ValueFromAmount (nBalance);
773
- }
774
-
775
- std::string strAccount = AccountFromValue (request.params [0 ]);
776
-
777
- CAmount nBalance = pwallet->GetAccountBalance (strAccount, nMinDepth, filter);
778
-
779
- assert (nBalance == legacyBalance);
780
- return ValueFromAmount (nBalance);
742
+ return ValueFromAmount (pwallet->GetLegacyBalance (filter, nMinDepth, account));
781
743
}
782
744
783
745
UniValue getunconfirmedbalance (const JSONRPCRequest &request)
@@ -907,9 +869,7 @@ UniValue sendfrom(const JSONRPCRequest& request)
907
869
EnsureWalletIsUnlocked (pwallet);
908
870
909
871
// Check funds
910
- CAmount nBalance = pwallet->GetAccountBalance (strAccount, nMinDepth, ISMINE_SPENDABLE);
911
- CAmount legacyBalance = pwallet->GetLegacyBalance (ISMINE_SPENDABLE, nMinDepth, &strAccount);
912
- assert (nBalance == legacyBalance);
872
+ CAmount nBalance = pwallet->GetLegacyBalance (ISMINE_SPENDABLE, nMinDepth, &strAccount);
913
873
if (nAmount > nBalance)
914
874
throw JSONRPCError (RPC_WALLET_INSUFFICIENT_FUNDS, " Account has insufficient funds" );
915
875
@@ -1018,9 +978,7 @@ UniValue sendmany(const JSONRPCRequest& request)
1018
978
EnsureWalletIsUnlocked (pwallet);
1019
979
1020
980
// Check funds
1021
- CAmount nBalance = pwallet->GetAccountBalance (strAccount, nMinDepth, ISMINE_SPENDABLE);
1022
- CAmount legacyBalance = pwallet->GetLegacyBalance (ISMINE_SPENDABLE, nMinDepth, &strAccount);
1023
- assert (nBalance == legacyBalance);
981
+ CAmount nBalance = pwallet->GetLegacyBalance (ISMINE_SPENDABLE, nMinDepth, &strAccount);
1024
982
if (totalAmount > nBalance)
1025
983
throw JSONRPCError (RPC_WALLET_INSUFFICIENT_FUNDS, " Account has insufficient funds" );
1026
984
0 commit comments