nudge (#7887)
This commit is contained in:
parent
cccaacee36
commit
52bc4a3598
|
@ -61,12 +61,12 @@ impl fmt::Debug for Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Account {
|
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Self {
|
||||||
Account {
|
Self {
|
||||||
lamports,
|
lamports,
|
||||||
data: vec![0u8; space],
|
data: vec![0u8; space],
|
||||||
owner: *owner,
|
owner: *owner,
|
||||||
..Account::default()
|
..Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,13 +74,13 @@ impl Account {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
state: &T,
|
state: &T,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<Account, bincode::Error> {
|
) -> Result<Self, bincode::Error> {
|
||||||
let data = bincode::serialize(state)?;
|
let data = bincode::serialize(state)?;
|
||||||
Ok(Account {
|
Ok(Self {
|
||||||
lamports,
|
lamports,
|
||||||
data,
|
data,
|
||||||
owner: *owner,
|
owner: *owner,
|
||||||
..Account::default()
|
..Self::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl Account {
|
||||||
state: &T,
|
state: &T,
|
||||||
space: usize,
|
space: usize,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<Account, bincode::Error> {
|
) -> Result<Self, bincode::Error> {
|
||||||
let mut account = Self::new(lamports, space, owner);
|
let mut account = Self::new(lamports, space, owner);
|
||||||
|
|
||||||
account.serialize_data(state)?;
|
account.serialize_data(state)?;
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub enum InstructionError {
|
||||||
/// A non-system program changed the size of the account data
|
/// A non-system program changed the size of the account data
|
||||||
AccountDataSizeChanged,
|
AccountDataSizeChanged,
|
||||||
|
|
||||||
/// the instruction expected an executable account
|
/// The instruction expected an executable account
|
||||||
AccountNotExecutable,
|
AccountNotExecutable,
|
||||||
|
|
||||||
/// CustomError allows on-chain programs to implement program-specific error types and see
|
/// CustomError allows on-chain programs to implement program-specific error types and see
|
||||||
|
|
|
@ -5,7 +5,7 @@ use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
pub type Entrypoint = unsafe extern "C" fn(
|
pub type Entrypoint = unsafe extern "C" fn(
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
data: &[u8],
|
instruction_data: &[u8],
|
||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
|
|
||||||
/// Convenience macro to declare a native program
|
/// Convenience macro to declare a native program
|
||||||
|
@ -29,7 +29,7 @@ pub type Entrypoint = unsafe extern "C" fn(
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
/// program_id: &Pubkey,
|
||||||
/// keyed_accounts: &mut [KeyedAccount],
|
/// keyed_accounts: &mut [KeyedAccount],
|
||||||
/// data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
/// ) -> Result<(), InstructionError> {
|
/// ) -> Result<(), InstructionError> {
|
||||||
/// // Process an instruction
|
/// // Process an instruction
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
|
@ -60,7 +60,7 @@ pub type Entrypoint = unsafe extern "C" fn(
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
/// program_id: &Pubkey,
|
||||||
/// keyed_accounts: &mut [KeyedAccount],
|
/// keyed_accounts: &mut [KeyedAccount],
|
||||||
/// data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
/// ) -> Result<(), InstructionError> {
|
/// ) -> Result<(), InstructionError> {
|
||||||
/// // Process an instruction
|
/// // Process an instruction
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
|
@ -92,9 +92,9 @@ macro_rules! declare_program(
|
||||||
pub extern "C" fn $name(
|
pub extern "C" fn $name(
|
||||||
program_id: &$crate::pubkey::Pubkey,
|
program_id: &$crate::pubkey::Pubkey,
|
||||||
keyed_accounts: &mut [$crate::account::KeyedAccount],
|
keyed_accounts: &mut [$crate::account::KeyedAccount],
|
||||||
data: &[u8],
|
instruction_data: &[u8],
|
||||||
) -> Result<(), $crate::instruction::InstructionError> {
|
) -> Result<(), $crate::instruction::InstructionError> {
|
||||||
$entrypoint(program_id, keyed_accounts, data)
|
$entrypoint(program_id, keyed_accounts, instruction_data)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -119,14 +119,14 @@ pub fn is_executable(keyed_accounts: &[KeyedAccount]) -> bool {
|
||||||
!keyed_accounts.is_empty() && keyed_accounts[0].account.executable
|
!keyed_accounts.is_empty() && keyed_accounts[0].account.executable
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn limited_deserialize<T>(data: &[u8]) -> Result<T, InstructionError>
|
pub fn limited_deserialize<T>(instruction_data: &[u8]) -> Result<T, InstructionError>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
let limit = crate::packet::PACKET_DATA_SIZE as u64;
|
let limit = crate::packet::PACKET_DATA_SIZE as u64;
|
||||||
bincode::config()
|
bincode::config()
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.deserialize(data)
|
.deserialize(instruction_data)
|
||||||
.map_err(|_| InstructionError::InvalidInstructionData)
|
.map_err(|_| InstructionError::InvalidInstructionData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue