@ -67,7 +67,7 @@ fn library_open(path: &PathBuf) -> std::io::Result<Library> {
|
|||||||
pub fn invoke_entrypoint(
|
pub fn invoke_entrypoint(
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
keyed_accounts: &mut [KeyedAccount],
|
keyed_accounts: &mut [KeyedAccount],
|
||||||
ix_data: &[u8],
|
instruction_data: &[u8],
|
||||||
symbol_cache: &SymbolCache,
|
symbol_cache: &SymbolCache,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
// dispatch it
|
// dispatch it
|
||||||
@ -75,7 +75,7 @@ pub fn invoke_entrypoint(
|
|||||||
let name_vec = &names[0].account.data;
|
let name_vec = &names[0].account.data;
|
||||||
if let Some(entrypoint) = symbol_cache.read().unwrap().get(name_vec) {
|
if let Some(entrypoint) = symbol_cache.read().unwrap().get(name_vec) {
|
||||||
unsafe {
|
unsafe {
|
||||||
return entrypoint(program_id, params, ix_data);
|
return entrypoint(program_id, params, instruction_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let name = match str::from_utf8(name_vec) {
|
let name = match str::from_utf8(name_vec) {
|
||||||
@ -101,7 +101,7 @@ pub fn invoke_entrypoint(
|
|||||||
return Err(InstructionError::GenericError);
|
return Err(InstructionError::GenericError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let ret = entrypoint(program_id, params, ix_data);
|
let ret = entrypoint(program_id, params, instruction_data);
|
||||||
symbol_cache
|
symbol_cache
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -133,10 +133,10 @@ fn finish_create_account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn assign_account_to_program(
|
fn assign_account_to_program(
|
||||||
account: &mut KeyedAccount,
|
keyed_account: &mut KeyedAccount,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if account.signer_key().is_none() {
|
if keyed_account.signer_key().is_none() {
|
||||||
debug!("Assign: account must sign");
|
debug!("Assign: account must sign");
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ fn assign_account_to_program(
|
|||||||
return Err(SystemError::InvalidProgramId.into());
|
return Err(SystemError::InvalidProgramId.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
account.account.owner = *program_id;
|
keyed_account.account.owner = *program_id;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,9 +186,9 @@ fn transfer_lamports(
|
|||||||
pub fn process_instruction(
|
pub fn 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> {
|
||||||
let instruction = limited_deserialize(data)?;
|
let instruction = limited_deserialize(instruction_data)?;
|
||||||
|
|
||||||
trace!("process_instruction: {:?}", instruction);
|
trace!("process_instruction: {:?}", instruction);
|
||||||
trace!("keyed_accounts: {:?}", keyed_accounts);
|
trace!("keyed_accounts: {:?}", keyed_accounts);
|
||||||
|
@ -70,17 +70,17 @@ pub trait Sysvar:
|
|||||||
fn to_account(&self, account: &mut Account) -> Option<()> {
|
fn to_account(&self, account: &mut Account) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], self).ok()
|
bincode::serialize_into(&mut account.data[..], self).ok()
|
||||||
}
|
}
|
||||||
fn from_account_info(account: &AccountInfo) -> Option<Self> {
|
fn from_account_info(account_info: &AccountInfo) -> Option<Self> {
|
||||||
bincode::deserialize(&account.data).ok()
|
bincode::deserialize(&account_info.data).ok()
|
||||||
}
|
}
|
||||||
fn to_account_info(&self, account: &mut AccountInfo) -> Option<()> {
|
fn to_account_info(&self, account_info: &mut AccountInfo) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], self).ok()
|
bincode::serialize_into(&mut account_info.data[..], self).ok()
|
||||||
}
|
}
|
||||||
fn from_keyed_account(account: &KeyedAccount) -> Result<Self, InstructionError> {
|
fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self, InstructionError> {
|
||||||
if !Self::check_id(account.unsigned_key()) {
|
if !Self::check_id(keyed_account.unsigned_key()) {
|
||||||
return Err(InstructionError::InvalidArgument);
|
return Err(InstructionError::InvalidArgument);
|
||||||
}
|
}
|
||||||
Self::from_account(account.account).ok_or(InstructionError::InvalidArgument)
|
Self::from_account(keyed_account.account).ok_or(InstructionError::InvalidArgument)
|
||||||
}
|
}
|
||||||
fn create_account(&self, lamports: u64) -> Account {
|
fn create_account(&self, lamports: u64) -> Account {
|
||||||
let data_len = Self::size_of().max(bincode::serialized_size(self).unwrap() as usize);
|
let data_len = Self::size_of().max(bincode::serialized_size(self).unwrap() as usize);
|
||||||
|
@ -17,11 +17,14 @@ pub fn create_account(lamports: u64, rent: &Rent) -> Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_rent_exemption(
|
pub fn verify_rent_exemption(
|
||||||
account: &KeyedAccount,
|
keyed_account: &KeyedAccount,
|
||||||
rent_sysvar_account: &KeyedAccount,
|
rent_sysvar_account: &KeyedAccount,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let rent = Rent::from_keyed_account(rent_sysvar_account)?;
|
let rent = Rent::from_keyed_account(rent_sysvar_account)?;
|
||||||
if !rent.is_exempt(account.account.lamports, account.account.data.len()) {
|
if !rent.is_exempt(
|
||||||
|
keyed_account.account.lamports,
|
||||||
|
keyed_account.account.data.len(),
|
||||||
|
) {
|
||||||
Err(InstructionError::InsufficientFunds)
|
Err(InstructionError::InsufficientFunds)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Reference in New Issue
Block a user