Skip to content

Commit

Permalink
update to steel 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
robertohuertasm committed Dec 1, 2024
1 parent 443e2f3 commit 1d522a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion basics/counter/steel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ counter-api = { path = "./api", version = "0.1.0" }
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "1.3"
steel = "2.1.0"
thiserror = "1.0"
4 changes: 2 additions & 2 deletions basics/counter/steel/program/src/increment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn process_increment(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
};
signer_info.is_signer()?;
let counter = counter_info
.to_account_mut::<Counter>(&counter_api::ID)?
.check_mut(|c| c.value < 100)?;
.as_account_mut::<Counter>(&counter_api::ID)?
.assert_mut(|c| c.value < 100)?;

// Update state
counter.value += amount;
Expand Down
22 changes: 10 additions & 12 deletions basics/counter/steel/program/src/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@ use counter_api::prelude::*;
use steel::*;

pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Get expected pda bump.
let counter_bump = counter_pda().1;

// Load accounts.
let [signer_info, counter_info, system_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
return Err(ProgramError::NotEnoughAccountKeys);
};

signer_info.is_signer()?;
counter_info.is_empty()?.is_writable()?.has_seeds(
&[COUNTER_SEED],
counter_bump,
&counter_api::ID
)?;
counter_info
.is_empty()?
.is_writable()?
.has_seeds(&[COUNTER_SEED], &counter_api::ID)?;
system_program.is_program(&system_program::ID)?;

// Initialize counter.
create_account::<Counter>(
counter_info,
&counter_api::ID,
&[COUNTER_SEED, &[counter_bump]],
system_program,
signer_info,
&counter_api::ID,
&[COUNTER_SEED],
)?;
let counter = counter_info.to_account_mut::<Counter>(&counter_api::ID)?;

let counter = counter_info.as_account_mut::<Counter>(&counter_api::ID)?;
counter.value = 0;

Ok(())
Expand Down

0 comments on commit 1d522a8

Please sign in to comment.