WritableAccount.add/subtract_lamports (#16750)
* add/sub lamports * make add/sub return Result * sample replacements * cleanup * fix up a few tests as examples * move enum, cleanup, impl from * fmt * cleanup * add lamports.rs
This commit is contained in:
committed by
GitHub
parent
be29568318
commit
48c07d32f0
22
sdk/program/src/lamports.rs
Normal file
22
sdk/program/src/lamports.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use crate::instruction::InstructionError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum LamportsError {
|
||||
/// arithmetic underflowed
|
||||
#[error("Arithmetic underflowed")]
|
||||
ArithmeticUnderflow,
|
||||
|
||||
/// arithmetic overflowed
|
||||
#[error("Arithmetic overflowed")]
|
||||
ArithmeticOverflow,
|
||||
}
|
||||
|
||||
impl From<LamportsError> for InstructionError {
|
||||
fn from(error: LamportsError) -> Self {
|
||||
match error {
|
||||
LamportsError::ArithmeticOverflow => InstructionError::ArithmeticOverflow,
|
||||
LamportsError::ArithmeticUnderflow => InstructionError::ArithmeticOverflow,
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ pub mod fee_calculator;
|
||||
pub mod hash;
|
||||
pub mod incinerator;
|
||||
pub mod instruction;
|
||||
pub mod lamports;
|
||||
pub mod loader_instruction;
|
||||
pub mod loader_upgradeable_instruction;
|
||||
pub mod log;
|
||||
|
Reference in New Issue
Block a user