Skip to content

Commit f27898c

Browse files
committed
Merge bitcoin/bitcoin#32721: wallet, rpc: Remove deprecated balances from getwalletinfo and getunconfirmedbalance
c3fe85e wallet, rpc, test: Remove deprecated getunconfirmedbalance (Ava Chow) 0ec2551 wallet, rpc: Remove deprecated balances from getwalletinfo (Ava Chow) Pull request description: `getwalletinfo` result fields `balance`, `immature_balance`, and `unconfirmed_balance`, and the `getunconfirmedbalance` RPC have all been deprecated since 0.19.0. It's been long enough that they should either be removed or undeprecated. The functionality provided by these RPCs is provided by `getbalances`. ACKs for top commit: davidgumberg: ACK bitcoin/bitcoin@c3fe85e rkrux: ACK c3fe85e BrandonOdiwuor: ACK c3fe85e removing the deprecated `balance, unconfirmed_balance, immature_balance` fields from `getwalletinfo` and `getunconfirmedbalance` RPCs, as this infomation can be found on the `getbalances` RPC w0xlt: reACK bitcoin/bitcoin@c3fe85e Tree-SHA512: c7c4acfd9cabc7517ba813b95281a6c6a717a417312afd9346298669b4f7bd37724ad977148ce42db7fd47fc3d1f5a8482d8ff2e7b9cb74756b171a5b8b91ef2
2 parents 8578fab + c3fe85e commit f27898c

File tree

6 files changed

+10
-50
lines changed

6 files changed

+10
-50
lines changed

src/wallet/rpc/coins.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,6 @@ RPCHelpMan getbalance()
214214
};
215215
}
216216

217-
RPCHelpMan getunconfirmedbalance()
218-
{
219-
return RPCHelpMan{"getunconfirmedbalance",
220-
"DEPRECATED\nIdentical to getbalances().mine.untrusted_pending\n",
221-
{},
222-
RPCResult{RPCResult::Type::NUM, "", "The balance"},
223-
RPCExamples{""},
224-
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
225-
{
226-
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
227-
if (!pwallet) return UniValue::VNULL;
228-
229-
// Make sure the results are valid at least up to the most recent block
230-
// the user could have gotten from another RPC command prior to now
231-
pwallet->BlockUntilSyncedToCurrentChain();
232-
233-
LOCK(pwallet->cs_wallet);
234-
235-
return ValueFromAmount(GetBalance(*pwallet).m_mine_untrusted_pending);
236-
},
237-
};
238-
}
239-
240217
RPCHelpMan lockunspent()
241218
{
242219
return RPCHelpMan{

src/wallet/rpc/wallet.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ static RPCHelpMan getwalletinfo()
4242
{RPCResult::Type::STR, "walletname", "the wallet name"},
4343
{RPCResult::Type::NUM, "walletversion", "the wallet version"},
4444
{RPCResult::Type::STR, "format", "the database format (only sqlite)"},
45-
{RPCResult::Type::STR_AMOUNT, "balance", "DEPRECATED. Identical to getbalances().mine.trusted"},
46-
{RPCResult::Type::STR_AMOUNT, "unconfirmed_balance", "DEPRECATED. Identical to getbalances().mine.untrusted_pending"},
47-
{RPCResult::Type::STR_AMOUNT, "immature_balance", "DEPRECATED. Identical to getbalances().mine.immature"},
4845
{RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"},
4946
{RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"},
5047
{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)"},
@@ -86,13 +83,9 @@ static RPCHelpMan getwalletinfo()
8683
UniValue obj(UniValue::VOBJ);
8784

8885
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
89-
const auto bal = GetBalance(*pwallet);
9086
obj.pushKV("walletname", pwallet->GetName());
9187
obj.pushKV("walletversion", pwallet->GetVersion());
9288
obj.pushKV("format", pwallet->GetDatabase().Format());
93-
obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted));
94-
obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending));
95-
obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature));
9689
obj.pushKV("txcount", (int)pwallet->mapWallet.size());
9790
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
9891

@@ -973,7 +966,6 @@ RPCHelpMan restorewallet();
973966
RPCHelpMan getreceivedbyaddress();
974967
RPCHelpMan getreceivedbylabel();
975968
RPCHelpMan getbalance();
976-
RPCHelpMan getunconfirmedbalance();
977969
RPCHelpMan lockunspent();
978970
RPCHelpMan listlockunspent();
979971
RPCHelpMan getbalances();
@@ -1033,7 +1025,6 @@ std::span<const CRPCCommand> GetWalletRPCCommands()
10331025
{"wallet", &getreceivedbyaddress},
10341026
{"wallet", &getreceivedbylabel},
10351027
{"wallet", &gettransaction},
1036-
{"wallet", &getunconfirmedbalance},
10371028
{"wallet", &getbalances},
10381029
{"wallet", &getwalletinfo},
10391030
{"wallet", &importdescriptors},

