Skip to content

Commit 0c6be6a

Browse files
cleanup native macro-derive example
1 parent 2c0078d commit 0c6be6a

File tree

11 files changed

+107
-311
lines changed

11 files changed

+107
-311
lines changed

program-tests/sdk-test-derived/src/compress_dynamic_pda.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

program-tests/sdk-test-derived/src/create_config.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

program-tests/sdk-test-derived/src/create_dynamic_pda.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use light_sdk::{
88
};
99
use solana_program::account_info::AccountInfo;
1010

11-
use crate::decompress_dynamic_pda::MyPdaAccount;
11+
use crate::MyPdaAccount;
1212

1313
/// INITS a PDA and compresses it into a new compressed account.
1414
pub fn create_dynamic_pda(

program-tests/sdk-test-derived/src/decompress_dynamic_pda.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

program-tests/sdk-test-derived/src/lib.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
use borsh::BorshDeserialize;
2+
use borsh::BorshSerialize;
23
use light_macros::pubkey;
4+
use light_sdk::{
5+
compressible::{CompressionInfo, HasCompressionInfo},
6+
LightDiscriminator, LightHasher,
7+
};
38
use light_sdk::{cpi::CpiSigner, derive_light_cpi_signer, error::LightSdkError};
49
use light_sdk_macros::add_native_compressible_instructions;
510
use solana_program::{
611
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::ProgramError,
712
pubkey::Pubkey,
813
};
914

10-
pub mod compress_dynamic_pda;
11-
pub mod create_config;
1215
pub mod create_dynamic_pda;
13-
pub mod decompress_dynamic_pda;
14-
pub mod update_config;
16+
1517
pub mod update_pda;
1618

1719
pub const ID: Pubkey = pubkey!("FNt7byTHev1k5x2cXZLBr8TdWiC3zoP5vcnZR4P682Uy");
1820
pub const LIGHT_CPI_SIGNER: CpiSigner =
1921
derive_light_cpi_signer!("FNt7byTHev1k5x2cXZLBr8TdWiC3zoP5vcnZR4P682Uy");
2022

21-
// Re-export so it's available to the macro
22-
pub use decompress_dynamic_pda::MyPdaAccount;
23-
2423
// Generate all compression-related instructions and data structures
2524
#[add_native_compressible_instructions(MyPdaAccount)]
2625
pub mod compression {
@@ -39,8 +38,6 @@ pub enum InstructionType {
3938
// Custom instructions
4039
CreateDynamicPda = 10,
4140
UpdatePda = 11,
42-
CompressDynamicPda = 12,
43-
DecompressDynamicPda = 13,
4441
}
4542

4643
impl TryFrom<u8> for InstructionType {
@@ -54,8 +51,6 @@ impl TryFrom<u8> for InstructionType {
5451
3 => Ok(InstructionType::CompressMyPdaAccount),
5552
10 => Ok(InstructionType::CreateDynamicPda),
5653
11 => Ok(InstructionType::UpdatePda),
57-
12 => Ok(InstructionType::CompressDynamicPda),
58-
13 => Ok(InstructionType::DecompressDynamicPda),
5954
_ => Err(LightSdkError::ConstraintViolation),
6055
}
6156
}
@@ -143,14 +138,30 @@ pub fn process_instruction(
143138
update_pda::update_pda::<false>(accounts, data).map_err(|e| ProgramError::from(e))
144139
}
145140

146-
InstructionType::CompressDynamicPda => {
147-
compress_dynamic_pda::compress_dynamic_pda(accounts, data)
148-
.map_err(|e| ProgramError::from(e))
149-
}
141+
_ => Err(ProgramError::InvalidInstructionData),
142+
}
143+
}
150144

151-
InstructionType::DecompressDynamicPda => {
152-
decompress_dynamic_pda::decompress_dynamic_pda(accounts, data.to_vec())
153-
.map_err(|_| ProgramError::Custom(3))
154-
}
145+
pub const COMPRESSION_DELAY: u64 = 100;
146+
147+
#[derive(
148+
Default, Clone, Debug, BorshSerialize, BorshDeserialize, LightHasher, LightDiscriminator,
149+
)]
150+
pub struct MyPdaAccount {
151+
#[skip]
152+
pub compression_info: CompressionInfo,
153+
#[hash]
154+
pub owner: Pubkey,
155+
pub data: u64,
156+
}
157+
158+
// Implement the HasCompressionInfo trait
159+
impl HasCompressionInfo for MyPdaAccount {
160+
fn compression_info(&self) -> &CompressionInfo {
161+
&self.compression_info
162+
}
163+
164+
fn compression_info_mut(&mut self) -> &mut CompressionInfo {
165+
&mut self.compression_info
155166
}
156167
}

program-tests/sdk-test-derived/src/update_config.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

program-tests/sdk-test-derived/src/update_pda.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use light_sdk::{
88
};
99
use solana_program::{account_info::AccountInfo, log::sol_log_compute_units};
1010

11-
use crate::decompress_dynamic_pda::MyPdaAccount;
11+
use crate::MyPdaAccount;
1212

1313
/// CU usage:
1414
/// - sdk pre system program 9,183k CU

0 commit comments

Comments
 (0)