Skip to content
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

Merged
merged 4 commits into from May 6, 2019
Merged

rpc: Add balances RPC #15930

merged 4 commits into from May 6, 2019

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 1, 2019

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.

@laanwj
Copy link
Member

laanwj commented May 1, 2019

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.

@instagibbs
Copy link
Member

concept ACK

Copy link
Contributor

@jnewbery jnewbery left a 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.

src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
@maflcko
Copy link
Member Author

maflcko commented May 1, 2019

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.

@jnewbery
Copy link
Contributor

jnewbery commented May 1, 2019

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.

@jonasschnelli
Copy link
Contributor

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

Copy link
Contributor

@jonatack jonatack left a 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

Copy link
Member

@promag promag left a 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.

test/functional/wallet_balance.py Show resolved Hide resolved
@luke-jr
Copy link
Member

luke-jr commented May 2, 2019

This seems redundant with JSON-RPC batching?

@maflcko
Copy link
Member Author

maflcko commented May 2, 2019

@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.

@luke-jr
Copy link
Member

luke-jr commented May 2, 2019

Perhaps just a getbalances as @jnewbery suggested then?

@promag
Copy link
Member

promag commented May 2, 2019

Having a separate RPC makes getwalletinfo constant (after removing deprecated fields).

@maflcko
Copy link
Member Author

maflcko commented May 2, 2019

Ok, going to rework to make this a fresh getbalances call (not to be confused with getbalance)

@jnewbery
Copy link
Contributor

jnewbery commented May 2, 2019

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).

Copy link
Member

@promag promag left a 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- and list- 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.

src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwallet.cpp Show resolved Hide resolved
src/wallet/rpcwallet.cpp Show resolved Hide resolved
@jnewbery
Copy link
Contributor

jnewbery commented May 2, 2019

utACK eeee149

@luke-jr
Copy link
Member

luke-jr commented May 2, 2019

PR title/description needs update

doc/release-notes.md Outdated Show resolved Hide resolved
@maflcko maflcko changed the title rpc: Add balances to getwalletinfo rpc: Add balances RPC May 2, 2019
@jnewbery
Copy link
Contributor

jnewbery commented May 3, 2019

utACK facfb41

Only change is adding "DEPRECATED" to the balance descriptions in getwalletinfo and replacing the despicable * with a glorious - in the release notes.

@laanwj
Copy link
Member

laanwj commented May 6, 2019

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
Copy link
Member

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 👍

@laanwj laanwj merged commit facfb41 into bitcoin:master May 6, 2019
laanwj added a commit that referenced this pull request May 6, 2019
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
@jonatack
Copy link
Contributor

jonatack commented May 6, 2019

Post-merge tested ACK a3d2d6b

@maflcko maflcko deleted the 1904-rpcWalletBalances branch May 6, 2019 13:19
@promag
Copy link
Member

promag commented May 6, 2019

utACK facfb41.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 6, 2019
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 9, 2020
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 9, 2020
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 9, 2020
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 9, 2020
…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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants