Skip to content

Commit 5191fea

Browse files
committed
add create-account program of steel
1 parent 3a36468 commit 5191fea

File tree

17 files changed

+324
-0
lines changed

17 files changed

+324
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
test-ledger
3+
node_modules
4+
pnpm-lock.yaml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
create-account-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"
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# CreateAccount
2+
3+
**CreateAccount** is a ...
4+
5+
## API
6+
- [`Consts`](api/src/consts.rs) – Program constants.
7+
- [`Error`](api/src/error.rs) – Custom program errors.
8+
- [`Event`](api/src/event.rs) – Custom program events.
9+
- [`Instruction`](api/src/instruction.rs) – Declared instructions.
10+
11+
## Instructions
12+
- [`Hello`](program/src/hello.rs) – Hello ...
13+
14+
## State
15+
- [`User`](api/src/state/user.rs) – User ...
16+
17+
## Tests
18+
19+
To run the test suit, use the Solana toolchain:
20+
```
21+
cargo test-sbf
22+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "create-account-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
12+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Seed of the new account PDA.
2+
pub const NEWACCOUNT: &[u8] = b"newaccount";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use steel::*;
2+
3+
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
4+
#[repr(u32)]
5+
pub enum CreateAccountError {
6+
#[error("This is a dummy error")]
7+
Dummy = 0,
8+
}
9+
10+
error!(CreateAccountError);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum CreateAccountInstruction {
6+
InitializeNewAccount = 0,
7+
}
8+
9+
#[repr(C)]
10+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11+
pub struct InitializeNewAccount {}
12+
13+
instruction!(CreateAccountInstruction, InitializeNewAccount);
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub mod consts;
2+
pub mod error;
3+
pub mod instruction;
4+
pub mod sdk;
5+
pub mod state;
6+
7+
pub mod prelude {
8+
pub use crate::consts::*;
9+
pub use crate::error::*;
10+
pub use crate::instruction::*;
11+
pub use crate::sdk::*;
12+
pub use crate::state::*;
13+
}
14+
15+
use steel::*;
16+
17+
// TODO Set program id
18+
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn initializenewaccount(signer: Pubkey) -> Instruction {
6+
Instruction {
7+
program_id: crate::ID,
8+
accounts: vec![
9+
AccountMeta::new(signer, true),
10+
AccountMeta::new(new_account_pda().0, false),
11+
AccountMeta::new_readonly(system_program::ID, false),
12+
],
13+
data: InitializeNewAccount {}.to_bytes()
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod newaccount;
2+
3+
pub use newaccount::*;
4+
5+
use steel::*;
6+
7+
use crate::consts::*;
8+
9+
#[repr(u8)]
10+
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
11+
pub enum CreateAccountAccount {
12+
NewAccount = 0
13+
}
14+
15+
/// Fetch PDA of the new account.
16+
pub fn new_account_pda() -> (Pubkey, u8) {
17+
Pubkey::find_program_address(&[NEWACCOUNT], &crate::id())
18+
}

0 commit comments

Comments
 (0)