@ -729,6 +729,8 @@ UniValue getbalance(const JSONRPCRequest& request)
if ( request . params . size ( ) = = 0 )
if ( request . params . size ( ) = = 0 )
return ValueFromAmount ( pwallet - > GetBalance ( ) ) ;
return ValueFromAmount ( pwallet - > GetBalance ( ) ) ;
const std : : string * account = request . params [ 0 ] . get_str ( ) ! = " * " ? & request . params [ 0 ] . get_str ( ) : nullptr ;
int nMinDepth = 1 ;
int nMinDepth = 1 ;
if ( request . params . size ( ) > 1 )
if ( request . params . size ( ) > 1 )
nMinDepth = request . params [ 1 ] . get_int ( ) ;
nMinDepth = request . params [ 1 ] . get_int ( ) ;
@ -737,6 +739,8 @@ 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 ) ;
if ( request . params [ 0 ] . get_str ( ) = = " * " ) {
if ( request . params [ 0 ] . get_str ( ) = = " * " ) {
// Calculate total balance in a very different way from GetBalance().
// Calculate total balance in a very different way from GetBalance().
// The biggest difference is that GetBalance() sums up all unspent
// The biggest difference is that GetBalance() sums up all unspent
@ -764,6 +768,7 @@ UniValue getbalance(const JSONRPCRequest& request)
nBalance - = s . amount ;
nBalance - = s . amount ;
nBalance - = allFee ;
nBalance - = allFee ;
}
}
assert ( nBalance = = legacyBalance ) ;
return ValueFromAmount ( nBalance ) ;
return ValueFromAmount ( nBalance ) ;
}
}
@ -771,6 +776,7 @@ UniValue getbalance(const JSONRPCRequest& request)
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , filter ) ;
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , filter ) ;
assert ( nBalance = = legacyBalance ) ;
return ValueFromAmount ( nBalance ) ;
return ValueFromAmount ( nBalance ) ;
}
}
@ -902,6 +908,8 @@ UniValue sendfrom(const JSONRPCRequest& request)
// Check funds
// Check funds
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
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 " ) ;
@ -1011,6 +1019,8 @@ UniValue sendmany(const JSONRPCRequest& request)
// Check funds
// Check funds
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
CAmount nBalance = pwallet - > GetAccountBalance ( strAccount , nMinDepth , ISMINE_SPENDABLE ) ;
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 " ) ;