Cleanup unsupported sysvars (#16390)

* Cleanup unsupported sysvars

* fix ser description
This commit is contained in:
Jack May
2021-04-06 00:08:03 -07:00
committed by GitHub
parent 03d3ae1cb9
commit 92f4018b07
12 changed files with 90 additions and 39 deletions

View File

@@ -43,6 +43,8 @@ pub enum ProgramError {
BorshIoError(String),
#[error("An account does not have enough lamports to be rent-exempt")]
AccountNotRentExempt,
#[error("Unsupported sysvar")]
UnsupportedSysvar,
}
pub trait PrintProgramError {
@@ -79,6 +81,7 @@ impl PrintProgramError for ProgramError {
Self::InvalidSeeds => msg!("Error: InvalidSeeds"),
Self::BorshIoError(_) => msg!("Error: BorshIoError"),
Self::AccountNotRentExempt => msg!("Error: AccountNotRentExempt"),
Self::UnsupportedSysvar => msg!("Error: UnsupportedSysvar"),
}
}
}
@@ -107,6 +110,7 @@ pub const MAX_SEED_LENGTH_EXCEEDED: u64 = to_builtin!(13);
pub const INVALID_SEEDS: u64 = to_builtin!(14);
pub const BORSH_IO_ERROR: u64 = to_builtin!(15);
pub const ACCOUNT_NOT_RENT_EXEMPT: u64 = to_builtin!(16);
pub const UNSUPPORTED_SYSVAR: u64 = to_builtin!(17);
impl From<ProgramError> for u64 {
fn from(error: ProgramError) -> Self {
@@ -126,6 +130,7 @@ impl From<ProgramError> for u64 {
ProgramError::InvalidSeeds => INVALID_SEEDS,
ProgramError::BorshIoError(_) => BORSH_IO_ERROR,
ProgramError::AccountNotRentExempt => ACCOUNT_NOT_RENT_EXEMPT,
ProgramError::UnsupportedSysvar => UNSUPPORTED_SYSVAR,
ProgramError::Custom(error) => {
if error == 0 {
@@ -154,6 +159,7 @@ impl From<u64> for ProgramError {
ACCOUNT_BORROW_FAILED => ProgramError::AccountBorrowFailed,
MAX_SEED_LENGTH_EXCEEDED => ProgramError::MaxSeedLengthExceeded,
INVALID_SEEDS => ProgramError::InvalidSeeds,
UNSUPPORTED_SYSVAR => ProgramError::UnsupportedSysvar,
CUSTOM_ZERO => ProgramError::Custom(0),
_ => ProgramError::Custom(error as u32),
}
@@ -180,6 +186,7 @@ impl TryFrom<InstructionError> for ProgramError {
Self::Error::MaxSeedLengthExceeded => Ok(Self::MaxSeedLengthExceeded),
Self::Error::BorshIoError(err) => Ok(Self::BorshIoError(err)),
Self::Error::AccountNotRentExempt => Ok(Self::AccountNotRentExempt),
Self::Error::UnsupportedSysvar => Ok(Self::UnsupportedSysvar),
_ => Err(error),
}
}
@@ -206,6 +213,7 @@ where
ACCOUNT_BORROW_FAILED => InstructionError::AccountBorrowFailed,
MAX_SEED_LENGTH_EXCEEDED => InstructionError::MaxSeedLengthExceeded,
INVALID_SEEDS => InstructionError::InvalidSeeds,
UNSUPPORTED_SYSVAR => InstructionError::UnsupportedSysvar,
_ => {
// A valid custom error has no bits set in the upper 32
if error >> BUILTIN_BIT_SHIFT == 0 {