diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index beda4fdd5..34f044ea9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3538,6 +3538,9 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) " \"walletname\": xxxxx, (string) the wallet name\n" " \"walletversion\": xxxxx, (numeric) the wallet version\n" " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n" + " \"available_balance\": xxxxxxx, (numeric) balance minus stakes in " + CURRENCY_UNIT + "\n" + " \"staked_claim_balance\": xxxxxxx, (numeric) total in claim reservations in " + CURRENCY_UNIT + "\n" + " \"staked_support_balance\": xxxxxxx, (numeric) total in support reservations in " + CURRENCY_UNIT + "\n" " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n" " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n" " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n" @@ -3566,7 +3569,13 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); - obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); + auto balance = pwallet->GetBalance(); + auto claims = pwallet->GetBalance(ISMINE_CLAIM); + auto supports = pwallet->GetBalance(ISMINE_SUPPORT); + obj.pushKV("balance", ValueFromAmount(balance)); + obj.pushKV("available_balance", ValueFromAmount(balance - claims - supports)); + obj.pushKV("staked_claim_balance", ValueFromAmount(claims)); + obj.pushKV("staked_support_balance", ValueFromAmount(supports)); obj.pushKV("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance())); obj.pushKV("immature_balance", ValueFromAmount(pwallet->GetImmatureBalance())); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); diff --git a/src/wallet/test/claim_rpc_tests.cpp b/src/wallet/test/claim_rpc_tests.cpp index 5a1f65195..8c309d7ed 100644 --- a/src/wallet/test/claim_rpc_tests.cpp +++ b/src/wallet/test/claim_rpc_tests.cpp @@ -151,6 +151,17 @@ uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) { } } +void ValidateBalance(double claims, double supports) { + rpcfn_type rpc_method = tableRPC["getwalletinfo"]->actor; + JSONRPCRequest req; + req.URI = "/wallet/tester_wallet"; + req.params = UniValue(UniValue::VARR); + UniValue results = rpc_method(req); + BOOST_CHECK_EQUAL(claims, results["staked_claim_balance"].get_real()); + BOOST_CHECK_EQUAL(supports, results["staked_support_balance"].get_real()); + BOOST_CHECK_EQUAL(claims + supports, results["balance"].get_real() - results["available_balance"].get_real()); +} + void AddClaimSupportThenRemove() { generateBlock(155); BOOST_CHECK_EQUAL(AvailableBalance(), 55.0); @@ -190,6 +201,8 @@ void AddClaimSupportThenRemove() { BOOST_CHECK_EQUAL(looked[1]["txid"].get_str(), spid.GetHex()); BOOST_CHECK_EQUAL(looked[1]["supported_claimid"].get_str(), clid); + ValidateBalance(1.0, 0.5); + // abandon support auto aid1 = AbandonAClaim(spid, true); BOOST_CHECK(!aid1.IsNull());