Skip to content

Commit f6f3961

Browse files
committed
addes basics/account_data/steel
1 parent 45e302a commit f6f3961

File tree

18 files changed

+1887
-0
lines changed

18 files changed

+1887
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"node-option": ["loader=ts-node/esm"]
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["api", "program"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
7+
edition = "2021"
8+
license = "Apache-2.0"
9+
homepage = ""
10+
documentation = ""
11+
respository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
account-data-api = { path = "./api", version = "0.1.0" }
17+
bytemuck = "1.14"
18+
num_enum = "0.7"
19+
solana-program = "1.18"
20+
steel = "1.3"
21+
thiserror = "1.0"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "account-data-api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bytemuck.workspace = true
8+
num_enum.workspace = true
9+
solana-program.workspace = true
10+
steel.workspace = true
11+
thiserror.workspace = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Seed of the account PDA.
2+
pub const ACCOUNT: &[u8] = b"account";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum AccountInstruction {
6+
InitializeAccount = 0,
7+
}
8+
9+
#[repr(C)]
10+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11+
pub struct InitializeAccount {
12+
pub name: [u8; 64],
13+
pub house_number: u8,
14+
pub city: [u8; 64],
15+
pub street: [u8; 64],
16+
17+
}
18+
19+
instruction!(AccountInstruction, InitializeAccount);
20+
21+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub mod consts;
2+
pub mod instruction;
3+
pub mod state;
4+
pub mod sdk;
5+
6+
pub mod prelude {
7+
pub use crate::consts::*;
8+
pub use crate::instruction::*;
9+
pub use crate::sdk::*;
10+
pub use crate::state::*;
11+
}
12+
13+
use steel::*;
14+
15+
declare_id!("FFJjpuXzZeBM8k1aTzzUrV9tgboUWtAaKH6U2QudoH2K");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use steel::*;
2+
3+
use crate::state::*;
4+
use crate::instruction::*;
5+
6+
pub fn initialize(signer: Pubkey, name: &str, house_number: u8, city: &str, street: &str) -> Instruction {
7+
Instruction {
8+
program_id: crate::ID,
9+
accounts: vec![
10+
AccountMeta::new(signer, true),
11+
AccountMeta::new(account_pda().0, false),
12+
AccountMeta::new_readonly(system_program::ID, false),
13+
],
14+
data: InitializeAccount {
15+
name: name.as_bytes().try_into().unwrap(),
16+
house_number: house_number,
17+
city: city.as_bytes().try_into().unwrap(),
18+
street: street.as_bytes().try_into().unwrap(),
19+
}.to_bytes()
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use steel::*;
2+
use crate::consts::*;
3+
4+
/// Fetch PDA of the account.
5+
pub fn account_pda() -> (Pubkey, u8) {
6+
Pubkey::find_program_address(&[ACCOUNT], &crate::id())
7+
}
8+
9+
10+
#[repr(u8)]
11+
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
12+
pub enum AccountDiscriminator {
13+
Data = 0
14+
}
15+
16+
#[repr(C)]
17+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
18+
pub struct Data {
19+
pub name: [u8; 64], // 64 bytes
20+
pub house_number: u8, // 1 byte
21+
pub street: [u8; 64], // 64 bytes
22+
pub city: [u8; 64], // 64 bytes
23+
}
24+
25+
account!(AccountDiscriminator, Data);
26+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod address_info;
2+
pub use address_info::*;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"ignore": []
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "tab"
15+
},
16+
"organizeImports": {
17+
"enabled": true
18+
},
19+
"linter": {
20+
"enabled": true,
21+
"rules": {
22+
"recommended": true
23+
}
24+
},
25+
"javascript": {
26+
"formatter": {
27+
"quoteStyle": "double"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)