Move types to more appropriate files (#10638)
This commit is contained in:
@ -39,13 +39,13 @@ use solana_sdk::{
|
|||||||
bpf_loader,
|
bpf_loader,
|
||||||
clock::{Epoch, Slot, DEFAULT_TICKS_PER_SECOND},
|
clock::{Epoch, Slot, DEFAULT_TICKS_PER_SECOND},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
|
decode_error::DecodeError,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
loader_instruction,
|
loader_instruction,
|
||||||
message::Message,
|
message::Message,
|
||||||
native_token::lamports_to_sol,
|
native_token::lamports_to_sol,
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::{Pubkey, MAX_SEED_LEN},
|
pubkey::{Pubkey, MAX_SEED_LEN},
|
||||||
signature::{Keypair, Signature, Signer, SignerError},
|
signature::{Keypair, Signature, Signer, SignerError},
|
||||||
signers::Signers,
|
signers::Signers,
|
||||||
|
@ -5,11 +5,11 @@ use num_derive::FromPrimitive;
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
|
decode_error::DecodeError,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
entrypoint::ProgramResult,
|
entrypoint::ProgramResult,
|
||||||
info,
|
info,
|
||||||
program_error::{PrintProgramError, ProgramError},
|
program_error::{PrintProgramError, ProgramError},
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -12,14 +12,14 @@ use solana_rbpf::{
|
|||||||
EbpfVm,
|
EbpfVm,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount,
|
account::{is_executable, next_keyed_account, KeyedAccount},
|
||||||
bpf_loader,
|
bpf_loader,
|
||||||
|
decode_error::DecodeError,
|
||||||
entrypoint::SUCCESS,
|
entrypoint::SUCCESS,
|
||||||
entrypoint_native::InvokeContext,
|
entrypoint_native::InvokeContext,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
loader_instruction::LoaderInstruction,
|
loader_instruction::LoaderInstruction,
|
||||||
program_utils::DecodeError,
|
program_utils::limited_deserialize,
|
||||||
program_utils::{is_executable, limited_deserialize, next_keyed_account},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use std::{io::prelude::*, mem};
|
use std::{io::prelude::*, mem};
|
||||||
|
@ -4,9 +4,9 @@ use chrono::prelude::{DateTime, Utc};
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
decode_error::DecodeError,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
};
|
};
|
||||||
|
@ -7,10 +7,10 @@ use crate::{
|
|||||||
use chrono::prelude::{DateTime, Utc};
|
use chrono::prelude::{DateTime, Utc};
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount,
|
account::{next_keyed_account, KeyedAccount},
|
||||||
hash::hash,
|
hash::hash,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
use crate::ConfigKeys;
|
use crate::ConfigKeys;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::{next_keyed_account, KeyedAccount};
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::program_utils::{limited_deserialize, next_keyed_account};
|
use solana_sdk::program_utils::limited_deserialize;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
|
@ -8,8 +8,8 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
|||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use solana_metrics::inc_new_counter_info;
|
use solana_metrics::inc_new_counter_info;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount, instruction::InstructionError, program_utils::limited_deserialize,
|
account::KeyedAccount, decode_error::DecodeError, instruction::InstructionError,
|
||||||
program_utils::DecodeError, pubkey::Pubkey,
|
program_utils::limited_deserialize, pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -6,13 +6,13 @@ use log::*;
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount,
|
account::{is_executable, next_keyed_account, KeyedAccount},
|
||||||
account_utils::State,
|
account_utils::State,
|
||||||
|
decode_error::DecodeError,
|
||||||
entrypoint_native::InvokeContext,
|
entrypoint_native::InvokeContext,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
move_loader::id,
|
move_loader::id,
|
||||||
program_utils::DecodeError,
|
program_utils::limited_deserialize,
|
||||||
program_utils::{is_executable, limited_deserialize, next_keyed_account},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
decode_error::DecodeError,
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
};
|
};
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
use crate::ownable_instruction::OwnableError;
|
use crate::ownable_instruction::OwnableError;
|
||||||
use bincode::serialize_into;
|
use bincode::serialize_into;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount,
|
account::{next_keyed_account, KeyedAccount},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,10 +6,11 @@ use log::*;
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, KeyedAccount},
|
account::{get_signers, next_keyed_account, KeyedAccount},
|
||||||
clock::{Epoch, UnixTimestamp},
|
clock::{Epoch, UnixTimestamp},
|
||||||
|
decode_error::DecodeError,
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
program_utils::{limited_deserialize, next_keyed_account, DecodeError},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
sysvar::{self, clock::Clock, rent::Rent, stake_history::StakeHistory, Sysvar},
|
sysvar::{self, clock::Clock, rent::Rent, stake_history::StakeHistory, Sysvar},
|
||||||
|
@ -4,8 +4,8 @@ use chrono::prelude::{Date, DateTime, Utc};
|
|||||||
use num_derive::FromPrimitive;
|
use num_derive::FromPrimitive;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
decode_error::DecodeError,
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
};
|
};
|
||||||
|
@ -7,9 +7,9 @@ use chrono::prelude::*;
|
|||||||
use solana_config_program::date_instruction::DateConfig;
|
use solana_config_program::date_instruction::DateConfig;
|
||||||
use solana_config_program::get_config_data;
|
use solana_config_program::get_config_data;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{Account, KeyedAccount},
|
account::{next_keyed_account, Account, KeyedAccount},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use std::cell::RefMut;
|
use std::cell::RefMut;
|
||||||
|
@ -10,10 +10,11 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_metrics::inc_new_counter_info;
|
use solana_metrics::inc_new_counter_info;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, KeyedAccount},
|
account::{get_signers, next_keyed_account, KeyedAccount},
|
||||||
|
decode_error::DecodeError,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
program_utils::{limited_deserialize, next_keyed_account, DecodeError},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
sysvar::{self, clock::Clock, slot_hashes::SlotHashes, Sysvar},
|
sysvar::{self, clock::Clock, slot_hashes::SlotHashes, Sysvar},
|
||||||
|
@ -738,10 +738,9 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::vote_state;
|
use crate::vote_state;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, Account},
|
account::{get_signers, next_keyed_account, Account},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
hash::hash,
|
hash::hash,
|
||||||
program_utils::next_keyed_account,
|
|
||||||
};
|
};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, Account, KeyedAccount},
|
account::{get_signers, next_keyed_account, Account, KeyedAccount},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
nonce::Account as NonceAccount,
|
nonce::Account as NonceAccount,
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
||||||
system_program,
|
system_program,
|
||||||
|
@ -6,10 +6,10 @@ use libloading::os::windows::*;
|
|||||||
use log::*;
|
use log::*;
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::KeyedAccount,
|
account::{next_keyed_account, KeyedAccount},
|
||||||
|
decode_error::DecodeError,
|
||||||
entrypoint_native::{InvokeContext, LoaderEntrypoint, ProgramEntrypoint},
|
entrypoint_native::{InvokeContext, LoaderEntrypoint, ProgramEntrypoint},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
program_utils::{next_keyed_account, DecodeError},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, env, path::PathBuf, str, sync::RwLock};
|
use std::{collections::HashMap, env, path::PathBuf, str, sync::RwLock};
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, Account, KeyedAccount},
|
account::{get_signers, next_keyed_account, Account, KeyedAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
nonce::{self, Account as NonceAccount},
|
nonce::{self, Account as NonceAccount},
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
||||||
system_program,
|
system_program,
|
||||||
|
@ -286,3 +286,16 @@ where
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect::<A>()
|
.collect::<A>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the next KeyedAccount or a NotEnoughAccountKeys error
|
||||||
|
pub fn next_keyed_account<'a, 'b, I: Iterator<Item = &'a KeyedAccount<'b>>>(
|
||||||
|
iter: &mut I,
|
||||||
|
) -> Result<I::Item, InstructionError> {
|
||||||
|
iter.next().ok_or(InstructionError::NotEnoughAccountKeys)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return true if the first keyed_account is executable, used to determine if
|
||||||
|
/// the loader should call a program's 'main'
|
||||||
|
pub fn is_executable(keyed_accounts: &[KeyedAccount]) -> Result<bool, InstructionError> {
|
||||||
|
Ok(!keyed_accounts.is_empty() && keyed_accounts[0].executable()?)
|
||||||
|
}
|
||||||
|
@ -216,3 +216,10 @@ pub fn create_is_signer_account_infos<'a>(
|
|||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the next AccountInfo or a NotEnoughAccountKeys error
|
||||||
|
pub fn next_account_info<'a, 'b, I: Iterator<Item = &'a AccountInfo<'b>>>(
|
||||||
|
iter: &mut I,
|
||||||
|
) -> Result<I::Item, ProgramError> {
|
||||||
|
iter.next().ok_or(ProgramError::NotEnoughAccountKeys)
|
||||||
|
}
|
||||||
|
38
sdk/src/decode_error.rs
Normal file
38
sdk/src/decode_error.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
|
/// Allows customer errors to be decoded back to their original enum
|
||||||
|
pub trait DecodeError<E> {
|
||||||
|
fn decode_custom_error_to_enum(custom: u32) -> Option<E>
|
||||||
|
where
|
||||||
|
E: FromPrimitive,
|
||||||
|
{
|
||||||
|
E::from_u32(custom)
|
||||||
|
}
|
||||||
|
fn type_of() -> &'static str;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use num_derive::FromPrimitive;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_decode_custom_error_to_enum() {
|
||||||
|
#[derive(Debug, FromPrimitive, PartialEq)]
|
||||||
|
enum TestEnum {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
}
|
||||||
|
impl<T> DecodeError<T> 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> = TestEnum::decode_custom_error_to_enum(3);
|
||||||
|
assert_eq!(option, None);
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ pub mod account_utils;
|
|||||||
pub mod bpf_loader;
|
pub mod bpf_loader;
|
||||||
pub mod clock;
|
pub mod clock;
|
||||||
pub mod commitment_config;
|
pub mod commitment_config;
|
||||||
|
pub mod decode_error;
|
||||||
pub mod entrypoint_native;
|
pub mod entrypoint_native;
|
||||||
pub mod epoch_info;
|
pub mod epoch_info;
|
||||||
pub mod epoch_schedule;
|
pub mod epoch_schedule;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{instruction::InstructionError, program_utils::DecodeError};
|
use crate::{decode_error::DecodeError, instruction::InstructionError};
|
||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -1,28 +1,4 @@
|
|||||||
use crate::{
|
use crate::instruction::InstructionError;
|
||||||
account::KeyedAccount, account_info::AccountInfo, instruction::InstructionError,
|
|
||||||
program_error::ProgramError,
|
|
||||||
};
|
|
||||||
use num_traits::FromPrimitive;
|
|
||||||
|
|
||||||
/// Return the next KeyedAccount or a NotEnoughAccountKeys error
|
|
||||||
pub fn next_keyed_account<'a, 'b, I: Iterator<Item = &'a KeyedAccount<'b>>>(
|
|
||||||
iter: &mut I,
|
|
||||||
) -> Result<I::Item, InstructionError> {
|
|
||||||
iter.next().ok_or(InstructionError::NotEnoughAccountKeys)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the next AccountInfo or a NotEnoughAccountKeys error
|
|
||||||
pub fn next_account_info<'a, 'b, I: Iterator<Item = &'a AccountInfo<'b>>>(
|
|
||||||
iter: &mut I,
|
|
||||||
) -> Result<I::Item, ProgramError> {
|
|
||||||
iter.next().ok_or(ProgramError::NotEnoughAccountKeys)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return true if the first keyed_account is executable, used to determine if
|
|
||||||
/// the loader should call a program's 'main'
|
|
||||||
pub fn is_executable(keyed_accounts: &[KeyedAccount]) -> Result<bool, InstructionError> {
|
|
||||||
Ok(!keyed_accounts.is_empty() && keyed_accounts[0].executable()?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserialize with a limit based the maximum amount of data a program can expect to get.
|
/// Deserialize with a limit based the maximum amount of data a program can expect to get.
|
||||||
/// This function should be used in place of direct deserialization to help prevent OOM errors
|
/// This function should be used in place of direct deserialization to help prevent OOM errors
|
||||||
@ -36,40 +12,3 @@ where
|
|||||||
.deserialize(instruction_data)
|
.deserialize(instruction_data)
|
||||||
.map_err(|_| InstructionError::InvalidInstructionData)
|
.map_err(|_| InstructionError::InvalidInstructionData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows customer errors to be decoded back to their original enum
|
|
||||||
pub trait DecodeError<E> {
|
|
||||||
fn decode_custom_error_to_enum(custom: u32) -> Option<E>
|
|
||||||
where
|
|
||||||
E: FromPrimitive,
|
|
||||||
{
|
|
||||||
E::from_u32(custom)
|
|
||||||
}
|
|
||||||
fn type_of() -> &'static str;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use num_derive::FromPrimitive;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_decode_custom_error_to_enum() {
|
|
||||||
#[derive(Debug, FromPrimitive, PartialEq)]
|
|
||||||
enum TestEnum {
|
|
||||||
A,
|
|
||||||
B,
|
|
||||||
C,
|
|
||||||
}
|
|
||||||
impl<T> DecodeError<T> 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> = TestEnum::decode_custom_error_to_enum(3);
|
|
||||||
assert_eq!(option, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
decode_error::DecodeError,
|
||||||
hash::{hash, hashv, Hasher},
|
hash::{hash, hashv, Hasher},
|
||||||
program_utils::DecodeError,
|
|
||||||
};
|
};
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
#[cfg(not(feature = "program"))]
|
#[cfg(not(feature = "program"))]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
decode_error::DecodeError,
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
nonce,
|
nonce,
|
||||||
program_utils::DecodeError,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_program,
|
system_program,
|
||||||
sysvar::{recent_blockhashes, rent},
|
sysvar::{recent_blockhashes, rent},
|
||||||
|
Reference in New Issue
Block a user