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

fix(hd_wallet): make extended pubkey of hd wallet generic #2159

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

shamardy
Copy link
Collaborator

@shamardy shamardy commented Jul 8, 2024

No description provided.

@onur-ozkan onur-ozkan force-pushed the feat-generic-xpub branch from 607d9fe to bde2077 Compare July 9, 2024 06:36
mariocynicys
mariocynicys previously approved these changes Jul 9, 2024
Copy link
Collaborator

@mariocynicys mariocynicys left a 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 :)

Comment on lines 37 to 39
&self,
extended_pubkey: &Secp256k1ExtendedPublicKey,
extended_pubkey: &HDCoinExtendedPubkey<Self>,
derivation_path: DerivationPath,
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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 nits as they might be too opinionated.

Copy link
Collaborator Author

@shamardy shamardy Jul 12, 2024

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.

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;

@dimxy
Copy link
Collaborator

dimxy commented Jul 11, 2024

An idea:
I think, as this new ExtendedPublicKey type is used in many traits and functions, we could implement it not as an associated type but as a dedicated enum type (when it is an associated type we have to create bulky type definitions).

I made draft code with ExtendedPublicKey as enum (named UniExtendedPublicKey)

Otherwise LGTM

dimxy
dimxy previously approved these changes Jul 11, 2024
@shamardy
Copy link
Collaborator Author

An idea:
I think, as this new ExtendedPublicKey type is used in many traits and functions, we could implement it not as an associated type but as a dedicated enum type (when it is an associated type we have to create bulky type definitions).

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.

@shamardy shamardy dismissed stale reviews from dimxy and mariocynicys via eb99106 July 12, 2024 12:45
@shamardy shamardy requested a review from mariocynicys July 12, 2024 12:48
@mariocynicys
Copy link
Collaborator

@dimxy @shamardy gonna disagree with you here.
I think dyn Traits and associate types > enums. merely for the fact that one won't need to match the enum (even when we know what it matches to) before using it.

Copy link
Collaborator

@mariocynicys mariocynicys left a 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
}
Copy link
Collaborator

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

async fn known_address_balance(&self, address: &HDBalanceAddress<Self>) -> BalanceResult<Self::BalanceObject> {

Copy link
Collaborator Author

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.

Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

LGTM!

@shamardy shamardy merged commit 6d1342e into dev Jul 12, 2024
22 of 25 checks passed
@shamardy shamardy deleted the feat-generic-xpub branch July 12, 2024 15:31
@dimxy
Copy link
Collaborator

dimxy commented Jul 12, 2024

@dimxy @shamardy gonna disagree with you here. I think dyn Traits and associate types > enums. merely for the fact that one won't need to match the enum (even when we know what it matches to) before using it.

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.

dimxy added a commit that referenced this pull request Jul 21, 2024
* 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)
dimxy added a commit to dimxy/komodo-defi-framework that referenced this pull request Aug 12, 2024
* 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)
  ...
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.

3 participants