-
Notifications
You must be signed in to change notification settings - Fork 353
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
new cosmwasm doc #1968
base: main
Are you sure you want to change the base?
new cosmwasm doc #1968
Changes from all commits
6417d7f
d8ee801
f13ec9c
195b242
70a388a
04933f0
4832805
fb02d73
32b9852
00b2b16
137f6d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,12 +393,12 @@ impl From<DivideByZeroError> for StdError { | |
} | ||
} | ||
|
||
/// The return type for init, execute and query. Since the error type cannot be serialized to JSON, | ||
/// this is only available within the contract and its unit tests. | ||
/// | ||
/// The prefix "Std" means "the standard result within the standard library". This is not the only | ||
/// result/error type in cosmwasm-std. | ||
/// `StdResult` is typically used in scenarios where a function within the contract needs to return a result or indicate an error | ||
/// that is specific to the contract's internal operations. Since the error component of `StdResult` is not meant for JSON serialization, | ||
/// it should be used with caution when designing functions that interact with external systems or data formats. | ||
costa2400 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub type StdResult<T> = core::result::Result<T, StdError>; | ||
/// Indicates operations that are prone to overflow. | ||
/// Used to mark numerical operations where overflow checks are necessary. | ||
|
||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum OverflowOperation { | ||
|
@@ -415,7 +415,7 @@ impl fmt::Display for OverflowOperation { | |
write!(f, "{self:?}") | ||
} | ||
} | ||
|
||
/// An error struct used when a numeric operation results in an overflow. | ||
#[derive(Error, Debug, PartialEq, Eq)] | ||
#[error("Cannot {operation} with given operands")] | ||
pub struct OverflowError { | ||
|
@@ -449,7 +449,7 @@ impl ConversionOverflowError { | |
} | ||
} | ||
} | ||
|
||
///An error struct used when a division operation in a contract attempts to divide by zero. | ||
#[derive(Error, Debug, Default, PartialEq, Eq)] | ||
#[error("Cannot divide by zero")] | ||
pub struct DivideByZeroError; | ||
|
@@ -468,7 +468,8 @@ pub enum DivisionError { | |
#[error("Overflow in division")] | ||
Overflow, | ||
} | ||
|
||
/// Errors that occur when multiplying a value by a [Fraction](crate::Fraction) in a checked manner. | ||
/// Ensures overflow safety in the operation. | ||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum CheckedMultiplyFractionError { | ||
#[error("{0}")] | ||
|
@@ -480,7 +481,8 @@ pub enum CheckedMultiplyFractionError { | |
#[error("{0}")] | ||
Overflow(#[from] OverflowError), | ||
} | ||
|
||
/// Represents errors during safe multiplication of a number by a fraction. | ||
costa2400 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Ensures accuracy and overflow prevention in calculations. | ||
costa2400 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum CheckedMultiplyRatioError { | ||
#[error("Denominator must not be zero")] | ||
|
@@ -489,7 +491,8 @@ pub enum CheckedMultiplyRatioError { | |
#[error("Multiplication overflow")] | ||
Overflow, | ||
} | ||
|
||
/// Errors that occur when safely converting from a ratio type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not really about a ratio type. It's returned for example here and also for all the versions of that functions for the different types of decimals. |
||
/// Ensures mathematical accuracy and prevents potential overflow issues. | ||
costa2400 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum CheckedFromRatioError { | ||
#[error("Denominator must not be zero")] | ||
|
@@ -506,7 +509,8 @@ pub struct RoundUpOverflowError; | |
#[derive(Error, Debug, PartialEq, Eq)] | ||
#[error("Round down operation failed because of overflow")] | ||
pub struct RoundDownOverflowError; | ||
|
||
/// General errors related to operations with coins, | ||
/// such as invalid amounts or unsupported denominations. | ||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum CoinsError { | ||
#[error("Duplicate denom")] | ||
|
@@ -518,7 +522,8 @@ impl From<CoinsError> for StdError { | |
Self::generic_err(format!("Creating Coins: {value}")) | ||
} | ||
} | ||
|
||
/// Errors encountered when parsing coin values from strings. | ||
/// Ensures that coin strings are in the correct format and valid. | ||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum CoinFromStrError { | ||
#[error("Missing denominator")] | ||
|
@@ -786,4 +791,4 @@ mod tests { | |
err => panic!("Unexpected error: {err:?}"), | ||
} | ||
} | ||
} | ||
} | ||
costa2400 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,7 +26,7 @@ use super::Int128; | |||||
pub struct SignedDecimal(#[schemars(with = "String")] Int128); | ||||||
|
||||||
forward_ref_partial_eq!(SignedDecimal, SignedDecimal); | ||||||
|
||||||
///Similar to `SignedDecimal256RangeExceeded`, but for standard `SignedDecimal` operations. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use brackets here, we can link to the type, so it's easier to navigate:
Suggested change
|
||||||
#[derive(Error, Debug, PartialEq, Eq)] | ||||||
#[error("SignedDecimal range exceeded")] | ||||||
pub struct SignedDecimalRangeExceeded; | ||||||
|
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 to have a doc comment here. I think we can be a bit more specific: