-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: resize mapping account * fix: remove initPriceFeedIndex instr to reduce binary size * refactor: format * fix: remove explicit funding account from resizemapping ix * Apply suggestions from code review --------- Co-authored-by: Tejas Badadare <[email protected]> Co-authored-by: Ali Behjati <[email protected]>
- Loading branch information
1 parent
e722345
commit 11bd882
Showing
13 changed files
with
201 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use { | ||
crate::{ | ||
accounts::{ | ||
AccountHeader, | ||
MappingAccount, | ||
PythAccount, | ||
}, | ||
c_oracle_header::PC_MAGIC, | ||
deserialize::{ | ||
load, | ||
load_account_as, | ||
}, | ||
instruction::CommandHeader, | ||
utils::{ | ||
check_valid_writable_account, | ||
pyth_assert, | ||
}, | ||
OracleError, | ||
}, | ||
solana_program::{ | ||
account_info::AccountInfo, | ||
entrypoint::{ | ||
ProgramResult, | ||
MAX_PERMITTED_DATA_INCREASE, | ||
}, | ||
pubkey::Pubkey, | ||
}, | ||
std::{ | ||
cmp::min, | ||
mem::size_of, | ||
}, | ||
}; | ||
|
||
/// Resize mapping account. | ||
// account[0] mapping account [writable] | ||
pub fn resize_mapping( | ||
program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
instruction_data: &[u8], | ||
) -> ProgramResult { | ||
let mapping_account = match accounts { | ||
[x] => Ok(x), | ||
_ => Err(OracleError::InvalidNumberOfAccounts), | ||
}?; | ||
|
||
let hdr = load::<CommandHeader>(instruction_data)?; | ||
|
||
check_valid_writable_account(program_id, mapping_account)?; | ||
|
||
{ | ||
let account_header = load_account_as::<AccountHeader>(mapping_account)?; | ||
pyth_assert( | ||
account_header.magic_number == PC_MAGIC | ||
&& account_header.version == hdr.version | ||
&& account_header.account_type == MappingAccount::ACCOUNT_TYPE, | ||
OracleError::InvalidAccountHeader.into(), | ||
)?; | ||
} | ||
|
||
pyth_assert( | ||
mapping_account.data_len() < size_of::<MappingAccount>(), | ||
OracleError::NoNeedToResize.into(), | ||
)?; | ||
let new_size = min( | ||
size_of::<MappingAccount>(), | ||
mapping_account.data_len() + MAX_PERMITTED_DATA_INCREASE, | ||
); | ||
mapping_account.realloc(new_size, true)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.