-
Notifications
You must be signed in to change notification settings - Fork 355
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
Migrate to v0.11 #104
Migrate to v0.11 #104
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 work, and quite a bit of cleanup here.
I like your usage of very clear error cases in subkeys. It is quite good in atomic swap as well, but I think there are still too many user-facing strings being created in the code, not in the error type.
I think it is best practice to only return data related to the error inside the ContractError
type, and all formatting to make it reasonable (making use of the metadata) is done in the #[error]
text. This also gives a very clear overview for anyone trying to adjust the messages (or trace a bug)
); | ||
|
||
// And then cannot (not enough funds anymore) | ||
let res = handle(&mut deps, env, handle_msg.clone()); | ||
match res.unwrap_err() { | ||
StdError::Underflow { .. } => {} | ||
ContractError::Std(StdError::Underflow { .. }) => {} |
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.
Good example to show how this is compatible with StdErrors
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.
But since we are are creating custom errors everywhere, maybe we want to map this.
Either where it is generated like .map_err(|e| ...)
. Or do something like:
impl From<cw1_whitelist::ContractError> for ContractError
fn from(err: cw1_whitelist::ContractError) -> Self {
match err {
cw1_whitelist::ContractError::Std(error) => ContractError::Std(error),
cw1_whitelist::ContractError::Unauthorized {} => ContractError::Unauthorized {},
}
}
}
But mapping StdError::Underflow{}
=> ContractError::InsufficientAllowance{}
?
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.
Although the underflow message does show you the amounts, which is nice and shouldn't be lost.
This is an idea, take it or leave it.
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.
I would leave it as it is. Besides the extra boilerplate, it's pretty clear what's being done.
@@ -192,17 +192,17 @@ pub fn try_refund<S: Storage, A: Api, Q: Querier>( | |||
Err(StdError::unauthorized()) | |||
} else { | |||
// we delete the escrow (TODO: expose this in Bucket for simpler API) | |||
prefixed(PREFIX_ESCROW, &mut deps.storage).remove(id.as_bytes()); | |||
prefixed(&mut deps.storage, PREFIX_ESCROW).remove(id.as_bytes()); |
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, this is now in Bucket.remove
you can use that now.
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.
Will change those in another branch / PR.
@@ -161,17 +161,17 @@ pub fn try_approve<S: Storage, A: Api, Q: Querier>( | |||
Err(StdError::generic_err("escrow expired")) | |||
} else { | |||
// we delete the escrow (TODO: expose this in Bucket for simpler API) | |||
prefixed(PREFIX_ESCROW, &mut deps.storage).remove(id.as_bytes()); | |||
prefixed(&mut deps.storage, PREFIX_ESCROW).remove(id.as_bytes()); |
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.
And here... time to update
You're right, I see you point: The very idea of custom errors is to move the messages to the error definition; and in any case just pass parameters. And that, only if justified. |
I think there is a lot of work migrating to proper custom errors, and a lot of this can be done in parallel to other 0.11 upgrade stuff. I am preparing some larger changes to bucket (and adding an indexed bucket) for 0.11-alpha4. Now that you have fully migrated the error messages in a few contracts, and we can get some clarity there on what makes sense to us both, it would be great if you could finish up the other contracts with minimal changes. Either somehow asking clippy to ignore the deprecation warning for a minute, or just using a Oh, and rebasing/merging on master to resolve all conflicts (I think mainly with the 0.2.2 release and version changes?) Then please take out of draft mode, so we can merge this in, and you can keep updating the error codes on one branch, while I can update the Bucket refactor on another branch. I hope to do the Bucket refactor monday or tuesday |
Rename log to attr/attributes
Change FullDelegation accumulated_rewards to Vec<Coin>
Turns out is not so easy to do that, because once I change to What I can do is leave the warnings (or revert to using v0.10.1 in the remaining contracts) for now, and focus on the rebase from master and other small changes, in order to remove Draft mode. So we can merge the work so far. Update: Tried to revert remaining contract (staking) to 0.10.1, but that's not possible due to "library"-type dependencies. So I guess forward is the simple path. I'll try to finish migration tomorrow, to a point that it can be merged without errors / warnings. |
2bd9776
to
8e48aaa
Compare
OK, migrated all but the two new contracts (cw3-fixed-multisig and cw721-nft). Also rebased from master. Will remove Draft, so you can review and merge this if you want. And, I can migrate the other two contracts in a different branch / PR. |
It's probably a good idea to increase the version of the packages to |
Good point, but I don't intend to publish anything until 0.3.0, with 0.11 support. As 0.10 -> 0.11 is breaking. Thank you for finishing this up to a usable point. I will review and merge and we can both work on this as needed (I would just mess with the bucket and query stuff from my open PRs on cosmwasm with the next 0.11-alpha, and leave all the error work to you to ensure we don't step on toes) |
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.
Good stuff here, and thanks for getting it stable.
I will merge this in. Left a few comments along the way that may be useful for the next segment of your error-refactoring PR.
} | ||
|
||
impl From<cw20_base::ContractError> for ContractError { | ||
fn from(err: cw20_base::ContractError) -> Self { |
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 extension.
I did try to figure out how to "extend" enums in rust and it is not possible.
I wonder if we could simplify this one day with codegen? But I guess it is only a few minutes to write such code now.
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.
Yeah, these cases made me search for "rust inheritance" and the like... Traits are fine and dandy, but for real abstraction there's nothing like subtypes (interface inheritance) IMO.
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.
Come to think of it, this is probably more a case requiring or benefiting from "plain old" (implementation) inheritance, rather than interface inheritance.
NotInValidatorSet(String), | ||
|
||
#[error("Different denominations in bonds: '{0}' vs. '{1}'")] | ||
DifferentBondDenom(String, String), |
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.
Question: would it make sense to have these named (struct) variants rather than tuple variants, where there is more than one argument?
I think the generated code is the same, you just then use DifferentBondDenom{contract: String, message: String}
or something like that to make it clear which side is which.
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.
I think it makes sense, yes. I'll change it for clarity.
cw0 = { path = "../../packages/cw0", version = "0.2.2" } | ||
cw2 = { path = "../../packages/cw2", version = "0.2.2" } | ||
cw3 = { path = "../../packages/cw3", version = "0.2.2" } | ||
cw0 = { version = "0.2.2" } |
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.
Ah, interesting way to do this... as long as no one else imports this, we can hold it back to the older package versions. Nice idea!
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.
Yeah, that took a while... :-) happy that I made it compile (and then mergeable).
WIP for #96.