New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: Add balances RPC #15930
rpc: Add balances RPC #15930
Conversation
Concept ACK
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. |
concept ACK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 I also think all wallet |
Nice! I agree with @jnewbery about returning the new object through I agree about depracating / removing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
"balances": {
"mine": {
"trusted": 0.00000000,
"untrusted_pending": 0.00000000,
"immature": 0.00000000
}
},
help getwalletinfo
getwalletinfo
Returns an object containing various wallet state info.
Result:
{
"walletname": xxxxx, (string) the wallet name
"walletversion": xxxxx, (numeric) the wallet version
"balances": { (object) the wallet balances in BTC
"mine": { (object) balances from outputs that the wallet can sign
"trusted": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)
"untrusted_pending": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)
"immature": xxx (numeric) balance from immature coinbase outputs
},
"watchonly": { (object) watchonly balances (not present if wallet does not watch anything)
"trusted": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)
"untrusted_pending": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)
"immature": xxx (numeric) balance from immature coinbase outputs
},
},
"balance": xxxxxxx, (numeric) Identical to balances.mine.trusted
"unconfirmed_balance": xxx, (numeric) Identical to balances.mine.untrusted_pending
"immature_balance": xxxxxx, (numeric) Identical to balances.mine.immature
"txcount": xxxxxxx, (numeric) the total number of transactions in the wallet
"keypoololdest": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool
"keypoolsize": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)
"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)
"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
"paytxfee": x.xxxx, (numeric) the transaction fee configuration, set in BTC/kB
"hdseedid": "<hash160>" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)
"private_keys_enabled": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)
}
Examples:
> bitcoin-cli getwalletinfo
> 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
0.00000000
help getunconfirmedbalance
getunconfirmedbalance
DEPRECATED
Identical to getwalletinfo().balances.mine.untrusted_pending
getunconfirmedbalance true
error code: -1
error message:
getunconfirmedbalance
DEPRECATED
Identical to getwalletinfo().balances.mine.untrusted_pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK either way (getbalances
or here). I tend to prefer getbalances
though.
This seems redundant with JSON-RPC batching? |
@luke-jr It would be horribly redundant to provide a separate rpc for each balance type, when it comes at no cost to return them all. |
Perhaps just a |
Having a separate RPC makes |
Ok, going to rework to make this a fresh |
fac5d96
to
7529929
Compare
Note that batched RPCs are not atomic (and nor could they ever be, since the RPC server can't take the main lock). |
7529929
to
fafb024
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think all wallet
get-
andlist-
methods should return a best block hash, so it's clear at what point the returned values are valid.
Agree with @jnewbery, it can be useful.
utACK eeee149 |
PR title/description needs update |
eeee149
to
facfb41
Compare
utACK facfb41 Only change is adding "DEPRECATED" to the balance descriptions in |
lightly tested ACK facfb41 |
|
||
- `getbalances` returns an object with all balances (`mine`, | ||
`untrusted_pending` and `immature`). Please refer to the RPC help of | ||
`getbalances` for details. The new RPC is intended to replace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on referring to the RPC help for details. This is what the release notes should do instead of substitute for documentation 👍
facfb41 rpc: Deprecate getunconfirmedbalance and getwalletinfo balances (MarcoFalke) 999931c rpc: Add getbalances RPC (MarcoFalke) fad13e9 rpcwallet: Make helper methods const on CWallet (MarcoFalke) fad40ec wallet: Use IsValidNumArgs in getwalletinfo rpc (MarcoFalke) Pull request description: 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. ACKs for commit facfb4: jnewbery: utACK facfb41 Tree-SHA512: 1f54fedce55df9a8ea82d2b6265354b39a956072621876ebaee2355aac0e23c7b64340c3279502415598c095858529e18b50789be956250aafda1cd3a8d948a5
Post-merge tested ACK a3d2d6b |
utACK facfb41. |
facfb41 rpc: Deprecate getunconfirmedbalance and getwalletinfo balances (MarcoFalke) 999931c rpc: Add getbalances RPC (MarcoFalke) fad13e9 rpcwallet: Make helper methods const on CWallet (MarcoFalke) fad40ec wallet: Use IsValidNumArgs in getwalletinfo rpc (MarcoFalke) Pull request description: 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. ACKs for commit facfb4: jnewbery: utACK facfb41 Tree-SHA512: 1f54fedce55df9a8ea82d2b6265354b39a956072621876ebaee2355aac0e23c7b64340c3279502415598c095858529e18b50789be956250aafda1cd3a8d948a5
Summary: bitcoin/bitcoin@fad40ec --- Depends on D6443 Partial backport of Core [[bitcoin/bitcoin#15930 | PR15930]] Test Plan: ninja ./src/bitcoind -regtest -daemon ./src/bitcoin-cli getwalletinfo help check that it looks alright Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6444
Summary: bitcoin/bitcoin@fad13e9 --- Depends on D6444 Partial backport of Core [[bitcoin/bitcoin#15930 | PR15930]] Test Plan: ninja Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6445
Summary: bitcoin/bitcoin@999931c --- Depends on D6445 Partial backport of Core [[bitcoin/bitcoin#15930 | PR15930]] Test Plan: ninja ./src/bitcoind -regtest -daemon ./src/bitcoin-cli getwalletinfo help Check that output is correct ./src/bitcoin-cli getbalances ./src/bitcoin-cli getbalances help Ditto Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6446
…fo balances Summary: bitcoin/bitcoin@facfb41 --- Depends on D6446 Concludes backport of Core [[bitcoin/bitcoin#15930 | PR15930]] Test Plan: ninja ./src/bitcoind -regtest -daemon ./src/bitcoin-cli -regtest getunconfirmedbalance help ./src/bitcoin-cli -regtest getwalletinfo help Check if it looks good Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6447
This exposes the
CWallet::GetBalance()
struct over RPC.In the future, incorrectly named rpcs such as
getunconfirmedbalance
or rpcs redundant to this such asgetbalance
could be removed.