Skip to content

Commit 47230d7

Browse files
committed
fix(lazer): keep old names for legacy structs for compatibility
1 parent ba25bdf commit 47230d7

File tree

2 files changed

+10
-8
lines changed
  • lazer/contracts/solana/programs/pyth-lazer-solana-contract

2 files changed

+10
-8
lines changed

lazer/contracts/solana/programs/pyth-lazer-solana-contract/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ impl TrustedSignerInfo {
3838
const SERIALIZED_LEN: usize = PUBKEY_BYTES + size_of::<i64>();
3939
}
4040

41+
/// TODO: remove this legacy storage type
4142
#[account]
42-
pub struct StorageV1 {
43+
pub struct Storage {
4344
pub top_authority: Pubkey,
4445
pub num_trusted_signers: u8,
4546
pub trusted_signers: [TrustedSignerInfo; MAX_NUM_TRUSTED_SIGNERS],
4647
}
4748

48-
impl StorageV1 {
49+
impl Storage {
4950
const SERIALIZED_LEN: usize = PUBKEY_BYTES
5051
+ size_of::<u8>()
5152
+ TrustedSignerInfo::SERIALIZED_LEN * MAX_NUM_TRUSTED_SIGNERS;
@@ -84,7 +85,8 @@ pub const STORAGE_SEED: &[u8] = b"storage";
8485
pub mod pyth_lazer_solana_contract {
8586
use super::*;
8687

87-
pub fn initialize_v1(ctx: Context<InitializeV1>, top_authority: Pubkey) -> Result<()> {
88+
/// TODO: remove this legacy instruction
89+
pub fn initialize(ctx: Context<Initialize>, top_authority: Pubkey) -> Result<()> {
8890
ctx.accounts.storage.top_authority = top_authority;
8991
Ok(())
9092
}
@@ -101,7 +103,7 @@ pub mod pyth_lazer_solana_contract {
101103
}
102104

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

222224
#[derive(Accounts)]
223-
pub struct InitializeV1<'info> {
225+
pub struct Initialize<'info> {
224226
#[account(mut)]
225227
pub payer: Signer<'info>,
226228
#[account(
227229
init,
228230
payer = payer,
229-
space = 8 + StorageV1::SERIALIZED_LEN,
231+
space = 8 + Storage::SERIALIZED_LEN,
230232
seeds = [STORAGE_SEED],
231233
bump,
232234
)]
233-
pub storage: Account<'info, StorageV1>,
235+
pub storage: Account<'info, Storage>,
234236
pub system_program: Program<'info, System>,
235237
}
236238

lazer/contracts/solana/programs/pyth-lazer-solana-contract/tests/test1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async fn test_with_init_v1_and_migrate() {
202202
let mut transaction_init_contract = Transaction::new_with_payer(
203203
&[Instruction::new_with_bytes(
204204
pyth_lazer_solana_contract::ID,
205-
&pyth_lazer_solana_contract::instruction::InitializeV1 {
205+
&pyth_lazer_solana_contract::instruction::Initialize {
206206
top_authority: setup.payer.pubkey(),
207207
}
208208
.data(),

0 commit comments

Comments
 (0)