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

Query Response Constructors #1766

Merged
merged 6 commits into from
Jul 15, 2023
Merged

Conversation

chipshort
Copy link
Collaborator

this is the 1.3 part of #1765

I also added the constructor to the existing responses (but can remove if you prefer)

@chipshort chipshort changed the base branch from main to release/1.3 July 6, 2023 13:32
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Very nice solution honoring my nice doc comment

@@ -55,6 +58,8 @@ pub struct BalanceResponse {
pub amount: Coin,
}

impl_response_constructor!(BalanceResponse, amount: Coin);
Copy link
Member

Choose a reason for hiding this comment

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

Great. This also brings up #1767

#[doc(hidden)]
#[allow(dead_code)]
pub fn new($( $field: $t),*) -> Self {
Self { $( $field: $field.into() ),* }
Copy link
Member

Choose a reason for hiding this comment

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

With this into() the constructor arg can have a different type than the field itself? Looks cool. Do you have an example for where they are different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that's actually a leftover from a version where I set all the parameters to be impl Into<$t>.
Keeping the .into() here would allow making some of the arguments impl Into<_> on the caller-side, but not sure if we really need that, since these constructors are mostly for internal use anyways?
I haven't done it in any of the calls here, but e.g. the BondedDenomResponse could have this one:

impl_response_constructor!(BondedDenomResponse, denom: impl Into<String>);

Copy link
Member

Choose a reason for hiding this comment

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

Then let's simplify and remove the .into(). We can always add it back if needed.

@@ -13,4 +13,4 @@ use serde::de::DeserializeOwned;
/// - multi-test/cw-sdk: create a default instance and mutate the fields
///
/// This trait is crate-internal and can change any time.
pub(crate) trait QueryResponseType: Default + DeserializeOwned {}
pub(crate) trait QueryResponseType: DeserializeOwned {}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder (maybe not in scope) if this should require a few other things, like Debug, PartialEq and Clone. Certainly helpful for test code and should be implemented for all those types coming from JSON.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good idea. I also just noticed that the staking responses don't implement this trait yet (because they don't have Default impls). I guess we want to implement it for them, now that Default is no longer needed.

Copy link
Member

Choose a reason for hiding this comment

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

True

@webmaster128 webmaster128 added this to the 1.3.0 milestone Jul 10, 2023
@webmaster128 webmaster128 merged commit 7ef4f87 into release/1.3 Jul 15, 2023
@webmaster128 webmaster128 deleted the fix-delegator-withdraw-address branch July 15, 2023 13:25
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.

2 participants