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 cosmwasm_std::Coins struct #1489

Closed
wants to merge 1 commit into from
Closed

Add cosmwasm_std::Coins struct #1489

wants to merge 1 commit into from

Conversation

larry0x
Copy link
Contributor

@larry0x larry0x commented Nov 14, 2022

Closes: #1377

@webmaster128 I accidentally closed #1487 when doing a force-push (I got confused with git rebasing and the commit history became very messed up) so here's another PR.

Comment on lines +34 to +41
// the map having a different length from the vec means the vec must either
// 1) contain duplicate denoms, or 2) contain zero amounts
if map.len() != vec_len {
return Err(StdError::parse_err(
type_name::<Self>(),
"duplicate denoms or zero amount",
));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not combine the duplicates and discard the zero amounts? It's more of a friendlier handling versus a throw.

Copy link
Member

@webmaster128 webmaster128 Nov 29, 2022

Choose a reason for hiding this comment

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

I'm also leaning towards a solution where Vec<Coin> -> Coins cannot fail. This can be achieved by just defining the semantics to be overriding old values. Vec<Coin> is typically some trusted value anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vec<Coin> is typically some trusted value anyways

Wouldn't this be an argument for fail-able casting instead of against it? Since Vec<Coin> comes from trusted sources, it having dups or zero amounts usually indicates there are serious bugs in the source or in contract execution. In this case I think an error is the preferred behavior.

Copy link
Member

Choose a reason for hiding this comment

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

If you put it that way, yes, it would be an argument for an assertion. Something is seriously wrong, an error case no one is prepared to handle. So it could be implemented as a panic.

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.

Feature request: a cosmwasm_std::Coins class similar to sdk.Coins
3 participants