Skip to content

Commit 85082a3

Browse files
authored
add basics/rent/steel (#240)
1 parent dd771c7 commit 85082a3

File tree

15 files changed

+359
-0
lines changed

15 files changed

+359
-0
lines changed

basics/rent/steel/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
test-ledger

basics/rent/steel/Cargo.toml

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+
repository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
rent_example-api = { path = "./api", version = "0.1.0" }
17+
bytemuck = "1.14"
18+
num_enum = "0.7"
19+
solana-program = "1.18"
20+
steel = "2.0"
21+
thiserror = "1.0"

basics/rent/steel/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RentExample
2+
3+
**RentExample** 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+
- [`Add`](program/src/add.rs) – Add ...
13+
- [`Initialize`](program/src/initialize.rs) – Initialize ...
14+
15+
## State
16+
- [`Counter`](api/src/state/counter.rs) – Counter ...
17+
18+
## Get started
19+
20+
Compile your program:
21+
```sh
22+
steel build
23+
```
24+
25+
Run unit and integration tests:
26+
```sh
27+
steel test
28+
```

basics/rent/steel/api/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rent_example-api"
3+
description = "API for interacting with the RentExample program"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
documentation.workspace = true
9+
repository.workspace = true
10+
readme.workspace = true
11+
keywords.workspace = true
12+
13+
[dependencies]
14+
bytemuck.workspace = true
15+
num_enum.workspace = true
16+
solana-program.workspace = true
17+
steel.workspace = true
18+
thiserror.workspace = true

basics/rent/steel/api/src/error.rs

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 RentExampleError {
6+
#[error("This is a dummy error")]
7+
Dummy = 0,
8+
}
9+
10+
error!(RentExampleError);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum RentInstruction {
6+
CreateSystemAccount = 0,
7+
}
8+
9+
#[repr(C)]
10+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11+
pub struct CreateSystemAccount {
12+
pub name: [u8; 32],
13+
pub address: [u8; 64],
14+
}
15+
16+
instruction!(RentInstruction, CreateSystemAccount);

basics/rent/steel/api/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub mod error;
2+
pub mod instruction;
3+
pub mod sdk;
4+
pub mod state;
5+
6+
pub mod prelude {
7+
pub use crate::error::*;
8+
pub use crate::instruction::*;
9+
pub use crate::sdk::*;
10+
pub use crate::state::*;
11+
// Re-export common solana dependencies
12+
pub use solana_program::{
13+
account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey, rent::Rent,
14+
system_program,
15+
};
16+
}
17+
18+
use steel::*;
19+
20+
// TODO Set program id
21+
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");

basics/rent/steel/api/src/sdk.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::prelude::*;
2+
use steel::*;
3+
4+
pub fn create_system_account(
5+
payer: Pubkey,
6+
new_account: Pubkey,
7+
name: String,
8+
address: String,
9+
) -> Instruction {
10+
let mut name_bytes = [0u8; 32];
11+
let mut address_bytes = [0u8; 64];
12+
13+
name_bytes[..name.len()].copy_from_slice(name.as_bytes());
14+
address_bytes[..address.len()].copy_from_slice(address.as_bytes());
15+
16+
Instruction {
17+
program_id: crate::ID,
18+
accounts: vec![
19+
AccountMeta::new(payer, true),
20+
AccountMeta::new(new_account, true),
21+
AccountMeta::new_readonly(system_program::ID, false),
22+
],
23+
data: CreateSystemAccount {
24+
name: name_bytes,
25+
address: address_bytes,
26+
}
27+
.to_bytes(),
28+
}
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use super::RentAccount;
2+
use steel::*;
3+
4+
#[repr(C)]
5+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
6+
pub struct Address {
7+
pub name: [u8; 32],
8+
pub address: [u8; 64],
9+
}
10+
11+
account!(RentAccount, Address);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mod address;
2+
3+
pub use address::*;
4+
5+
use steel::*;
6+
7+
#[repr(u8)]
8+
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
9+
pub enum RentAccount {
10+
Address = 0,
11+
}

0 commit comments

Comments
 (0)