-
Notifications
You must be signed in to change notification settings - Fork 2
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
Registry Instruction #48
base: master
Are you sure you want to change the base?
Conversation
program/src/processor/registry.rs
Outdated
let existing_lamports = registry_ai.lamports(); | ||
**registry_ai.lamports.borrow_mut() = 0; | ||
|
||
//increment registry count and change seeds | ||
registry_count += 1; | ||
let registry_seeds = &[ | ||
b"subscription_registry", | ||
®istry_count.to_le_bytes(), | ||
] | ||
|
||
//create new registry account with more space for data | ||
invoke_signed( | ||
let new_length = registry_length + 48; | ||
&system_instruction::create_account( | ||
user_ai.key, | ||
registry_ai.key, | ||
rent::Rent::get()?.minimum_balance(new_length - registry_length), | ||
new_length as u64, | ||
program_id, | ||
), | ||
&[ | ||
user_ai.clone(); | ||
registry_ai.clone(); | ||
system_program_ai.clone(); | ||
], | ||
&[registry_seeds], | ||
); | ||
|
||
//add the lamports from before adding this space | ||
let user_added_lamports = registry_ai.lamports(); | ||
**registry_ai.lamports.borrow_mut() = user_added_lamports | ||
.checked_add(existing_lamports) | ||
.ok_or(TokenError::Overflow)?; |
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.
Two main things:
- Another account - you will actually need to pass in another account (where the seeds are "subscription_registry" and registry_count + 1 as you've correctly defined) - your current code works for the very first initialization, but if you are going from an existing registry and adding a new entry, you cannot just recreate the account with more space which you're doing here, you'll have to initialize a new account with more space
- Transferring lamports - your logic right now is technically correct but it's kinda wonky lol - you alr know
system_instruction::create_account
provides a certain amount of SOL, so I would recommend transferring the lamports from the current to new registry account first, and then callingsystem_instruction::create_account
to fill in the rest
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.
Really great job. All the logic makes sense to me - just need to make sure it compiles + write some client code to test. I'll definitely help you out with that at tonight's meeting 👍
Working on creating a registry:
When a user calls the instruction:
To Do: