Skip to content

Commit

Permalink
Update Substrate error types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium committed Jan 9, 2025
1 parent 5e530d6 commit e143d14
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh-api"
version = "3.10.0"
version = "3.10.1"
edition = "2021"
authors = ["Robert G. Jakabosky <robert@polymesh.network>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -33,9 +33,9 @@ members = [
# Our crates
polymesh-api-client = { version = "3.8.2", path = "crates/polymesh-api-client", default-features = false }
polymesh-api-ink = { version = "1.5.0", path = "crates/polymesh-api-ink", default-features = false }
polymesh-api-codegen = { version = "3.6.2", path = "crates/polymesh-api-codegen", default-features = false }
polymesh-api-codegen-macro = { version = "3.6.2", path = "crates/polymesh-api-codegen-macro", default-features = false }
polymesh-api = { version = "3.10.0", path = "./", default-features = false }
polymesh-api-codegen = { version = "3.6.3", path = "crates/polymesh-api-codegen", default-features = false }
polymesh-api-codegen-macro = { version = "3.6.3", path = "crates/polymesh-api-codegen-macro", default-features = false }
polymesh-api = { version = "3.10.1", path = "./", default-features = false }
polymesh-api-client-extras = { version = "3.5.0", path = "crates/polymesh-api-client-extras", default-features = false }
polymesh-api-tester = { version = "0.9.0", path = "crates/polymesh-api-tester", default-features = false }

Expand Down Expand Up @@ -78,6 +78,7 @@ ink = { workspace = true, optional = true, default-features = false }

# substrate
sp-arithmetic = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
codec = { version = "3", package = "parity-scale-codec", default-features = false }
scale-info = { workspace = true, default-features = false, optional = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/polymesh-api-codegen-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh-api-codegen-macro"
version = "3.6.2"
version = "3.6.3"
edition = "2021"
authors = ["Robert G. Jakabosky <robert@polymesh.network>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/polymesh-api-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh-api-codegen"
version = "3.6.2"
version = "3.6.3"
edition = "2021"
authors = ["Robert G. Jakabosky <robert@polymesh.network>"]
license = "Apache-2.0"
Expand Down
57 changes: 20 additions & 37 deletions crates/polymesh-api-codegen/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,13 @@ mod v14 {
ConsumerRemaining,
NoProviders,
TooManyConsumers,
Token(TokenError),
Token(::sp_runtime::TokenError),
Arithmetic(::sp_arithmetic::ArithmeticError),
Transactional(::sp_runtime::TransactionalError),
Exhausted,
Corruption,
Unavailable,
RootNotAllowed,
}

impl #ty_ident {
Expand All @@ -1556,24 +1561,13 @@ mod v14 {
Self::ConsumerRemaining => "ConsumerRemaining",
Self::NoProviders => "NoProviders",
Self::TooManyConsumers => "TooManyConsumers",
Self::Token(err) => {
match err {
TokenError::NoFunds => "Token::NoFunds",
TokenError::WouldDie => "Token::WouldDie",
TokenError::BelowMinimum => "Token::BelowMinimum",
TokenError::CannotCreate => "Token::CannotCreate",
TokenError::UnknownAsset => "Token::UnknownAsset",
TokenError::Frozen => "Token::Frozen",
TokenError::Unsupported => "Token::Unsupported",
}
},
Self::Arithmetic(err) => {
match err {
::sp_arithmetic::ArithmeticError::Underflow => "Arithmetic::Underflow",
::sp_arithmetic::ArithmeticError::Overflow => "Arithmetic::Overflow",
::sp_arithmetic::ArithmeticError::DivisionByZero => "Arithmetic::DivisionByZero",
}
},
Self::Token(err) => (*err).into(),
Self::Arithmetic(err) => (*err).into(),
Self::Transactional(err) => (*err).into(),
Self::Exhausted => "Exhausted",
Self::Corruption => "Corruption",
Self::Unavailable => "Unavailable",
Self::RootNotAllowed => "RootNotAllowed",
}
}
}
Expand Down Expand Up @@ -1605,24 +1599,13 @@ mod v14 {
Self::ConsumerRemaining => &["At least one consumer is remaining so the account cannot be destroyed."],
Self::NoProviders => &["There are no providers so the account cannot be created."],
Self::TooManyConsumers => &["There are too many consumers so the account cannot be created."],
Self::Token(err) => {
match err {
TokenError::NoFunds => &["Funds are unavailable."],
TokenError::WouldDie => &["Account that must exist would die."],
TokenError::BelowMinimum => &["Account cannot exist with the funds that would be given."],
TokenError::CannotCreate => &["Account cannot be created."],
TokenError::UnknownAsset => &["The asset in question is unknown."],
TokenError::Frozen => &["Funds exist but are frozen."],
TokenError::Unsupported => &["Operation is not supported by the asset."],
}
},
Self::Arithmetic(err) => {
match err {
::sp_arithmetic::ArithmeticError::Underflow => &["Arithmetic underflow"],
::sp_arithmetic::ArithmeticError::Overflow => &["Arithmetic overflow"],
::sp_arithmetic::ArithmeticError::DivisionByZero => &["Arithmetic divide by zero"],
}
},
Self::Token(err) => &["An error to do with tokens."],
Self::Arithmetic(err) => &["An arithmetic error."],
Self::Transactional(err) => &["The number of transactional layers has been reached, or we are not in a transactional layer."],
Self::Exhausted => &["Resources exhausted, e.g. attempt to read/write data which is too large to manipulate."],
Self::Corruption => &["The state is corrupt; this is generally not going to fix itself."],
Self::Unavailable => &["Some resource (e.g. a preimage) is unavailable right now. This might fix itself later."],
Self::RootNotAllowed => &["Root origin is not allowed."],
}
}
}
Expand Down

0 comments on commit e143d14

Please sign in to comment.