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
3 changes: 3 additions & 0 deletions basics/account-data/steel/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"node-option": ["loader=ts-node/esm"]
}
21 changes: 21 additions & 0 deletions basics/account-data/steel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[workspace]
resolver = "2"
members = ["api", "program"]

[workspace.package]
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
homepage = ""
documentation = ""
respository = ""
readme = "./README.md"
keywords = ["solana"]

[workspace.dependencies]
account-data-api = { path = "./api", version = "0.1.0" }
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "2.1.0"
thiserror = "1.0"
11 changes: 11 additions & 0 deletions basics/account-data/steel/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "account-data-api"
version = "0.1.0"
edition = "2021"

[dependencies]
bytemuck.workspace = true
num_enum.workspace = true
solana-program.workspace = true
steel.workspace = true
thiserror.workspace = true
2 changes: 2 additions & 0 deletions basics/account-data/steel/api/src/consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Seed of the account PDA.
pub const ACCOUNT: &[u8] = b"account";
21 changes: 21 additions & 0 deletions basics/account-data/steel/api/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use steel::*;

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

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitializeAccount {
pub name: [u8; 64],
pub house_number: u8,
pub city: [u8; 64],
pub street: [u8; 64],

}

instruction!(AccountInstruction, InitializeAccount);


15 changes: 15 additions & 0 deletions basics/account-data/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub mod consts;
pub mod instruction;
pub mod state;
pub mod sdk;

pub mod prelude {
pub use crate::consts::*;
pub use crate::instruction::*;
pub use crate::sdk::*;
pub use crate::state::*;
}

use steel::*;

declare_id!("FFJjpuXzZeBM8k1aTzzUrV9tgboUWtAaKH6U2QudoH2K");
21 changes: 21 additions & 0 deletions basics/account-data/steel/api/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use steel::*;

use crate::state::*;
use crate::instruction::*;

pub fn initialize(signer: Pubkey, name: &str, house_number: u8, city: &str, street: &str) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(account_pda().0, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: InitializeAccount {
name: name.as_bytes().try_into().unwrap(),
house_number: house_number,
city: city.as_bytes().try_into().unwrap(),
street: street.as_bytes().try_into().unwrap(),
}.to_bytes()
}
}
26 changes: 26 additions & 0 deletions basics/account-data/steel/api/src/state/address_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use steel::*;
use crate::consts::*;

/// Fetch PDA of the account.
pub fn account_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[ACCOUNT], &crate::id())
}


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

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Data {
pub name: [u8; 64], // 64 bytes
pub house_number: u8, // 1 byte
pub street: [u8; 64], // 64 bytes
pub city: [u8; 64], // 64 bytes
}

account!(AccountDiscriminator, Data);

2 changes: 2 additions & 0 deletions basics/account-data/steel/api/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod address_info;
pub use address_info::*;
30 changes: 30 additions & 0 deletions basics/account-data/steel/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
24 changes: 24 additions & 0 deletions basics/account-data/steel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "module",
"scripts": {
"test": "pnpm ts-mocha -p ./tests/tsconfig.test.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/rent_program.so"
},
"dependencies": {
"@solana/web3.js": "^1.95.4"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/bn.js": "^5.1.6",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.9",
"chai": "^5.1.1",
"mocha": "^10.7.3",
"solana-bankrun": "^0.4.0",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
Loading
Loading