Skip to content

Commit 52b3a69

Browse files
authored
add basics/checking-accounts/steel (#199)
1 parent ff2ab18 commit 52b3a69

File tree

14 files changed

+275
-0
lines changed

14 files changed

+275
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
test-ledger
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+
steel-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Steel
2+
3+
**Steel** 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "steel-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_to_change account PDA.
2+
pub const ACCOUNT_TO_CHANGE: &[u8] = b"account_to_change";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum SteelInstruction {
6+
CheckAccounts = 0,
7+
}
8+
9+
#[repr(C)]
10+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11+
pub struct CheckAccounts {}
12+
13+
instruction!(SteelInstruction, CheckAccounts);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub mod consts;
2+
pub mod instruction;
3+
pub mod sdk;
4+
pub mod state;
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+
// TODO Set program id
16+
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn check_accounts(
6+
signer: Pubkey,
7+
account_to_create: Pubkey,
8+
account_to_change: Pubkey,
9+
) -> Instruction {
10+
Instruction {
11+
program_id: crate::ID,
12+
accounts: vec![
13+
AccountMeta::new(signer, true),
14+
AccountMeta::new(account_to_create, false),
15+
AccountMeta::new(account_to_change, false),
16+
AccountMeta::new_readonly(system_program::ID, false),
17+
],
18+
data: CheckAccounts {}.to_bytes(),
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use steel::*;
2+
3+
use super::SteelAccount;
4+
5+
#[repr(C)]
6+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
7+
pub struct AccountToChange {}
8+
9+
account!(SteelAccount, AccountToChange);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod account_to_change;
2+
3+
pub use account_to_change::*;
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 SteelAccount {
12+
AccountToChange = 0,
13+
}
14+
15+
/// Fetch PDA of the account_to_change account.
16+
pub fn account_to_change_pda() -> (Pubkey, u8) {
17+
Pubkey::find_program_address(&[ACCOUNT_TO_CHANGE], &crate::id())
18+
}

0 commit comments

Comments
 (0)