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

Implement requesting balances of HD wallet addresses #1190

Merged
merged 31 commits into from
Feb 22, 2022

Conversation

sergeyboyko0791
Copy link

@sergeyboyko0791 sergeyboyko0791 commented Jan 9, 2022

  • Add account_balance, scan_for_new_addresses, get_new_address, init_create_new_account, init_create_new_account_status, init_create_new_account_user_action RPC calls
  • Refactor init_utxo according to a unified init_standalone_coin protocol
  • Initialize UTXO coin with a pubkey requested from a Trezor device
  • Move UtxoCoinBuilder, UtxoArcBuilder from utxo.rs to a separate module
  • Add the check_utxo_maturity flag to electrum/enable RPC call mature_confirmations not used #1181

…otocol

* Move `PrivKeyBuildPolicy` to `lp_coins.rs`
* Refactor `grpc_web_multi_url_request`
* Add `MmRpcResult::map_err`, `RpcTaskStatus::map_err`
* Move `UtxoCoinBuilder`, `UtxoArcBuilder` from `utxo.rs` to a separate module
* Add `extended_pubkey`, `derivation_path` to `HDWalletInfo`
* Move `extended_pubkey` from `UtxoHDWallet` to `UtxoHDAccount`
* Register `UtxoStandardCoin` at `InitStandaloneCoinActivationOps::init_standalone_coin`
* Add `RpcDerivationPath`
* Push missed `coin_balance.rs`
* Increase `WAIT_DOCKER_READY_TIMEOUT_MS` to 60s
* Bump the `ring` crate version to 0.16.15
* Optimize UTXO coin builders not to clone `UtxoActivationParams`
* Refactor `NativeClient::list_transactions_by_address` to `NativeClient::is_address_list_transactions_empty`
* Add `init_qtum`, `init_qtum_status`, `init_qtum_user_action` RPC calls
* Add `derivation_path` to `HDAccountBalance`
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions on the first review iteration :)

mm2src/coins/utxo/bchd_grpc.rs Outdated Show resolved Hide resolved
derivation_path,
} = coin.derive_address(hd_account, address_id, change)?;

let balance = coin.known_address_balance(&address).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting balances sequentially can become a problem if users will have many addresses after a long time. It's preferable to start using batch requests here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I splitted the wallet_balance into hd_account_balance and check_hd_account_balance, added pagging options to hd_account_balance. Could you please re-review?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant using JSON RPC batch requests https://www.jsonrpc.org/specification#batch. E.g. request all balances of known addresses from Electrum in a single batch.
Please check if using batches will be more effective - compare the time required to perform e.g. 10 balance requests sequentially or in the batch. If the difference is significant, consider refactoring to batch requests in the next iteration.

mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 2 minor comments :)

mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/lp_coins.rs Outdated Show resolved Hide resolved
sergeyboyko0791 and others added 2 commits January 21, 2022 17:28
* Return the previous implementation of `grpc_web_multi_url_request`
* Split `wallet_balance` into `hd_account_balance` and `check_hd_account_balance` RPC calls
* Add `check_utxo_maturity` to electrum/enable RPC call
* Add `QtumCoinBuilder` and `QtumCoinWithIguanaPrivKeyBuilder` that override `check_utxo_maturity`
* Add `UtxoCommonOps::list_all_unspent_ordered` that behaves as `UtxoCommonOps::list_unspent_ordered` before
* `UtxoCommonOps::list_unspent_ordered` checks the `check_utxo_maturity` flag to use either `list_all_unspent_ordered` or `list_mature_unspent_ordered`
* Rename `UtxoCommonOps::ordered_mature_unspents` to `UtxoCommonOps::list_mature_unspent_ordered`
This was linked to issues Jan 25, 2022
* Use `tokio::RwLock` instead of `parking_lot::Mutex` to store HD accounts
* Move HD wallet related traits and structures from lp_coins.rs to coin_hd_wallet.rs
* TODO use `HwRpcTaskAwaitingStatus`, `HwRpcTaskUserAction`, `HwRpcTaskUserActionRequest`, `InitRpcTaskResponse`, `RpcTaskActionError`, `RpcTaskStatusError`, `RpcTaskStatusRequest` everywhere it's possible
@sergeyboyko0791
Copy link
Author

sergeyboyko0791 commented Feb 8, 2022

Since the last review iteration, I added get_new_hd_address, init_create_new_hd_account, init_create_new_hd_account_status, init_create_new_hd_account_user_action RPC calls.
@artemii235 @shamardy could you please re-review it?

shamardy
shamardy previously approved these changes Feb 8, 2022
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work! 🔥

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 7 comments are sufficient for this review iteration 🙂

mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/coin_balance.rs Outdated Show resolved Hide resolved
mm2src/coins/coin_balance.rs Show resolved Hide resolved
mm2src/coins/hd_pubkey.rs Show resolved Hide resolved
sergeyboyko0791 and others added 4 commits February 9, 2022 19:43
* Move the `HDWallet` related methods from `HDWalletCoinOps` into `HDWalletOps`
* Move the `HDAccount` related methods from `HDWalletCoinOps` into `HDAccountOps`
* Rename `get_new_hd_address` to `get_new_address`, `hd_account_balance` to `account_balance`, `init_create_hd_account` to `init_create_account` RPC calls
* Possible refactoring.

* Removed more bounds.

* Added HDAccount for HDWalletCoinOps to reduce "as HDWalletOps" constructions.

* Continue refactoring
* Add a default implementation of `HDWalletCoinOps::generate_new_address`
* Remove `HDWalletCoinOps::address_balance`
* Make `HDWalletBalanceRpcOps` independent of `HDWalletBalanceOps`

Co-authored-by: Artem Vitae <artem@vitae.com>
@sergeyboyko0791
Copy link
Author

@artemii235 I hope I've resolved all issues

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more (hopefully minor 🙂 ) changes requests.

mm2src/coins/hd_wallet.rs Outdated Show resolved Hide resolved
mm2src/coins/init_create_account.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/crypto/src/key_pair_ctx.rs Outdated Show resolved Hide resolved
mm2src/rpc/dispatcher/dispatcher.rs Outdated Show resolved Hide resolved
…Id refers to an activated account/address

* Add the `WithdrawFrom::AccountId` variant to allow the user to specify account_id, chain and address_id
* Add `Bip44DerivationPath`, `Bip44PathToCoin`, `Bip44PathToAccount`
* Avoid extracting a pubkey from a Trezor device on `init_withdraw`
# Conflicts:
#	mm2src/docker_tests/docker_tests_common.rs
* Avoid using `clippy::type_complexity` by refactoring the `RpcTask` module
* Typo: address_unspendable_balanAce
* Rename `ExpectedHDWalletDerivationMethod` to `CoinIsActivatedNotWithHDWallet`
* Reorder RPCs alphabetically
* impl `From<KeyPair>`
@sergeyboyko0791
Copy link
Author

I think it's ready for the next review iteration :)
cc @artemii235

artemii235
artemii235 previously approved these changes Feb 21, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Thanks for all fixes!

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reapproving.

@artemii235 artemii235 merged commit d95da9f into dev Feb 22, 2022
@artemii235 artemii235 deleted the init-utxo-with-trezor branch February 22, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardware wallets support mature_confirmations not used
4 participants