[solana] Reuse accounts (#1216)

* Reuse accounts

* add comment
This commit is contained in:
guibescos 2024-01-08 20:08:55 +00:00 committed by GitHub
parent 0ce4c4c8fe
commit a94194184b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -269,7 +269,9 @@ pub struct PostUpdates<'info> {
/// CHECK: This is just a PDA controlled by the program. There is currently no way to withdraw funds from it.
#[account(mut)]
pub treasury: AccountInfo<'info>,
#[account(init, payer =payer, space = PriceUpdateV1::LEN)]
/// The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.
/// Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized
#[account(init_if_needed, constraint = price_update_account.write_authority == Pubkey::default() || price_update_account.write_authority == payer.key(), payer =payer, space = PriceUpdateV1::LEN)]
pub price_update_account: Account<'info, PriceUpdateV1>,
pub system_program: Program<'info, System>,
}
@ -288,7 +290,9 @@ pub struct PostUpdatesAtomic<'info> {
#[account(mut, seeds = [TREASURY_SEED.as_ref()], bump)]
/// CHECK: This is just a PDA controlled by the program. There is currently no way to withdraw funds from it.
pub treasury: AccountInfo<'info>,
#[account(init, payer = payer, space = PriceUpdateV1::LEN)]
/// The contraint is such that either the price_update_account is uninitialized or the payer is the write_authority.
/// Pubkey::default() is the SystemProgram on Solana and it can't sign so it's impossible that price_update_account.write_authority == Pubkey::default() once the account is initialized
#[account(init_if_needed, constraint = price_update_account.write_authority == Pubkey::default() || price_update_account.write_authority == payer.key(), payer = payer, space = PriceUpdateV1::LEN)]
pub price_update_account: Account<'info, PriceUpdateV1>,
pub system_program: Program<'info, System>,
}