From 0ec255139be3745a135386e9db957fe81bc3d833 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Tue, 10 Jun 2025 12:10:19 -0700 Subject: [PATCH 1/2] wallet, rpc: Remove deprecated balances from getwalletinfo --- src/wallet/rpc/wallet.cpp | 7 ------- test/functional/wallet_balance.py | 3 --- test/functional/wallet_basic.py | 9 ++++----- test/functional/wallet_multiwallet.py | 5 ++--- test/functional/wallet_reorgsrestore.py | 8 ++++---- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 4bd4851609d..f1a613bc6bc 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -42,9 +42,6 @@ static RPCHelpMan getwalletinfo() {RPCResult::Type::STR, "walletname", "the wallet name"}, {RPCResult::Type::NUM, "walletversion", "the wallet version"}, {RPCResult::Type::STR, "format", "the database format (only sqlite)"}, - {RPCResult::Type::STR_AMOUNT, "balance", "DEPRECATED. Identical to getbalances().mine.trusted"}, - {RPCResult::Type::STR_AMOUNT, "unconfirmed_balance", "DEPRECATED. Identical to getbalances().mine.untrusted_pending"}, - {RPCResult::Type::STR_AMOUNT, "immature_balance", "DEPRECATED. Identical to getbalances().mine.immature"}, {RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"}, {RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"}, {RPCResult::Type::NUM, "keypoolsize_hd_internal", /*optional=*/true, "how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)"}, @@ -82,13 +79,9 @@ static RPCHelpMan getwalletinfo() UniValue obj(UniValue::VOBJ); size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); - const auto bal = GetBalance(*pwallet); obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); obj.pushKV("format", pwallet->GetDatabase().Format()); - obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted)); - obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending)); - obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); obj.pushKV("keypoolsize", (int64_t)kpExternalSize); diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index 4efc0169eb3..62160c635ad 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -170,9 +170,6 @@ class WalletTest(BitcoinTestFramework): # getunconfirmedbalance assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent - # getwalletinfo.unconfirmed_balance - assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60')) - assert_equal(self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('30') - fee_node_1) test_balances(fee_node_1=Decimal('0.01')) diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index ce2c1596210..23c1616f9c6 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -69,9 +69,9 @@ class WalletTest(BitcoinTestFramework): self.generate(self.nodes[0], 1, sync_fun=self.no_op) - walletinfo = self.nodes[0].getwalletinfo() - assert_equal(walletinfo['immature_balance'], 50) - assert_equal(walletinfo['balance'], 0) + balances = self.nodes[0].getbalances() + assert_equal(balances["mine"]["immature"], 50) + assert_equal(balances["mine"]["trusted"], 0) self.sync_all(self.nodes[0:3]) self.generate(self.nodes[1], COINBASE_MATURITY + 1, sync_fun=lambda: self.sync_all(self.nodes[0:3])) @@ -118,8 +118,7 @@ class WalletTest(BitcoinTestFramework): # but 10 will go to node2 and the rest will go to node0 balance = self.nodes[0].getbalance() assert_equal(set([txout1['value'], txout2['value']]), set([10, balance])) - walletinfo = self.nodes[0].getwalletinfo() - assert_equal(walletinfo['immature_balance'], 0) + assert_equal(self.nodes[0].getbalances()["mine"]["immature"], 0) # Have node0 mine a block, thus it will collect its own fee. self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3])) diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 87c8f627552..60fc98e3c28 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -185,8 +185,7 @@ class MultiWalletTest(BitcoinTestFramework): self.nodes[0].loadwallet("w5") assert_equal(set(node.listwallets()), {"w4", "w5"}) w5 = wallet("w5") - w5_info = w5.getwalletinfo() - assert_equal(w5_info['immature_balance'], 50) + assert_equal(w5.getbalances()["mine"]["immature"], 50) competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir') os.mkdir(competing_wallet_dir) @@ -208,7 +207,7 @@ class MultiWalletTest(BitcoinTestFramework): self.generatetoaddress(node, nblocks=1, address=wallets[0].getnewaddress(), sync_fun=self.no_op) for wallet_name, wallet in zip(wallet_names, wallets): info = wallet.getwalletinfo() - assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0) + assert_equal(wallet.getbalances()["mine"]["immature"], 50 if wallet is wallets[0] else 0) assert_equal(info['walletname'], wallet_name) # accessing invalid wallet fails diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py index 73ca173f237..1567fb30d0e 100755 --- a/test/functional/wallet_reorgsrestore.py +++ b/test/functional/wallet_reorgsrestore.py @@ -100,7 +100,7 @@ class ReorgsRestoreTest(BitcoinTestFramework): # Restart to ensure node and wallet are flushed self.restart_node(0) wallet = node.get_wallet_rpc("reorg_crash") - assert_greater_than(wallet.getwalletinfo()['immature_balance'], 0) + assert_greater_than(wallet.getbalances()["mine"]["immature"], 0) # Disconnect tip and sync wallet state tip = wallet.getbestblockhash() @@ -108,7 +108,7 @@ class ReorgsRestoreTest(BitcoinTestFramework): wallet.syncwithvalidationinterfacequeue() # Tip was disconnected, ensure coinbase has been abandoned - assert_equal(wallet.getwalletinfo()['immature_balance'], 0) + assert_equal(wallet.getbalances()["mine"]["immature"], 0) coinbase_tx_id = wallet.getblock(tip, verbose=1)["tx"][0] assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], True) @@ -131,12 +131,12 @@ class ReorgsRestoreTest(BitcoinTestFramework): assert(node.getbestblockhash() != tip) # Ensure wallet state is consistent now assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], True) - assert_equal(wallet.getwalletinfo()['immature_balance'], 0) + assert_equal(wallet.getbalances()["mine"]["immature"], 0) # And finally, verify the state if the block ends up being into the best chain again node.reconsiderblock(tip) assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], False) - assert_greater_than(wallet.getwalletinfo()['immature_balance'], 0) + assert_greater_than(wallet.getbalances()["mine"]["immature"], 0) def run_test(self): # Send a tx from which to conflict outputs later From c3fe85e2d6dd4f251a62a99fd891b0fa370f9712 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Tue, 10 Jun 2025 12:11:07 -0700 Subject: [PATCH 2/2] wallet, rpc, test: Remove deprecated getunconfirmedbalance --- src/wallet/rpc/coins.cpp | 23 ----------------------- src/wallet/rpc/wallet.cpp | 2 -- test/functional/wallet_balance.py | 3 --- 3 files changed, 28 deletions(-) diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index cce9b26babe..16d93de1216 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -214,29 +214,6 @@ RPCHelpMan getbalance() }; } -RPCHelpMan getunconfirmedbalance() -{ - return RPCHelpMan{"getunconfirmedbalance", - "DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n", - {}, - RPCResult{RPCResult::Type::NUM, "", "The balance"}, - RPCExamples{""}, - [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue -{ - const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return UniValue::VNULL; - - // Make sure the results are valid at least up to the most recent block - // the user could have gotten from another RPC command prior to now - pwallet->BlockUntilSyncedToCurrentChain(); - - LOCK(pwallet->cs_wallet); - - return ValueFromAmount(GetBalance(*pwallet).m_mine_untrusted_pending); -}, - }; -} - RPCHelpMan lockunspent() { return RPCHelpMan{ diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index f1a613bc6bc..a86d92af836 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -956,7 +956,6 @@ RPCHelpMan restorewallet(); RPCHelpMan getreceivedbyaddress(); RPCHelpMan getreceivedbylabel(); RPCHelpMan getbalance(); -RPCHelpMan getunconfirmedbalance(); RPCHelpMan lockunspent(); RPCHelpMan listlockunspent(); RPCHelpMan getbalances(); @@ -1016,7 +1015,6 @@ std::span GetWalletRPCCommands() {"wallet", &getreceivedbyaddress}, {"wallet", &getreceivedbylabel}, {"wallet", &gettransaction}, - {"wallet", &getunconfirmedbalance}, {"wallet", &getbalances}, {"wallet", &getwalletinfo}, {"wallet", &importdescriptors}, diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index 62160c635ad..c3d9596b8a0 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -167,9 +167,6 @@ class WalletTest(BitcoinTestFramework): # TODO: fix getbalance tracking of coin spentness depth assert_equal(self.nodes[0].getbalance(minconf=1), Decimal('0')) assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0')) - # getunconfirmedbalance - assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend - assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent test_balances(fee_node_1=Decimal('0.01'))