From aaa2eed5f8dda3872daa90da2764ed95dc993202 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sat, 5 Oct 2024 12:17:54 +0400 Subject: [PATCH 1/2] move LamportsError to solana-instruction --- sdk/instruction/src/error.rs | 29 +++++++++++++++++++++++++++++ sdk/program/src/lamports.rs | 23 +---------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/sdk/instruction/src/error.rs b/sdk/instruction/src/error.rs index 5cef257b3f31cb..270659f8de054e 100644 --- a/sdk/instruction/src/error.rs +++ b/sdk/instruction/src/error.rs @@ -432,3 +432,32 @@ where } } } + +#[derive(Debug)] +pub enum LamportsError { + /// arithmetic underflowed + ArithmeticUnderflow, + /// arithmetic overflowed + ArithmeticOverflow, +} + +#[cfg(feature = "std")] +impl std::error::Error for LamportsError {} + +impl fmt::Display for LamportsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::ArithmeticUnderflow => f.write_str("Arithmetic underflowed"), + Self::ArithmeticOverflow => f.write_str("Arithmetic overflowed"), + } + } +} + +impl From for InstructionError { + fn from(error: LamportsError) -> Self { + match error { + LamportsError::ArithmeticOverflow => InstructionError::ArithmeticOverflow, + LamportsError::ArithmeticUnderflow => InstructionError::ArithmeticOverflow, + } + } +} diff --git a/sdk/program/src/lamports.rs b/sdk/program/src/lamports.rs index 91102899e029b5..595d4b1f4950f2 100644 --- a/sdk/program/src/lamports.rs +++ b/sdk/program/src/lamports.rs @@ -1,23 +1,2 @@ //! Defines the [`LamportsError`] type. - -use {crate::instruction::InstructionError, thiserror::Error}; - -#[derive(Debug, Error)] -pub enum LamportsError { - /// arithmetic underflowed - #[error("Arithmetic underflowed")] - ArithmeticUnderflow, - - /// arithmetic overflowed - #[error("Arithmetic overflowed")] - ArithmeticOverflow, -} - -impl From for InstructionError { - fn from(error: LamportsError) -> Self { - match error { - LamportsError::ArithmeticOverflow => InstructionError::ArithmeticOverflow, - LamportsError::ArithmeticUnderflow => InstructionError::ArithmeticOverflow, - } - } -} +pub use solana_instruction::error::LamportsError; From 1c6a2c07584fd69cc607368f5ab84be536f48d60 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 8 Oct 2024 21:27:09 +0400 Subject: [PATCH 2/2] nits --- sdk/program/src/lamports.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/program/src/lamports.rs b/sdk/program/src/lamports.rs index 595d4b1f4950f2..925240b9893939 100644 --- a/sdk/program/src/lamports.rs +++ b/sdk/program/src/lamports.rs @@ -1,2 +1,6 @@ -//! Defines the [`LamportsError`] type. +//! Re-exports the [`LamportsError`] type for backwards compatibility. +#[deprecated( + since = "2.1.0", + note = "Use solana_instruction::error::LamportsError instead" +)] pub use solana_instruction::error::LamportsError;