test/functional/wallet_balance.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ def test_balances(*, fee_node_1=0):
167167
# TODO: fix getbalance tracking of coin spentness depth
168168
assert_equal(self.nodes[0].getbalance(minconf=1), Decimal('0'))
169169
assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0'))
170-
# getunconfirmedbalance
171-
assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend
172-
assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent
173-
# getwalletinfo.unconfirmed_balance
174-
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60'))
175-
assert_equal(self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('30') - fee_node_1)
176170

177171
test_balances(fee_node_1=Decimal('0.01'))
178172

test/functional/wallet_basic.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def run_test(self):
6969

7070
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
7171

72-
walletinfo = self.nodes[0].getwalletinfo()
73-
assert_equal(walletinfo['immature_balance'], 50)
74-
assert_equal(walletinfo['balance'], 0)
72+
balances = self.nodes[0].getbalances()
73+
assert_equal(balances["mine"]["immature"], 50)
74+
assert_equal(balances["mine"]["trusted"], 0)
7575

7676
self.sync_all(self.nodes[0:3])
7777
self.generate(self.nodes[1], COINBASE_MATURITY + 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
@@ -118,8 +118,7 @@ def run_test(self):
118118
# but 10 will go to node2 and the rest will go to node0
119119
balance = self.nodes[0].getbalance()
120120
assert_equal(set([txout1['value'], txout2['value']]), set([10, balance]))
121-
walletinfo = self.nodes[0].getwalletinfo()
122-
assert_equal(walletinfo['immature_balance'], 0)
121+
assert_equal(self.nodes[0].getbalances()["mine"]["immature"], 0)
123122

124123
# Have node0 mine a block, thus it will collect its own fee.
125124
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))

test/functional/wallet_multiwallet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ def wallet_file(name):
203203
self.nodes[0].loadwallet("w5")
204204
assert_equal(set(node.listwallets()), {"w4", "w5"})
205205
w5 = wallet("w5")
206-
w5_info = w5.getwalletinfo()
207-
assert_equal(w5_info['immature_balance'], 50)
206+
assert_equal(w5.getbalances()["mine"]["immature"], 50)
208207

209208
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
210209
os.mkdir(competing_wallet_dir)
@@ -226,7 +225,7 @@ def wallet_file(name):
226225
self.generatetoaddress(node, nblocks=1, address=wallets[0].getnewaddress(), sync_fun=self.no_op)
227226
for wallet_name, wallet in zip(wallet_names, wallets):
228227
info = wallet.getwalletinfo()
229-
assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0)
228+
assert_equal(wallet.getbalances()["mine"]["immature"], 50 if wallet is wallets[0] else 0)
230229
assert_equal(info['walletname'], wallet_name)
231230

232231
# accessing invalid wallet fails

test/functional/wallet_reorgsrestore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def test_reorg_handling_during_unclean_shutdown(self):
100100
# Restart to ensure node and wallet are flushed
101101
self.restart_node(0)
102102
wallet = node.get_wallet_rpc("reorg_crash")
103-
assert_greater_than(wallet.getwalletinfo()['immature_balance'], 0)
103+
assert_greater_than(wallet.getbalances()["mine"]["immature"], 0)
104104

105105
# Disconnect tip and sync wallet state
106106
tip = wallet.getbestblockhash()
107107
wallet.invalidateblock(tip)
108108
wallet.syncwithvalidationinterfacequeue()
109109

110110
# Tip was disconnected, ensure coinbase has been abandoned
111-
assert_equal(wallet.getwalletinfo()['immature_balance'], 0)
111+
assert_equal(wallet.getbalances()["mine"]["immature"], 0)
112112
coinbase_tx_id = wallet.getblock(tip, verbose=1)["tx"][0]
113113
assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], True)
114114

@@ -131,12 +131,12 @@ def test_reorg_handling_during_unclean_shutdown(self):
131131
assert(node.getbestblockhash() != tip)
132132
# Ensure wallet state is consistent now
133133
assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], True)
134-
assert_equal(wallet.getwalletinfo()['immature_balance'], 0)
134+
assert_equal(wallet.getbalances()["mine"]["immature"], 0)
135135

136136
# And finally, verify the state if the block ends up being into the best chain again
137137
node.reconsiderblock(tip)
138138
assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], False)
139-
assert_greater_than(wallet.getwalletinfo()['immature_balance'], 0)
139+
assert_greater_than(wallet.getbalances()["mine"]["immature"], 0)
140140

141141
def run_test(self):
142142
# Send a tx from which to conflict outputs later

0 commit comments

Comments
 (0)