Skip to content

Commit

Permalink
fix(lazer): keep old names for legacy structs for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Nov 29, 2024
1 parent ba25bdf commit 47230d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ impl TrustedSignerInfo {
const SERIALIZED_LEN: usize = PUBKEY_BYTES + size_of::<i64>();
}

/// TODO: remove this legacy storage type
#[account]
pub struct StorageV1 {
pub struct Storage {
pub top_authority: Pubkey,
pub num_trusted_signers: u8,
pub trusted_signers: [TrustedSignerInfo; MAX_NUM_TRUSTED_SIGNERS],
}

impl StorageV1 {
impl Storage {
const SERIALIZED_LEN: usize = PUBKEY_BYTES
+ size_of::<u8>()
+ TrustedSignerInfo::SERIALIZED_LEN * MAX_NUM_TRUSTED_SIGNERS;
Expand Down Expand Up @@ -84,7 +85,8 @@ pub const STORAGE_SEED: &[u8] = b"storage";
pub mod pyth_lazer_solana_contract {
use super::*;

pub fn initialize_v1(ctx: Context<InitializeV1>, top_authority: Pubkey) -> Result<()> {
/// TODO: remove this legacy instruction
pub fn initialize(ctx: Context<Initialize>, top_authority: Pubkey) -> Result<()> {
ctx.accounts.storage.top_authority = top_authority;
Ok(())
}
Expand All @@ -101,7 +103,7 @@ pub mod pyth_lazer_solana_contract {
}

pub fn migrate_to_storage_v2(ctx: Context<MigrateToStorageV2>, treasury: Pubkey) -> Result<()> {
let old_storage = StorageV1::try_deserialize(&mut &**ctx.accounts.storage.data.borrow())?;
let old_storage = Storage::try_deserialize(&mut &**ctx.accounts.storage.data.borrow())?;
if old_storage.top_authority != ctx.accounts.top_authority.key() {
return Err(ProgramError::MissingRequiredSignature.into());
}
Expand Down Expand Up @@ -220,17 +222,17 @@ pub mod pyth_lazer_solana_contract {
}

#[derive(Accounts)]
pub struct InitializeV1<'info> {
pub struct Initialize<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
init,
payer = payer,
space = 8 + StorageV1::SERIALIZED_LEN,
space = 8 + Storage::SERIALIZED_LEN,
seeds = [STORAGE_SEED],
bump,
)]
pub storage: Account<'info, StorageV1>,
pub storage: Account<'info, Storage>,
pub system_program: Program<'info, System>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async fn test_with_init_v1_and_migrate() {
let mut transaction_init_contract = Transaction::new_with_payer(
&[Instruction::new_with_bytes(
pyth_lazer_solana_contract::ID,
&pyth_lazer_solana_contract::instruction::InitializeV1 {
&pyth_lazer_solana_contract::instruction::Initialize {
top_authority: setup.payer.pubkey(),
}
.data(),
Expand Down

0 comments on commit 47230d7

Please sign in to comment.