diff --git a/Cargo.lock b/Cargo.lock index 41d5941fe..4e7c8a8dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2977,8 +2977,9 @@ dependencies = [ [[package]] name = "solana-decode-error" version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c781686a18db2f942e70913f7ca15dc120ec38dcab42ff7557db2c70c625a35" dependencies = [ - "num-derive", "num-traits", ] @@ -3540,7 +3541,6 @@ name = "solana-precompile-error" version = "2.2.2" dependencies = [ "num-traits", - "solana-decode-error", ] [[package]] @@ -3596,7 +3596,6 @@ dependencies = [ "solana-borsh", "solana-clock", "solana-cpi", - "solana-decode-error", "solana-define-syscall", "solana-epoch-rewards", "solana-epoch-schedule", @@ -3654,7 +3653,6 @@ dependencies = [ "num_enum", "serde", "serde_derive", - "solana-decode-error", "solana-instruction", "solana-msg", "solana-pubkey", @@ -3699,7 +3697,6 @@ dependencies = [ "serde", "serde_derive", "solana-atomic-u64", - "solana-decode-error", "solana-define-syscall", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -4226,7 +4223,6 @@ dependencies = [ "serde", "serde_derive", "solana-clock", - "solana-decode-error", "solana-epoch-schedule", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/Cargo.toml b/Cargo.toml index 2e94c8168..592a2731f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ members = [ "commitment-config", "compute-budget-interface", "cpi", - "decode-error", "define-syscall", "derivation-path", "ed25519-program", @@ -224,7 +223,6 @@ solana-cluster-type = { path = "cluster-type", version = "2.2.1" } solana-commitment-config = { path = "commitment-config", version = "2.2.1" } solana-compute-budget-interface = { path = "compute-budget-interface", version = "2.2.1" } solana-cpi = { path = "cpi", version = "2.2.1" } -solana-decode-error = { path = "decode-error", version = "2.2.1" } solana-define-syscall = { path = "define-syscall", version = "2.2.1" } solana-derivation-path = { path = "derivation-path", version = "2.2.1" } solana-ed25519-program = { path = "ed25519-program", version = "2.2.1" } @@ -361,7 +359,6 @@ opt-level = 1 solana-account = { path = "account" } solana-clock = { path = "clock" } solana-cpi = { path = "cpi" } -solana-decode-error = { path = "decode-error" } solana-frozen-abi = { path = "frozen-abi" } solana-frozen-abi-macro = { path = "frozen-abi-macro" } solana-instruction = { path = "instruction" } diff --git a/decode-error/Cargo.toml b/decode-error/Cargo.toml deleted file mode 100644 index d2ffbce28..000000000 --- a/decode-error/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "solana-decode-error" -description = "Solana DecodeError Trait" -documentation = "https://docs.rs/solana-decode-error" -version = "2.3.0" -authors = { workspace = true } -repository = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -edition = { workspace = true } - -[dependencies] -num-traits = { workspace = true } - -[dev-dependencies] -num-derive = { workspace = true } diff --git a/decode-error/src/lib.rs b/decode-error/src/lib.rs deleted file mode 100644 index fb4aa992b..000000000 --- a/decode-error/src/lib.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! Converting custom error codes to enums. - -use num_traits::FromPrimitive; - -/// Allows custom errors to be decoded back to their original enum. -/// -/// Some Solana error enums, like [`ProgramError`], include a `Custom` variant, -/// like [`ProgramError::Custom`], that contains a `u32` error code. This code -/// may represent any error that is not covered by the error enum's named -/// variants. It is common for programs to convert their own error enums to an -/// error code and store it in the `Custom` variant, possibly with the help of -/// the [`ToPrimitive`] trait. -/// -/// This trait builds on the [`FromPrimitive`] trait to help convert those error -/// codes to the original error enum they represent. -/// -/// As this allows freely converting `u32` to any type that implements -/// `FromPrimitive`, it is only used correctly when the caller is certain of the -/// original error type. -/// -/// [`ProgramError`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html -/// [`ProgramError::Custom`]: https://docs.rs/solana-program-error/latest/solana_program_error/enum.ProgramError.html#variant.Custom -/// [`ToPrimitive`]: num_traits::ToPrimitive -#[deprecated( - since = "2.3.0", - note = "Implement `solana_program_error::ToStr` and `TryFrom` by hand or with `num_enum::TryFromPrimitive` instead" -)] -pub trait DecodeError { - fn decode_custom_error_to_enum(custom: u32) -> Option - where - E: FromPrimitive, - { - E::from_u32(custom) - } - fn type_of() -> &'static str; -} - -#[cfg(test)] -#[allow(deprecated)] -mod tests { - use {super::*, num_derive::FromPrimitive}; - - #[test] - fn test_decode_custom_error_to_enum() { - #[derive(Debug, FromPrimitive, PartialEq, Eq)] - enum TestEnum { - A, - B, - C, - } - impl DecodeError for TestEnum { - fn type_of() -> &'static str { - "TestEnum" - } - } - assert_eq!(TestEnum::decode_custom_error_to_enum(0), Some(TestEnum::A)); - assert_eq!(TestEnum::decode_custom_error_to_enum(1), Some(TestEnum::B)); - assert_eq!(TestEnum::decode_custom_error_to_enum(2), Some(TestEnum::C)); - let option: Option = TestEnum::decode_custom_error_to_enum(3); - assert_eq!(option, None); - } -} diff --git a/precompile-error/Cargo.toml b/precompile-error/Cargo.toml index 21d5e58dc..5409b3cfc 100644 --- a/precompile-error/Cargo.toml +++ b/precompile-error/Cargo.toml @@ -14,4 +14,3 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] num-traits = { workspace = true } -solana-decode-error = { workspace = true } diff --git a/precompile-error/src/lib.rs b/precompile-error/src/lib.rs index c315cb405..6c3e2a000 100644 --- a/precompile-error/src/lib.rs +++ b/precompile-error/src/lib.rs @@ -68,10 +68,3 @@ impl fmt::Display for PrecompileError { } } } - -#[allow(deprecated)] -impl solana_decode_error::DecodeError for PrecompileError { - fn type_of() -> &'static str { - "PrecompileError" - } -} diff --git a/program-error/Cargo.toml b/program-error/Cargo.toml index 736c496a0..6488205a5 100644 --- a/program-error/Cargo.toml +++ b/program-error/Cargo.toml @@ -23,7 +23,6 @@ borsh = { workspace = true, optional = true } num-traits = { workspace = true } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } -solana-decode-error = { workspace = true } solana-instruction = { workspace = true, default-features = false, features = [ "std", ] } diff --git a/program-error/src/lib.rs b/program-error/src/lib.rs index e9680e5ff..b936d9dd6 100644 --- a/program-error/src/lib.rs +++ b/program-error/src/lib.rs @@ -129,26 +129,18 @@ impl fmt::Display for ProgramError { pub trait PrintProgramError { fn print(&self) where - E: 'static - + std::error::Error - + solana_decode_error::DecodeError - + PrintProgramError - + FromPrimitive; + E: 'static + std::error::Error + PrintProgramError + FromPrimitive; } #[allow(deprecated)] impl PrintProgramError for ProgramError { fn print(&self) where - E: 'static - + std::error::Error - + solana_decode_error::DecodeError - + PrintProgramError - + FromPrimitive, + E: 'static + std::error::Error + PrintProgramError + FromPrimitive, { match self { Self::Custom(error) => { - if let Some(custom_error) = E::decode_custom_error_to_enum(*error) { + if let Some(custom_error) = E::from_u32(*error) { custom_error.print::(); } else { msg!("Error: Unknown"); diff --git a/program/Cargo.toml b/program/Cargo.toml index c99dc1bbc..40aaf6dbe 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -66,7 +66,6 @@ solana-blake3-hasher = { workspace = true, features = ["blake3"] } solana-borsh = { workspace = true, optional = true } solana-clock = { workspace = true, features = ["serde", "sysvar"] } solana-cpi = { workspace = true } -solana-decode-error = { workspace = true } solana-epoch-rewards = { workspace = true, features = ["serde", "sysvar"] } solana-epoch-schedule = { workspace = true, features = ["serde", "sysvar"] } solana-fee-calculator = { workspace = true, features = ["serde"] } diff --git a/pubkey/Cargo.toml b/pubkey/Cargo.toml index 91dad8ad4..a7fc27149 100644 --- a/pubkey/Cargo.toml +++ b/pubkey/Cargo.toml @@ -39,7 +39,6 @@ rand = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-atomic-u64 = { workspace = true } -solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, optional = true, features = [ "frozen-abi", ] } diff --git a/pubkey/src/lib.rs b/pubkey/src/lib.rs index ca143d865..6c26bd646 100644 --- a/pubkey/src/lib.rs +++ b/pubkey/src/lib.rs @@ -119,12 +119,6 @@ impl fmt::Display for PubkeyError { } } -#[allow(deprecated)] -impl solana_decode_error::DecodeError for PubkeyError { - fn type_of() -> &'static str { - "PubkeyError" - } -} impl From for PubkeyError { fn from(error: u64) -> Self { match error { @@ -381,13 +375,6 @@ impl From for ParsePubkeyError { } } -#[allow(deprecated)] -impl solana_decode_error::DecodeError for ParsePubkeyError { - fn type_of() -> &'static str { - "ParsePubkeyError" - } -} - impl FromStr for Pubkey { type Err = ParsePubkeyError; diff --git a/scripts/patch-crates-functions.sh b/scripts/patch-crates-functions.sh index 15f439619..b930449a4 100644 --- a/scripts/patch-crates-functions.sh +++ b/scripts/patch-crates-functions.sh @@ -22,7 +22,6 @@ crate_dirs=( commitment-config compute-budget-interface cpi - decode-error define-syscall derivation-path ed25519-program diff --git a/vote-interface/Cargo.toml b/vote-interface/Cargo.toml index 0b6993704..53c284bf9 100644 --- a/vote-interface/Cargo.toml +++ b/vote-interface/Cargo.toml @@ -51,7 +51,6 @@ num-traits = { workspace = true } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-clock = { workspace = true } -solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, features = [ "frozen-abi", ], optional = true } diff --git a/vote-interface/src/error.rs b/vote-interface/src/error.rs index 46b27747c..82c6cd615 100644 --- a/vote-interface/src/error.rs +++ b/vote-interface/src/error.rs @@ -71,42 +71,3 @@ impl fmt::Display for VoteError { }) } } - -#[allow(deprecated)] -impl solana_decode_error::DecodeError for VoteError { - fn type_of() -> &'static str { - "VoteError" - } -} - -#[cfg(test)] -mod tests { - use {super::*, solana_instruction::error::InstructionError}; - - #[test] - fn test_custom_error_decode() { - use num_traits::FromPrimitive; - #[allow(deprecated)] - fn pretty_err(err: InstructionError) -> String - where - T: 'static + std::error::Error + solana_decode_error::DecodeError + FromPrimitive, - { - if let InstructionError::Custom(code) = err { - let specific_error: T = T::decode_custom_error_to_enum(code).unwrap(); - format!( - "{:?}: {}::{:?} - {}", - err, - T::type_of(), - specific_error, - specific_error, - ) - } else { - "".to_string() - } - } - assert_eq!( - "Custom(0): VoteError::VoteTooOld - vote already recorded or not in slot hashes history", - pretty_err::(VoteError::VoteTooOld.into()) - ) - } -}