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

Add traits and remove excessive type definition in extrinsic helpers #434

Merged
merged 25 commits into from
Jan 19, 2023

Conversation

haerdib
Copy link
Contributor

@haerdib haerdib commented Jan 12, 2023

The aim of this PR is to remove the excessive type definitions for the extrinsic creation. Until now, whenever there have been changes in types (see an example) lots of manual changes needed to be done. To solve this, several traits are introduced in this PR.

Drawback:

  • Need of trait import in case extrinsic are used.

Additionally, the following was changed:

  • removed common.rs because all the types were for a specific pallet anyway. So moved them there.
  • removed some redundant naming, e.g. BALANCES_TRANSFER -> TRANSFER
  • removed unnecessary trait bounds

closes #415

@haerdib haerdib self-assigned this Jan 12, 2023
@haerdib haerdib added F7-enhancement Enhances an already existing functionality E2-breaksapi labels Jan 12, 2023
@haerdib haerdib changed the title Simplify extrinsic helpers Add traits and remove excessive type definition in extrinsic helpers Jan 12, 2023
@haerdib haerdib requested a review from clangenb January 12, 2023 11:59
@haerdib haerdib marked this pull request as ready for review January 12, 2023 12:01
src/extrinsic/staking.rs Outdated Show resolved Hide resolved
Comment on lines 47 to 62
pub trait AssignExtrinsicTypes {
type Address;
type Signature;
type SignedExtra;
}

impl<Signer, Client, Params, Runtime> AssignExtrinsicTypes for Api<Signer, Client, Params, Runtime>
where
Signer: SignExtrinsic<Runtime::AccountId>,
Runtime: FrameSystemConfig,
Params: ExtrinsicParams<Runtime::Index, Runtime::Hash>,
{
type Address = Signer::ExtrinsicAddress;
type Signature = Signer::Signature;
type SignedExtra = Params::SignedExtra;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't need this trait if we have the Extrinsic associated types as I described above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see the correlation : This trait is just so that not every trait needs to redefine these three types. Nothing to do with the Extrinsic I think?

Copy link
Contributor Author

@haerdib haerdib Jan 12, 2023

Choose a reason for hiding this comment

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

Nvm - there is a correlation. Forget the comment above .

Copy link
Collaborator

@clangenb clangenb Jan 12, 2023

Choose a reason for hiding this comment

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

I thought Extrinsic is mostly where we use them as the trait is called AssignExtrinsicTypes, but you can quite conveniently have an extrinsic associated type to assign those values.

If this re-assignment is needed beyond the scope of extrinsics, we should add these associated types to an overarching ApiTrait IMO, so that if you use the api, you always have it in scope and you don't need to import this extra trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it. If it's about the re-assignment, as you wrote, it should be done a level above.

use ac_primitives::{CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig};
use codec::{Compact, Decode, Encode};

const MODULE: &str = "Staking";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if I agree with the plain Module name. I would prefer to name STAKING_MODULE, what was your reasoning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redundancy. The file is already called staking.rs. Why would everything need a Staking prefix?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, I see now that it is private, so I think it is ok. However, module is just so overly generic so I am still a bit against it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kay kay, I'll give in this time. As thanks for the solution above 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Readded the name. But for the MODULE only. For the calls, I still think that's an overkill.

@haerdib haerdib requested a review from clangenb January 12, 2023 16:04
@haerdib haerdib requested a review from Niederb January 13, 2023 07:58
Copy link
Collaborator

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nice, this looks great. I only have a naming suggestion, what would you think about renaming the traits like:

CreateBalancesExtrinsic -> BalancesExtrinsics (note the pural of extrinsics).

We could also drop the create_ prefix of the methods.

Copy link
Contributor

@Niederb Niederb left a comment

Choose a reason for hiding this comment

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

Really nice PR. Makes the "Type-Zoo" easier to digest and comprehend.

Copy link
Collaborator

@clangenb clangenb 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 fixes, it looks great to me now!

@haerdib haerdib merged commit e27d177 into master Jan 19, 2023
@haerdib haerdib deleted the bh/415-extrinsic-helpers branch January 19, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2-breaksapi F7-enhancement Enhances an already existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate if type definitions in extrinsic helpers are necessary
3 participants