Skip to content

Commit 1c39cb7

Browse files
committed
refactor: use v2 accounts in create and update
1 parent 47cbded commit 1c39cb7

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

create-and-update/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use borsh::{BorshDeserialize, BorshSerialize};
66
use light_sdk::{
77
account::LightAccount,
88
address::v2::derive_address,
9-
cpi::{v1::CpiAccounts, CpiSigner},
9+
cpi::{v2::CpiAccounts, CpiSigner},
1010
derive_light_cpi_signer,
1111
instruction::{account_meta::CompressedAccountMeta, PackedAddressTreeInfo, ValidityProof},
1212
LightDiscriminator, LightHasher,
@@ -25,7 +25,7 @@ pub mod create_and_update {
2525

2626
use super::*;
2727
use light_sdk::cpi::{
28-
v1::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction,
28+
v2::LightSystemProgramCpi, InvokeLightSystemProgram, LightCpiInstruction,
2929
};
3030

3131
/// Creates a new compressed account with initial data
@@ -64,7 +64,9 @@ pub mod create_and_update {
6464
);
6565
LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof)
6666
.with_light_account(data_account)?
67-
.with_new_addresses(&[address_tree_info.into_new_address_params_packed(address_seed)])
67+
.with_new_addresses(&[
68+
address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))
69+
])
6870
.invoke(light_cpi_accounts)?;
6971

7072
Ok(())
@@ -118,7 +120,7 @@ pub mod create_and_update {
118120
.with_light_account(updated_data_account)?
119121
.with_new_addresses(&[new_account
120122
.address_tree_info
121-
.into_new_address_params_packed(new_address_seed)])
123+
.into_new_address_params_assigned_packed(new_address_seed, Some(0))])
122124
.invoke(light_cpi_accounts)?;
123125

124126
msg!(
@@ -236,8 +238,10 @@ pub mod create_and_update {
236238
.with_light_account(first_data_account)?
237239
.with_light_account(second_data_account)?
238240
.with_new_addresses(&[
239-
address_tree_info.into_new_address_params_packed(first_address_seed),
240-
address_tree_info.into_new_address_params_packed(second_address_seed),
241+
address_tree_info
242+
.into_new_address_params_assigned_packed(first_address_seed, Some(0)),
243+
address_tree_info
244+
.into_new_address_params_assigned_packed(second_address_seed, Some(1)),
241245
])
242246
.invoke(light_cpi_accounts)?;
243247

create-and-update/tests/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ where
200200
{
201201
let mut remaining_accounts = PackedAccounts::default();
202202
let config = SystemAccountMetaConfig::new(create_and_update::ID);
203-
remaining_accounts.add_system_accounts(config)?;
203+
remaining_accounts.add_system_accounts_v2(config)?;
204204

205205
let rpc_result = rpc
206206
.get_validity_proof(
@@ -255,7 +255,7 @@ where
255255
{
256256
let mut remaining_accounts = PackedAccounts::default();
257257
let config = SystemAccountMetaConfig::new(create_and_update::ID);
258-
remaining_accounts.add_system_accounts(config)?;
258+
remaining_accounts.add_system_accounts_v2(config)?;
259259

260260
let hash = existing_account.hash;
261261

@@ -334,7 +334,7 @@ where
334334
{
335335
let mut remaining_accounts = PackedAccounts::default();
336336
let config = SystemAccountMetaConfig::new(create_and_update::ID);
337-
remaining_accounts.add_system_accounts(config)?;
337+
remaining_accounts.add_system_accounts_v2(config)?;
338338

339339
let first_hash = first_account.hash;
340340
let second_hash = second_account.hash;

create-and-update/tests/test_create_two_accounts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ where
9898
{
9999
let mut remaining_accounts = PackedAccounts::default();
100100
let config = SystemAccountMetaConfig::new(create_and_update::ID);
101-
remaining_accounts.add_system_accounts(config)?;
101+
remaining_accounts.add_system_accounts_v2(config)?;
102102

103103
let rpc_result = rpc
104104
.get_validity_proof(

0 commit comments

Comments
 (0)