Skip to content
Closed
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
9 changes: 9 additions & 0 deletions basics/checking-accounts/steel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = ["api", "program"]
resolver = "2"

[workspace.dependencies]
solana-program = "1.18.17"
steel = "2.0"
bytemuck = "1.14"
num_enum = "0.7"
13 changes: 13 additions & 0 deletions basics/checking-accounts/steel/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "checking-accounts-steel-api"
version = "0.1.0"
edition = "2021"

[dependencies]
solana-program.workspace = true
steel.workspace = true
bytemuck.workspace = true
num_enum.workspace = true

[lib]
crate-type = ["cdylib", "lib"]
57 changes: 57 additions & 0 deletions basics/checking-accounts/steel/api/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use solana_program::msg;
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum SteelInstruction {
CheckingAccounts = 0,
}

instruction!(SteelInstruction, CheckingAccounts);
// CheckingAccounts instruction
#[repr(C, packed)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CheckingAccounts {}

impl CheckingAccounts {
pub fn process(accounts: &[AccountInfo]) -> ProgramResult {
// Accounts passed in a vector must be in the expected order.
// You can verify the list has the correct number of accounts.
// This error will get thrown by default if you
// reach pass the exact no of accounts specified.
let [payer, account_to_create, account_to_change, system_program] = accounts else {
msg!("This instruction requires 4 accounts:");
msg!(" payer, account_to_create, account_to_change, system_program");
return Err(ProgramError::NotEnoughAccountKeys);
};

// you can make sure an account is indeed a signer
if let Err(err) = payer.is_signer() {
msg!("The program expects payer to be a signer.");
return Err(err);
};

// You can make sure an account has NOT been initialized.
msg!("New account: {}", account_to_create.key);
if account_to_create.lamports() != 0 {
msg!("The program expected the account to create to not yet be initialized.");
return Err(ProgramError::AccountAlreadyInitialized);
};
// (Create account...)

// You can also make sure an account has been initialized.
msg!("Account to change: {}", account_to_change.key);
if account_to_change.lamports() == 0 {
msg!("The program expected the account to change to be initialized.");
return Err(ProgramError::UninitializedAccount);
};

// If we want to modify an account's data, it must be owned by our program.
account_to_change.has_owner(&crate::ID)?;

// You can also check pubkeys against constants.
system_program.has_address(&system_program::ID)?;

Ok(())
}
}
9 changes: 9 additions & 0 deletions basics/checking-accounts/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod instruction;

use steel::*;

declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");

pub mod prelude {
pub use crate::instruction::*;
}
8 changes: 8 additions & 0 deletions basics/checking-accounts/steel/cicd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script is for quick building & deploying of the program.
# It also serves as a reference for the commands used for building & deploying Solana programs.
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"

cargo build-sbf --manifest-path=./program/Cargo.toml --bpf-out-dir=./program/target/so
solana program deploy ./program/target/so/program.so
21 changes: 21 additions & 0 deletions basics/checking-accounts/steel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"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/program.so"
},
"dependencies": {
"@solana/web3.js": "^1.95.4"
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/node": "^22.8.5",
"@types/mocha": "^10.0.9",
"chai": "^4.3.4",
"mocha": "^10.8.2",
"solana-bankrun": "^0.4.0",
"ts-mocha": "^10.0.0",
"typescript": "^5"
}
}
Loading