Skip to content

Commit 7501977

Browse files
committed
cli -getinfo: use getbalances instead of deprecated getwalletinfo balance
1 parent 661bd5d commit 7501977

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
228228
const int ID_NETWORKINFO = 0;
229229
const int ID_BLOCKCHAININFO = 1;
230230
const int ID_WALLETINFO = 2;
231+
const int ID_BALANCES = 3;
231232

232233
/** Create a simulated `getinfo` request. */
233234
UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
@@ -239,16 +240,17 @@ class GetinfoRequestHandler: public BaseRequestHandler
239240
result.push_back(JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO));
240241
result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, ID_BLOCKCHAININFO));
241242
result.push_back(JSONRPCRequestObj("getwalletinfo", NullUniValue, ID_WALLETINFO));
243+
result.push_back(JSONRPCRequestObj("getbalances", NullUniValue, ID_BALANCES));
242244
return result;
243245
}
244246

245247
/** Collect values from the batch and form a simulated `getinfo` reply. */
246248
UniValue ProcessReply(const UniValue &batch_in) override
247249
{
248250
UniValue result(UniValue::VOBJ);
249-
std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, 3);
250-
// Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on
251-
// getwalletinfo() is allowed to fail in case there is no wallet.
251+
std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, batch_in.size());
252+
// Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on;
253+
// getwalletinfo() and getbalances() are allowed to fail if there is no wallet.
252254
if (!batch[ID_NETWORKINFO]["error"].isNull()) {
253255
return batch[ID_NETWORKINFO];
254256
}
@@ -265,13 +267,15 @@ class GetinfoRequestHandler: public BaseRequestHandler
265267
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
266268
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));
267269
if (!batch[ID_WALLETINFO]["result"].isNull()) {
268-
result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
269270
result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]);
270271
if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) {
271272
result.pushKV("unlocked_until", batch[ID_WALLETINFO]["result"]["unlocked_until"]);
272273
}
273274
result.pushKV("paytxfee", batch[ID_WALLETINFO]["result"]["paytxfee"]);
274275
}
276+
if (!batch[ID_BALANCES]["result"].isNull()) {
277+
result.pushKV("balance", batch[ID_BALANCES]["result"]["mine"]["trusted"]);
278+
}
275279
result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
276280
result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
277281
return JSONRPCReplyObj(result, NullUniValue, 1);

0 commit comments

Comments
 (0)