-
Notifications
You must be signed in to change notification settings - Fork 119
Implement add_mapping instruction #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 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) }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.