-
Notifications
You must be signed in to change notification settings - Fork 358
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
Conversation
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.
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 { |
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.
Can't we just do allowance_response: v
?
Much less verbose and helps make use of flatten
} | ||
|
||
#[test] | ||
fn it_should_make_correct_schema() { |
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.
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; |
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.
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
Hi,
This PR is ref to #57
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.