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

WIP: Feedback needed - serde[(flatten)] #84

Closed
wants to merge 2 commits into from

Conversation

whalelephant
Copy link
Contributor

Hi,

This PR is ref to #57

  • Th current code has been tested to build to wasm successfully and pass tests in /packages and /contracts.
  • The additional tests may be misplaced
  • Not sure what to call the flattened field name, currently allowance_response which is helpful for maintainers but probably not so for the users.

I think it will be nicer to maintain "extended" structs by using flatten, this assumes we can reuse the basic structs many times. However, it is more verbose when developers have to use "extended" structs.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Nice start. Added some thoughts on where to go with this

@@ -27,8 +27,10 @@ pub fn query_all_allowances<S: Storage, A: Api, Q: Querier>(
let (k, v) = item?;
Ok(AllowanceInfo {
spender: api.human_address(&CanonicalAddr::from(k))?,
allowance: v.allowance,
expires: v.expires,
allowance_response: AllowanceResponse {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just do allowance_response: v?

Much less verbose and helps make use of flatten

}

#[test]
fn it_should_make_correct_schema() {
Copy link
Member

Choose a reason for hiding this comment

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

Oh, this is a very interesting idea.

What I would do would be to define the old AllowanceInfo type for tests and generate json schema for the old and new AllowanceInfo (with and without flatten) and you could compare those two schemas (asset equal)

mod test {
use super::*;
use cosmwasm_schema::schema_for;
use serde_json;
Copy link
Member

Choose a reason for hiding this comment

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

Note we use a custom json serde lib for cosmwasm_std.

You can import cosmwasm_std::to_vec to use that. It would be good to ensure our custom lib supports flatten as well as the standard one

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.

None yet

2 participants