-
Notifications
You must be signed in to change notification settings - Fork 483
Add basics/account-data/steel #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
heyAyushh
merged 9 commits into
solana-developers:main
from
0xCipherCoder:feat-basics-account-data-steel
Jan 2, 2025
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f4be49
Added steel framework code for account data and updated anchor code
0xCipherCoder a8a9a83
Merge branch 'main' of https://github.com/0xCipherCoder/program-examp…
0xCipherCoder a0d0e7c
Removed cargo lock updates
0xCipherCoder 52c7f79
Removed cargo lock updates
0xCipherCoder 71beeeb
Merge branch 'main' of github.com:solana-developers/program-examples …
0xCipherCoder 264deb2
Merged main and removed steel from cargo
0xCipherCoder 88c9543
Fixed clippy and rustfmt issues
0xCipherCoder 3dc265d
Fixed clippy issues
0xCipherCoder 608c33f
Fixed fmt issues
0xCipherCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
basics/account-data/anchor/programs/anchor-program-example/src/constants/constants.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub const ANCHOR_DESCRIMINATOR_SIZE: usize = 8; |
1 change: 1 addition & 0 deletions
1
basics/account-data/anchor/programs/anchor-program-example/src/constants/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod constants; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = "1.3" | ||
| thiserror = "1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Account Data Program Example in Steel Framewrok | ||
|
|
||
| Creates an account with data. | ||
|
|
||
| ## Build | ||
|
|
||
| ```sh | ||
|
|
||
| cargo build-sbf | ||
|
|
||
| ``` | ||
|
|
||
| ## Tests | ||
|
|
||
| Run the tests using following command: | ||
|
|
||
| ```sh | ||
|
|
||
| # Node tests | ||
| pnpm build-and-test # This will build and test the program | ||
|
|
||
| #or | ||
| pnpm test # If you have already built the program test the program | ||
|
|
||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /// Seed of the address_info account PDA. | ||
| pub const ADDRESS_INFO_SEED: &[u8] = b"address_info"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use steel::*; | ||
| use crate::state::AddressInfoData; | ||
|
|
||
| /// Instruction types for the address info program | ||
| #[repr(u8)] | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)] | ||
| pub enum AddressInfoInstruction { | ||
| CreateAddressInfo = 0, | ||
| } | ||
|
|
||
| /// Instruction data for creating address info | ||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug, Pod, Zeroable)] | ||
| pub struct CreateAddressInfo { | ||
| pub data: AddressInfoData, | ||
| } | ||
|
|
||
| // Link instruction type with its data structure | ||
| instruction!(AddressInfoInstruction, CreateAddressInfo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| pub mod consts; | ||
| pub mod instruction; | ||
| pub mod sdk; | ||
| pub mod state; | ||
|
|
||
| pub mod prelude { | ||
| pub use crate::consts::*; | ||
| pub use crate::instruction::*; | ||
| pub use crate::sdk::*; | ||
| pub use crate::state::*; | ||
| } | ||
|
|
||
| use steel::*; | ||
|
|
||
| // Set your Program ID | ||
| declare_id!("Dw6Yq7TZSHdaqB2nKjsxuDrdp5xYCuZaVKFZb5vp5Y4Y"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use steel::*; | ||
| use crate::prelude::*; | ||
|
|
||
| pub fn create_address_info(signer: Pubkey, data: AddressInfoData) -> 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: CreateAddressInfo { data }.to_bytes(), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| use steel::*; | ||
| use crate::consts::ADDRESS_INFO_SEED; | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug, Pod, Zeroable, PartialEq)] | ||
| pub struct AddressInfoData { | ||
| /// Name of the address owner (max 64 bytes) | ||
| pub name: [u8; 64], | ||
| /// House number as bytes | ||
| pub house_number: [u8; 8], | ||
| /// Street name (max 64 bytes) | ||
| pub street: [u8; 64], | ||
| /// City name (max 64 bytes) | ||
| pub city: [u8; 64], | ||
| } | ||
|
|
||
| impl AddressInfoData { | ||
| pub fn new(name: String, house_number: u64, street: String, city: String) -> Self { | ||
| Self { | ||
| name: string_to_bytes(&name), | ||
| house_number: house_number.to_le_bytes(), | ||
| street: string_to_bytes(&street), | ||
| city: string_to_bytes(&city), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn string_to_bytes(s: &str) -> [u8; 64] { | ||
| let mut bytes = [0; 64]; | ||
| let s_bytes = s.as_bytes(); | ||
| let len = s_bytes.len().min(64); | ||
| bytes[..len].copy_from_slice(&s_bytes[..len]); | ||
| bytes | ||
| } | ||
|
|
||
| /// Account type discriminator | ||
| #[repr(u8)] | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] | ||
| pub enum AddressInfoAccount { | ||
| AddressInfo = 0, | ||
| } | ||
|
|
||
| /// Account data structure | ||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] | ||
| pub struct AddressInfo { | ||
| pub data: AddressInfoData, | ||
| } | ||
|
|
||
| // Link account discriminator with account data structure | ||
| account!(AddressInfoAccount, AddressInfo); | ||
|
|
||
| pub fn account_pda() -> (Pubkey, u8) { | ||
| Pubkey::find_program_address(&[ADDRESS_INFO_SEED], &crate::id()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "account-data-program", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "scripts": { | ||
| "test": "pnpm ts-mocha -p ./tsconfig.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/account_data_program.so" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "@solana/web3.js": "^1.95.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/chai": "^4.3.7", | ||
| "@types/mocha": "10.0.9", | ||
| "@types/node": "^22.7.4", | ||
| "borsh": "^2.0.0", | ||
| "chai": "^4.3.7", | ||
| "mocha": "10.7.3", | ||
| "solana-bankrun": "0.4.0", | ||
| "ts-mocha": "^10.0.0", | ||
| "typescript": "5.6.3" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this mention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/solana-developers/program-examples/blob/main/CONTRIBUTING.md#general-coding-and-writing-guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is required to remove? @heyAyushh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I removed steel from the
cargo.tomlfile