This exposes the CWallet::GetBalance()
struct over RPC.
In the future, incorrectly named rpcs such as getunconfirmedbalance
or rpcs redundant to this such as getbalance
could be removed.
This exposes the CWallet::GetBalance()
struct over RPC.
In the future, incorrectly named rpcs such as getunconfirmedbalance
or rpcs redundant to this such as getbalance
could be removed.
Concept ACK
or rpcs redundant to this such as getbalance could be removed.
Dunno, I think having a dedicated call to get the balance is useful. If it’s not broken (like mis-named methods) I’d prefer keeping it.
2405+ " \"trusted\": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)\n"
2406+ " \"untrusted_pending\": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)\n"
2407+ " \"immature\": xxx (numeric) balance from immature coinbase outputs\n"
2408+ " },\n"
2409+ " },\n"
2410+ " \"balance\": xxxxxxx, (numeric) Identical to balances.mine.trusted\n"
Looks good. I think this needs release notes to describe the new return object and document that getunconfirmedbalance
is deprecated.
I think having a dedicated call to get the balance is useful.
How about we have a getbalances
RPC that just returns the balances
object added in this PR.
How about we have a getbalances RPC that just returns the balances object added in this PR.
Then I’d rather not add the same struct to getwalletinfo. Imo a single place where to get this is enough.
I don’t have an issue with the same data appearing in multiple RPC methods, but if you think that’s an issue, then I’d have a slight preference for a getbalances
RPC method to be separate from getwalletinfo
. I think either is an improvement though.
I also think all wallet get-
and list-
methods should return a best block hash, so it’s clear at what point the returned values are valid.
74+ assert_equal(self.nodes[0].getwalletinfo()['balances']['mine']['trusted'], 50)
75+ assert_equal(self.nodes[1].getwalletinfo()['balances']['mine']['trusted'], 50)
76+
77+ assert_equal(self.nodes[0].getwalletinfo()['balances']['watchonly']['immature'], 5000)
78+ assert 'watchonly' not in self.nodes[1].getwalletinfo()['balances']
79+
balances.min.trusted == balance
as well as for unconfirmed_balance
and immature_balance
.
Nice! Concept ACK.
I agree with @jnewbery about returning the new object through getbalance
. Why?
getwalletinfo
, for historical and logical reasons, has the is_min is_spendable balance value in it and I think removing it makes little sense. We already have the same data type in getbalance
and to me it would just be logical to switch from a single balance value to the new obect (in both calls).
I agree about depracating / removing getunconfirmedbalance
Concept ACK
Initial manual testing, to be completed later:
test/functional/wallet_balance.py passes locally -> EDIT: all unit + extended functional tests pass locally
getwalletinfo
0 "balances": {
1 "mine": {
2 "trusted": 0.00000000,
3 "untrusted_pending": 0.00000000,
4 "immature": 0.00000000
5 }
6 },
help getwalletinfo
0getwalletinfo
1Returns an object containing various wallet state info.
2
3Result:
4{
5 "walletname": xxxxx, (string) the wallet name
6 "walletversion": xxxxx, (numeric) the wallet version
7 "balances": { (object) the wallet balances in BTC
8 "mine": { (object) balances from outputs that the wallet can sign
9 "trusted": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)
10 "untrusted_pending": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)
11 "immature": xxx (numeric) balance from immature coinbase outputs
12 },
13 "watchonly": { (object) watchonly balances (not present if wallet does not watch anything)
14 "trusted": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)
15 "untrusted_pending": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)
16 "immature": xxx (numeric) balance from immature coinbase outputs
17 },
18 },
19 "balance": xxxxxxx, (numeric) Identical to balances.mine.trusted
20 "unconfirmed_balance": xxx, (numeric) Identical to balances.mine.untrusted_pending
21 "immature_balance": xxxxxx, (numeric) Identical to balances.mine.immature
22 "txcount": xxxxxxx, (numeric) the total number of transactions in the wallet
23 "keypoololdest": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool
24 "keypoolsize": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)
25 "keypoolsize_hd_internal": xxxx, (numeric) 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)
26 "unlocked_until": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked
27 "paytxfee": x.xxxx, (numeric) the transaction fee configuration, set in BTC/kB
28 "hdseedid": "<hash160>" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)
29 "private_keys_enabled": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)
30}
31
32Examples:
33> bitcoin-cli getwalletinfo
34> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
getunconfirmedbalance
00.00000000
help getunconfirmedbalance
0getunconfirmedbalance
1DEPRECATED
2Identical to getwalletinfo().balances.mine.untrusted_pending
getunconfirmedbalance true
0error code: -1
1error message:
2getunconfirmedbalance
3DEPRECATED
4Identical to getwalletinfo().balances.mine.untrusted_pending
getbalances
or here). I tend to prefer getbalances
though.
getwalletinfo
constant (after removing deprecated fields).
getbalances
call (not to be confused with getbalance
)
This seems redundant with JSON-RPC batching?
Note that batched RPCs are not atomic (and nor could they ever be, since the RPC server can’t take the main lock).
2450@@ -2389,9 +2451,9 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
2451 "{\n"
2452 " \"walletname\": xxxxx, (string) the wallet name\n"
2453 " \"walletversion\": xxxxx, (numeric) the wallet version\n"
2454- " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2455- " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2456- " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
2457+ " \"balance\": xxxxxxx, (numeric) Identical to getbalances().mine.trusted\n"
Deprecated, use getbalances().mine.trusted
instead?
getbalances
instead.
2390+ " \"mine\": { (object) balances from outputs that the wallet can sign\n"
2391+ " \"trusted\": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)\n"
2392+ " \"untrusted_pending\": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)\n"
2393+ " \"immature\": xxx (numeric) balance from immature coinbase outputs\n"
2394+ " },\n"
2395+ " \"watchonly\": { (object) watchonly balances (not present if wallet does not watch anything)\n"
2406+ if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
2407+ throw std::runtime_error(help.ToString());
2408+ }
2409+
2410+ // Make sure the results are valid at least up to the most recent block
2411+ // the user could have gotten from another RPC command prior to now
69@@ -70,14 +70,14 @@ std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& reques
70 return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) ? wallets[0] : nullptr;
71 }
72
73-std::string HelpRequiringPassphrase(CWallet * const pwallet)
74+std::string HelpRequiringPassphrase(const CWallet* pwallet)
@luke-jr It is not the pointer losing constness, but the pwallet
local variable losing constness.
CWallet * const pwallet
means “Take a pointer-to-CWallet as argument, and store in the local variable pwallet
which is const”. It’s not actually part of the function signature.
60@@ -61,6 +61,15 @@ platform.
61 Notable changes
62 ===============
63
64+New RPCs
65+--------
66+
67+* `getbalances` returns an object with all balances (`mine`,
-
here, not *
*
with -
utACK facfb4111d14a3b06c46690a2cca7ca91cea8a96
Only change is adding “DEPRECATED” to the balance descriptions in getwalletinfo
and replacing the despicable *
with a glorious -
in the release notes.
60@@ -61,6 +61,15 @@ platform.
61 Notable changes
62 ===============
63
64+New RPCs
65+--------
66+
67+- `getbalances` returns an object with all balances (`mine`,
68+ `untrusted_pending` and `immature`). Please refer to the RPC help of
69+ `getbalances` for details. The new RPC is intended to replace