aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-04-10 12:50:24 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-04-10 12:50:51 -0400
commit6ab96ec5469ceea8544fb07e31118c295dbe57ca (patch)
tree362e17219dded7fcdc5bd7ada6ffa4a4333b7f37 /src
parentd84c9aa25d8b86d7b3ff2205560986f012da727a (diff)
parent5df0877f91f4ed59031b0d7dcd66780df87ac1af (diff)
Merge #18574: cli: call getbalances.ismine.trusted instead of getwalletinfo.balance
5df0877f91f4ed59031b0d7dcd66780df87ac1af test: update and harden interface_bitcoin_cli tests (Jon Atack) 75019774c96795ef1a57af2a92dd9491f5065cc5 cli -getinfo: use getbalances instead of deprecated getwalletinfo balance (Jon Atack) Pull request description: Extracted from #18453 to preserve that PR as a discussion on multiwallet RPC/CLI. This PR updates `bitcoin-cli -getinfo` to fetch the wallet balance from `getbalances` in order to no longer depend on `getwalletinfo.balance` which was deprecated a year ago in facfb41. I found this when removing the getwalletinfo() `balance`, `unconfirmed_balance`, and `immature_balance` fields to see what broke from depending on them. I didn't see any perceivable change in `-getinfo` run time from the change. Test coverage for this change is provided by `test/functional/interface_bitcoin_cli.py`, which the second commit updates to (a) no longer depend on getwalletinfo.balances and (b) test the -getinfo blockcount and balance fields against non-default, non-zero values. ACKs for top commit: robot-visions: ACK 5df0877 MarcoFalke: ACK 5df0877 vasild: re-ACK 5df0877f9 promag: Code review ACK 5df0877f91f4ed59031b0d7dcd66780df87ac1af. theStack: ACK https://github.com/bitcoin/bitcoin/commit/5df0877f91f4ed59031b0d7dcd66780df87ac1af Tree-SHA512: 0dd8c62f915b1c0112e42b132dcf74a141bdd1f51e7c17d4a698b374ec296f4f9836f7058dbe237cf24f9bfb32ea5000e14f7089e2e86472d9c6a175be26e910
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-cli.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 6982eaab61..a602688e64 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -228,6 +228,7 @@ public:
const int ID_NETWORKINFO = 0;
const int ID_BLOCKCHAININFO = 1;
const int ID_WALLETINFO = 2;
+ const int ID_BALANCES = 3;
/** Create a simulated `getinfo` request. */
UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
@@ -239,6 +240,7 @@ public:
result.push_back(JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO));
result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, ID_BLOCKCHAININFO));
result.push_back(JSONRPCRequestObj("getwalletinfo", NullUniValue, ID_WALLETINFO));
+ result.push_back(JSONRPCRequestObj("getbalances", NullUniValue, ID_BALANCES));
return result;
}
@@ -246,9 +248,9 @@ public:
UniValue ProcessReply(const UniValue &batch_in) override
{
UniValue result(UniValue::VOBJ);
- std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, 3);
- // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on
- // getwalletinfo() is allowed to fail in case there is no wallet.
+ std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, batch_in.size());
+ // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on;
+ // getwalletinfo() and getbalances() are allowed to fail if there is no wallet.
if (!batch[ID_NETWORKINFO]["error"].isNull()) {
return batch[ID_NETWORKINFO];
}
@@ -265,13 +267,15 @@ public:
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));
if (!batch[ID_WALLETINFO]["result"].isNull()) {
- result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]);
if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) {
result.pushKV("unlocked_until", batch[ID_WALLETINFO]["result"]["unlocked_until"]);
}
result.pushKV("paytxfee", batch[ID_WALLETINFO]["result"]["paytxfee"]);
}
+ if (!batch[ID_BALANCES]["result"].isNull()) {
+ result.pushKV("balance", batch[ID_BALANCES]["result"]["mine"]["trusted"]);
+ }
result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
return JSONRPCReplyObj(result, NullUniValue, 1);