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

[r2r] Implement TX history V2 for UTXO coins activated with a Hardware wallet #1467

Merged
merged 27 commits into from
Sep 24, 2022

Conversation

sergeyboyko0791
Copy link

No description provided.

* Add `UtxoTxHistoryOps`, implement it for `BchCoin`
* Remove `UtxoStandardOps` implementation for `BchCoin`
* TODO implement `WaitForHistoryUpdateTrigger` state
…ardCoin`

* Add `taget: MyTxHistoryTarget` field to `my_tx_history` request
* Add `utxo_common/utxo_tx_history_common.rs` for TX history related common impl
* Add `HDWalletCoinOps::derive_known_addresses`
* Refactor `GetTxHistoryFilters` by requiring to set `from_addresses`
* Fix `tx_history_v2_tests`
* Implement `UtxoTxHistoryOps` and `CoinWithTxHistoryV2` for `QtumCoin`
* Implement `WaitForHistoryUpdateTrigger` state
* Add `ElectrumClient::scripthash_get_history_batch`
* Implement `UtxoTxHistoryOps::request_tx_history` according to `DerivationMethod`
* Add `CoinBalanceReportOps` trait
* Don't spawn legacy tx_history loop on `init_utxo`, `init_qtum` RPCs
* Rename `EnableCoinBalance` to `CoinBalanceReport`
* Rename `utxo_tx_history_common.rs` to `utxo_tx_history_v2_common.rs`
…tory V2

* Add `UtxoTxHistoryOps::tx_from_storage_or_rpc`
* Fix `CoinWithTxHistoryV2::get_tx_history_filters`, `UtxoTxHistoryOps::request_tx_history`
@sergeyboyko0791 sergeyboyko0791 linked an issue Sep 11, 2022 that may be closed by this pull request
* Add `UtxoMyAddressesHistoryError` for `UtxoTxHistoryOps::my_addresses`
* Optimize `UtxoTxHistoryOps::request_tx_history` by passing `my_addresses` argument
* Use `utxo_common::request_tx_history` for `BchCoin` instead of `utxo_tx_history_v2_common`'s
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Implement TX history V2 for UTXO coins activated with a Hardware wallet [r2r] Implement TX history V2 for UTXO coins activated with a Hardware wallet Sep 11, 2022
@sergeyboyko0791 sergeyboyko0791 self-assigned this Sep 11, 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 the great work! Could you please also add an integration test for history in HD mode similar to https://github.com/KomodoPlatform/atomicDEX-API/blob/e420d60fa1d5df3963418cf25d728ef04c5bbccd/mm2src/mm2_main/src/mm2_tests/bch_and_slp_tests.rs#L390?

.compat(),
)
fn process_history_loop(&self, _ctx: MmArc) -> Box<dyn Future<Item = (), Error = ()> + Send> {
warn!("'process_history_loop' is not deprecated for BchCoin! Consider using 'my_tx_history_v2'");
Copy link
Member

Choose a reason for hiding this comment

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

It seems you meant is not implemented or is deprecated.

Copy link
Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Author

Choose a reason for hiding this comment

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

Done

async fn get_block_timestamp(&self, height: u64) -> MmResult<u64, UtxoRpcError>;

/// Requests balances of all activated coin's addresses.
async fn get_addresses_balances(&self) -> BalanceResult<HashMap<String, BigDecimal>>;
Copy link
Member

Choose a reason for hiding this comment

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

my_addresses_balances seems a more suitable name. I personally would expect this method to accept addresses as argument with current name.

Copy link
Author

Choose a reason for hiding this comment

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

Good note, thank you!

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

if to_update {
return Self::change_state(FetchingTxHashes::new());
Copy link
Member

Choose a reason for hiding this comment

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

In FetchingTxHashes state, it will fetch history for all addresses - can be quite an overhead. We need only addresses whose balance was changed here.

Copy link
Author

Choose a reason for hiding this comment

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

Great advice, will do!

Copy link
Author

Choose a reason for hiding this comment

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

This led to a huge refactoring of some of the TX history storage methods and the TX history states.
I tried to cover most of the cases in tx_history_v2_tests.rs module.

shamardy
shamardy previously approved these changes Sep 13, 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! Only minor non-blocker comments

mm2src/coins/hd_wallet.rs Show resolved Hide resolved
mm2src/coins/utxo/rpc_clients.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_tx_history_v2.rs Outdated Show resolved Hide resolved
@sergeyboyko0791 sergeyboyko0791 changed the title [r2r] Implement TX history V2 for UTXO coins activated with a Hardware wallet [wip] Implement TX history V2 for UTXO coins activated with a Hardware wallet Sep 14, 2022
* Optimize TX history states by specifying `FetchingTxHashes::fetch_for_addresses`
* Rename `UtxoTxHistoryOps::get_addresses_balances` to `my_addresses_balances`
* Add `UtxoTxHistoryOps::address_from_str` to parse addresses within `UtxoTxHistoryOps::my_addresses_balances` result
* Add `AddrFromStrError`
… function

* Add `SqlQuery::count_distinct`
…s` and `get_unconfirmed_txes_from_history` functions
* Fix `SqlTxHistoryStorage` to repeat the same ordering as in `compare_transaction_details`
* Fix tests
* Use `utxo_common::utxo_tx_history_v2_common::request_tx_history` within for BCH coin
* Move `utxo_coin_fields_for_test` to `utxo_common_tests.rs`
* Add `T_BCH_ELECTRUMS` listening on WSS port
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Implement TX history V2 for UTXO coins activated with a Hardware wallet [r2r] Implement TX history V2 for UTXO coins activated with a Hardware wallet Sep 24, 2022
@sergeyboyko0791
Copy link
Author

@artemii235 @shamardy this PR is ready for review

@artemii235 artemii235 merged commit 36392fd into dev Sep 24, 2022
@artemii235 artemii235 deleted the hd-utxo-tx-history branch September 24, 2022 18:52
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
3 participants