Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions account-comparison/programs/account-comparison/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anchor_lang::prelude::*;
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -58,11 +59,18 @@ pub mod account_comparison {
CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|err| ProgramError::from(LightSdkError::from(err)))?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"account", ctx.accounts.user.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|err| ProgramError::from(LightSdkError::from(err)))?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
14 changes: 11 additions & 3 deletions basic-operations/anchor/burn/programs/burn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMetaBurn, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -38,11 +39,18 @@ pub mod burn {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"message", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
14 changes: 11 additions & 3 deletions basic-operations/anchor/close/programs/close/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -38,11 +39,18 @@ pub mod close {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"message", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
14 changes: 11 additions & 3 deletions basic-operations/anchor/create/programs/create/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -38,11 +39,18 @@ pub mod create {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"message", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
14 changes: 11 additions & 3 deletions basic-operations/anchor/reinit/programs/reinit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -38,11 +39,18 @@ pub mod reinit {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"message", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
14 changes: 11 additions & 3 deletions basic-operations/anchor/update/programs/update/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -38,11 +39,18 @@ pub mod update {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"message", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
16 changes: 12 additions & 4 deletions basic-operations/native/programs/burn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use light_macros::pubkey;
use light_sdk::{
account::sha::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{
v1::{CpiAccounts, LightSystemProgramCpi},
CpiSigner, InvokeLightSystemProgram, LightCpiInstruction,
Expand Down Expand Up @@ -81,12 +82,19 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light

let light_cpi_accounts = CpiAccounts::new(signer, &accounts[1..], LIGHT_CPI_SIGNER);

let address_tree_pubkey = instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
solana_program::msg!("Invalid address tree");
return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData));
}

let (address, address_seed) = derive_address(
&[b"message", signer.key.as_ref()],
&instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?,
&address_tree_pubkey,
&ID,
);

Expand Down
16 changes: 12 additions & 4 deletions basic-operations/native/programs/close/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use light_macros::pubkey;
use light_sdk::{
account::sha::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{
v1::{CpiAccounts, LightSystemProgramCpi},
CpiSigner, InvokeLightSystemProgram, LightCpiInstruction,
Expand Down Expand Up @@ -81,12 +82,19 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light

let light_cpi_accounts = CpiAccounts::new(signer, &accounts[1..], LIGHT_CPI_SIGNER);

let address_tree_pubkey = instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
solana_program::msg!("Invalid address tree");
return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData));
}

let (address, address_seed) = derive_address(
&[b"message", signer.key.as_ref()],
&instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?,
&address_tree_pubkey,
&ID,
);

Expand Down
16 changes: 12 additions & 4 deletions basic-operations/native/programs/create/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use light_macros::pubkey;
use light_sdk::{
account::sha::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{
v1::{CpiAccounts, LightSystemProgramCpi},
CpiSigner, InvokeLightSystemProgram, LightCpiInstruction,
Expand Down Expand Up @@ -93,12 +94,19 @@ pub fn create(

let light_cpi_accounts = CpiAccounts::new(signer, &accounts[1..], LIGHT_CPI_SIGNER);

let address_tree_pubkey = instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
solana_program::msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData);
}

let (address, address_seed) = derive_address(
&[b"message", signer.key.as_ref()],
&instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?,
&address_tree_pubkey,
&ID,
);

Expand Down
16 changes: 12 additions & 4 deletions basic-operations/native/programs/reinit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use light_macros::pubkey;
use light_sdk::{
account::sha::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{
v1::{CpiAccounts, LightSystemProgramCpi},
CpiSigner, InvokeLightSystemProgram, LightCpiInstruction,
Expand Down Expand Up @@ -89,12 +90,19 @@ fn create(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(), Light

let light_cpi_accounts = CpiAccounts::new(signer, &accounts[1..], LIGHT_CPI_SIGNER);

let address_tree_pubkey = instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
solana_program::msg!("Invalid address tree");
return Err(LightSdkError::ProgramError(ProgramError::InvalidAccountData));
}

let (address, address_seed) = derive_address(
&[b"message", signer.key.as_ref()],
&instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?,
&address_tree_pubkey,
&ID,
);

Expand Down
16 changes: 12 additions & 4 deletions basic-operations/native/programs/update/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use light_macros::pubkey;
use light_sdk::{
account::sha::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{
v1::{CpiAccounts, LightSystemProgramCpi},
CpiSigner, InvokeLightSystemProgram, LightCpiInstruction,
Expand Down Expand Up @@ -109,12 +110,19 @@ pub fn create(

let light_cpi_accounts = CpiAccounts::new(signer, &accounts[1..], LIGHT_CPI_SIGNER);

let address_tree_pubkey = instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
solana_program::msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData);
}

let (address, address_seed) = derive_address(
&[b"message", signer.key.as_ref()],
&instruction_data
.address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ProgramError::NotEnoughAccountKeys)?,
&address_tree_pubkey,
&ID,
);

Expand Down
14 changes: 11 additions & 3 deletions counter/anchor/programs/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anchor_lang::{prelude::*, AnchorDeserialize, Discriminator};
use light_sdk::{
account::LightAccount,
address::v1::derive_address,
constants::ADDRESS_TREE_V1,
cpi::{v1::CpiAccounts, CpiSigner},
derive_light_cpi_signer,
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
Expand Down Expand Up @@ -41,11 +42,18 @@ pub mod counter {
crate::LIGHT_CPI_SIGNER,
);

let address_tree_pubkey = address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?;

if address_tree_pubkey.to_bytes() != ADDRESS_TREE_V1 {
msg!("Invalid address tree");
return Err(ProgramError::InvalidAccountData.into());
}

let (address, address_seed) = derive_address(
&[b"counter", ctx.accounts.signer.key().as_ref()],
&address_tree_info
.get_tree_pubkey(&light_cpi_accounts)
.map_err(|_| ErrorCode::AccountNotEnoughKeys)?,
&address_tree_pubkey,
&crate::ID,
);

Expand Down
Loading