-
Notifications
You must be signed in to change notification settings - Fork 97
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
fix(hd_wallet): make extended pubkey of hd wallet generic #2159
Conversation
607d9fe
to
bde2077
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.
Have a discussion point down there.
This LGTM though :)
mm2src/coins/eth/eth_hd_wallet.rs
Outdated
&self, | ||
extended_pubkey: &Secp256k1ExtendedPublicKey, | ||
extended_pubkey: &HDCoinExtendedPubkey<Self>, | ||
derivation_path: DerivationPath, |
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.
A general Q regarding the typing choices in the HD code (not a blocker for this PR):
Is it really better to have the types with maps from Self
like this. I mean we are implementing the trait for a concrete type now so we could use the concrete arguments for more clarity.
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.
Also could the names for such maps be followed by Of
(e.g. HDCoinExtendedPubkeyOf<Coin>
). The confusion for me personally comes from that I always think about these types with generic args that they contain these args but here they end up digging up the args and extract some other type from them.
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.
let me label these as nit
s as they might be too opinionated.
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 mean we are implementing the trait for a concrete type now so we could use the concrete arguments for more clarity.
Did that for some of the implementations, hope it's a bit clearer now. If you find any other easy refactors please point me to it, I wanted to make all the below types private to the hd_wallet mod but it requires a lot of refactors. Should be done in the future in a separate PR.
komodo-defi-framework/mm2src/coins/hd_wallet/mod.rs
Lines 52 to 64 in 76e87ab
pub(crate) type HDAccountsMap<HDAccount> = BTreeMap<u32, HDAccount>; | |
pub(crate) type HDAccountsMutex<HDAccount> = AsyncMutex<HDAccountsMap<HDAccount>>; | |
pub(crate) type HDAccountsMut<'a, HDAccount> = AsyncMutexGuard<'a, HDAccountsMap<HDAccount>>; | |
pub(crate) type HDAccountMut<'a, HDAccount> = AsyncMappedMutexGuard<'a, HDAccountsMap<HDAccount>, HDAccount>; | |
type HDWalletHDAddress<T> = <<T as HDWalletOps>::HDAccount as HDAccountOps>::HDAddress; | |
type HDCoinHDAddress<T> = HDWalletHDAddress<<T as HDWalletCoinOps>::HDWallet>; | |
pub(crate) type HDWalletAddress<T> = | |
<<<T as HDWalletOps>::HDAccount as HDAccountOps>::HDAddress as HDAddressOps>::Address; | |
pub(crate) type HDCoinAddress<T> = HDWalletAddress<<T as HDWalletCoinOps>::HDWallet>; | |
type HDWalletExtendedPubkey<T> = <<T as HDWalletOps>::HDAccount as HDAccountOps>::ExtendedPublicKey; | |
pub(crate) type HDCoinExtendedPubkey<T> = HDWalletExtendedPubkey<<T as HDWalletCoinOps>::HDWallet>; | |
pub(crate) type HDCoinHDAccount<T> = HDWalletHDAccount<<T as HDWalletCoinOps>::HDWallet>; | |
type HDWalletHDAccount<T> = <T as HDWalletOps>::HDAccount; |
An idea: I made draft code with ExtendedPublicKey as enum (named Otherwise LGTM |
This will make the code much simpler, but as discussed with you on DM, if we wanted to separate HD wallet code to a separate crate in the future to be used by anyone else, associated types will be much easier to extend without requiring PRs in komodefi. |
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.
One last concrete type, LGTM otherwise :)
@@ -1112,7 +1112,7 @@ impl HDWalletBalanceOps for QtumCoin { | |||
|
|||
async fn all_known_addresses_balances( | |||
&self, | |||
hd_account: &HDCoinHDAccount<Self>, | |||
hd_account: &UtxoHDAccount, | |||
) -> BalanceResult<Vec<HDAddressBalance<Self::BalanceObject>>> { | |||
utxo_common::all_known_addresses_balances(self, hd_account).await | |||
} |
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.
two lines under, known_address_balance
still uses HDBalanceAddress<Self>
.
komodo-defi-framework/mm2src/coins/utxo/qtum.rs
Line 1120 in eb99106
async fn known_address_balance(&self, address: &HDBalanceAddress<Self>) -> BalanceResult<Self::BalanceObject> { |
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.
Thanks for noticing this, will push a fix asap.
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.
LGTM!
A enum provides static polymorphism so could not be extended w/o its code modification, so we agreed an assoc type is better for hdwallet because it allows to add new implementations. |
* dev: feat(nft-swap): add standalone maker contract and proxy support (#2100) feat(ETH): add `gas_limit` coins param to override default values (#2137) feat(tendermint): implement better sequence resolving logic (#2164) ci(artifact): add target for macos on apple silicon (#2163) fix(helpers): extend http to ws address conversion (#2166) fix(makerbot): add "testcoin" to provider options (#2161) fix(hd_wallet): make extended pubkey of hd wallet generic (#2159) fix(docker-tests): implement containers runtime directories (#2162) feat(tendermint): improve the `max` handling for tendermint withdraw (#2155) revert #2158 (comment) (#2160) ci(artifacts): upload build artifacts with in-tree script (#2158) test(tendermint): migrate to local/offline containerized testnets (#2128) use easingthemes/ssh-deploy@v5.0.3 for all builds except windows (#2157) chore(bin): rename mm2 binaries to kdf (#2126)
* dev: (22 commits) chore(release): bump mm2 version to 2.2.0-beta (KomodoPlatform#2188) ci(docker-tests): ignore tendermint IBC tests for now (KomodoPlatform#2185) feat(nft-swap): complete refund methods (KomodoPlatform#2129) chore(release): add changelog entries for v2.1.0-beta (KomodoPlatform#2165) fix(zcoin): don't force low r signing to generate htlc pubkey for zcoin (KomodoPlatform#2184) chore(rust-analyzer): add rust-analyzer into the workspace toolchain (KomodoPlatform#2179) chore: migrate .cargo/config to .cargo/config.toml to avoid deprecation warning (KomodoPlatform#2177) fix(swaps): ensure taker payment spend confirmations (KomodoPlatform#2176) feat(nft-swap): add standalone maker contract and proxy support (KomodoPlatform#2100) feat(ETH): add `gas_limit` coins param to override default values (KomodoPlatform#2137) feat(tendermint): implement better sequence resolving logic (KomodoPlatform#2164) ci(artifact): add target for macos on apple silicon (KomodoPlatform#2163) fix(helpers): extend http to ws address conversion (KomodoPlatform#2166) fix(makerbot): add "testcoin" to provider options (KomodoPlatform#2161) fix(hd_wallet): make extended pubkey of hd wallet generic (KomodoPlatform#2159) fix(docker-tests): implement containers runtime directories (KomodoPlatform#2162) feat(tendermint): improve the `max` handling for tendermint withdraw (KomodoPlatform#2155) revert KomodoPlatform#2158 (comment) (KomodoPlatform#2160) ci(artifacts): upload build artifacts with in-tree script (KomodoPlatform#2158) test(tendermint): migrate to local/offline containerized testnets (KomodoPlatform#2128) ...
No description provided.