Skip to content

Conversation

@guibescos
Copy link
Contributor

@guibescos guibescos commented Aug 24, 2022

  • Move the minimum_size check to load_checked and initialize_checked from check_valid_signable_account and check_valid_writable_account. This allows to leverage the PythAccount trait for the check. It makes sense to have that check in the deserialization functions because if the account is too small deserialization will fail.
  • Move check_valid_fresh_account to initialize_pyth_account_checked. These two functions are always called together. Makes it harder to accidentally reinitialize an account.

@guibescos guibescos marked this pull request as ready for review August 24, 2022 17:37
@guibescos guibescos force-pushed the use-minimum-size branch 2 times, most recently from 21922b5 to 8ff86c7 Compare August 26, 2022 16:56
@guibescos guibescos changed the title Generic checks for pyth accounts Add some checks to load_checked Aug 26, 2022
/// Get the data stored in `account` as a value of type `T`
/// /// Warning: DON'T USE THIS UNCHECKED FUNCTION
pub fn load_account_as<'a, T: Pod>(account: &'a AccountInfo) -> Result<Ref<'a, T>, ProgramError> {
let data = account.try_borrow_data()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make this private but it'll require some more refactoring.

@guibescos guibescos changed the title Add some checks to load_checked Move minimum size check to load_checked and initialize_checked Aug 30, 2022
@guibescos guibescos merged commit 1a6ce1b into main Aug 30, 2022
@guibescos guibescos deleted the use-minimum-size branch August 30, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants