Skip to content

Conversation

@jayantk
Copy link
Contributor

@jayantk jayantk commented Aug 4, 2022

As it says. I pulled out some helpers to read accounts & check their content, and also to initialize new accounts of a type. I think we can follow this pattern of functions for the other types of accounts as well.

Jayant Krishnamurthy added 2 commits August 4, 2022 14:02
let mut cur_mapping = load_mapping_account_mut(cur_mapping, hdr.ver_)?;
pyth_assert(
cur_mapping.num_ == PC_MAP_TABLE_SIZE
&& unsafe { cur_mapping.next_.k8_.iter().all(|x| *x == 0) },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need the unsafe blocks here because the account keys are a union type.

Copy link
Contributor

@guibescos guibescos Aug 5, 2022

Choose a reason for hiding this comment

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

What about this syntax :

cur_mapping.next_.k1_ = next_mapping.key.to_bytes();

/// Initialize account as a new mapping account. This function will zero out any existing data in
/// the account.
fn initialize_mapping_account(account: &AccountInfo, version: u32) -> Result<(), ProgramError> {
clear_account(account)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's a good idea to only keep instructions in oracle.rs, and move helpers into other modules. (It currently looks very clean, am just imagining the file will grow a lot as we migrate more instructions)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is bound to happen at some time. Arguably each instruction could have its own file also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can move stuff around later. i agree this file is going to get too big, but it's not yet clear to me what the right split into multiple files is.

@jayantk jayantk merged commit 3686a5a into main Aug 5, 2022
@jayantk jayantk deleted the add_mapping branch August 5, 2022 14:25
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.

4 participants