Skip to content

Commit

Permalink
chore: lint + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyanag committed Nov 27, 2024
1 parent 6fd9d4c commit 2fc678c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions basics/counter/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub mod prelude {
pub use crate::error::*;
pub use crate::instruction::*;
pub use crate::sdk::*;
pub use crate::state::*;
pub use crate::state::*;
}

use steel::*;

// TODO Set program id
declare_id!("11111111111111111111111111111112");
declare_id!("11111111111111111111111111111112");
2 changes: 1 addition & 1 deletion basics/counter/steel/api/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ pub fn increment(signer: Pubkey) -> Instruction {
AccountMeta::new(signer, true),
AccountMeta::new(counter_pda().0, false),
],
data : Increment {}.to_bytes(),
data: Increment {}.to_bytes(),
}
}
2 changes: 1 addition & 1 deletion basics/counter/steel/api/src/state/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::SteelAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Counter {
pub value: u64
pub value: u64,
}

account!(SteelAccount, Counter);
4 changes: 2 additions & 2 deletions basics/counter/steel/api/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use crate::consts::*;
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum SteelAccount {
Counter = 0
Counter = 0,
}

/// Fetch PDA of the counter account.
pub fn counter_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[COUNTER], &crate::id())
Pubkey::find_program_address(&[COUNTER], &crate::id())
}
47 changes: 23 additions & 24 deletions basics/counter/steel/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"name": "steel-counter-solana",
"version": "1.0.0",
"description": "Counter with steel framework for solana",
"scripts": {
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/counter_program.so"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^22.7.4",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"solana-bankrun": "^0.3.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
},
"dependencies": {
"@solana/web3.js": "^1.95.3"
}
"name": "steel-counter-solana",
"version": "1.0.0",
"description": "Counter with steel framework for solana",
"scripts": {
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/counter_program.so"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^22.7.4",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"solana-bankrun": "^0.3.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
},
"dependencies": {
"@solana/web3.js": "^1.95.3"
}
}
17 changes: 8 additions & 9 deletions basics/counter/steel/program/src/increment.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use steel_api::prelude::*;
use steel::*;
use solana_program::msg;
use steel::*;
use steel_api::prelude::*;

pub fn process_increment(accounts: &[AccountInfo<'_>]) -> ProgramResult {

// Load accounts.
let [signer_info, counter_info] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
let counter = counter_info
.to_account_mut::<Counter>(&steel_api::ID)?
.check_mut(|c| c.value < 100)?;
let counter = counter_info
.to_account_mut::<Counter>(&steel_api::ID)?
.check_mut(|c| c.value < 100)?;

// Update state
counter.value += 1;
// Update state
counter.value += 1;

msg!("Increment");
msg!("Counter Value {}", counter.value);
Expand Down
15 changes: 7 additions & 8 deletions basics/counter/steel/program/src/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use steel_api::prelude::*;
use steel::*;
use solana_program::msg;
use steel::*;
use steel_api::prelude::*;

pub fn process_initialize(accounts: &[AccountInfo<'_>]) -> 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],
counter_bump,
&steel_api::ID
)?;
counter_info
.is_empty()?
.is_writable()?
.has_seeds(&[COUNTER], counter_bump, &steel_api::ID)?;
system_program.is_program(&system_program::ID)?;

// Initialize counter.
Expand Down
6 changes: 3 additions & 3 deletions basics/counter/steel/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mod initialize;

use increment::*;
use initialize::*;

use steel_api::prelude::*;

use steel::*;
use steel_api::prelude::*;

use solana_program::msg;

Expand All @@ -14,7 +14,7 @@ pub fn process_instruction(
accounts: &[AccountInfo],
data: &[u8],
) -> ProgramResult {
let (ix, data) = parse_instruction(&steel_api::ID, program_id , data)?;
let (ix, data) = parse_instruction(&steel_api::ID, program_id, data)?;

match ix {
SteelInstruction::Initialize => process_initialize(accounts)?,
Expand Down
17 changes: 8 additions & 9 deletions basics/counter/steel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"compilerOptions": {
"types": ["mocha", "chai", "node"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
"compilerOptions": {
"types": ["mocha", "chai", "node"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
}

0 comments on commit 2fc678c

Please sign in to comment.