forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extract instruction crate * remove thiserror * make bincode optional in solana-instruction * make serde optional in solana-instruction * fix doc tests * fmt * harmonize features * fmt Cargo.toml * clippy * fix syscalls.rs imports * update digests * update digest * unused imports * post-rebase fmt * fix doc links * use workspace lints * fmt * make rustc_version dep optional * update digest * update digest * update import * fmt * fix dup import * remove dev-context-only-utils (no longer needed) * fmt * remove unnecessary allow() * fix overwriting instruction syscall stubs * fmt * move get_processed_sibling_instruction and get_stack_height back to solana-program to avoid breaking change * fix path * fix typo * move the checked_add utility function back to solana-program * move AccountMeta to its own file * fix bad import * move ProcessedSiblingInstruction to syscalls.rs * move CompiledInstruction back to solana-program * move ProcessedSiblingInstruction back into lib.rs * make std optional in solana-instruction * fix required features for frozen-abi * update digest * update digest * missing import * update digest * don't assume std is imported in frozen-abi macros * fix import warnings * simplify cfg usage
- Loading branch information
1 parent
875f8b4
commit b4ed7a4
Showing
19 changed files
with
996 additions
and
748 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,58 @@ | ||
[package] | ||
name = "solana-instruction" | ||
description = "Types for directing the execution of Solana programs." | ||
documentation = "https://docs.rs/solana-instruction" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
bincode = { workspace = true, optional = true } | ||
borsh = { workspace = true, optional = true } | ||
num-traits = { workspace = true } | ||
serde = { workspace = true, optional = true } | ||
serde_derive = { workspace = true, optional = true } | ||
solana-frozen-abi = { workspace = true, optional = true } | ||
solana-frozen-abi-macro = { workspace = true, optional = true } | ||
solana-pubkey = { workspace = true, default-features = false } | ||
|
||
[target.'cfg(target_os = "solana")'.dependencies] | ||
solana-define-syscall = { workspace = true } | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } | ||
js-sys = { workspace = true } | ||
wasm-bindgen = { workspace = true } | ||
|
||
[dev-dependencies] | ||
solana-instruction = { path = ".", features = ["borsh"] } | ||
|
||
[build-dependencies] | ||
rustc_version = { workspace = true, optional = true } | ||
|
||
[features] | ||
bincode = ["dep:bincode", "dep:serde"] | ||
borsh = ["dep:borsh"] | ||
default = ["std"] | ||
frozen-abi = [ | ||
"dep:rustc_version", | ||
"dep:solana-frozen-abi", | ||
"dep:solana-frozen-abi-macro", | ||
"serde", | ||
"std", | ||
] | ||
serde = [ | ||
"dep:serde", | ||
"dep:serde_derive", | ||
"solana-pubkey/serde", | ||
] | ||
std = [] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[lints] | ||
workspace = true |
This file contains 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 @@ | ||
../../frozen-abi/build.rs |
This file contains 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,102 @@ | ||
use solana_pubkey::Pubkey; | ||
|
||
/// Describes a single account read or written by a program during instruction | ||
/// execution. | ||
/// | ||
/// When constructing an [`Instruction`], a list of all accounts that may be | ||
/// read or written during the execution of that instruction must be supplied. | ||
/// Any account that may be mutated by the program during execution, either its | ||
/// data or metadata such as held lamports, must be writable. | ||
/// | ||
/// Note that because the Solana runtime schedules parallel transaction | ||
/// execution around which accounts are writable, care should be taken that only | ||
/// accounts which actually may be mutated are specified as writable. As the | ||
/// default [`AccountMeta::new`] constructor creates writable accounts, this is | ||
/// a minor hazard: use [`AccountMeta::new_readonly`] to specify that an account | ||
/// is not writable. | ||
#[repr(C)] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(serde_derive::Serialize, serde_derive::Deserialize) | ||
)] | ||
#[derive(Debug, Default, PartialEq, Eq, Clone)] | ||
pub struct AccountMeta { | ||
/// An account's public key. | ||
pub pubkey: Pubkey, | ||
/// True if an `Instruction` requires a `Transaction` signature matching `pubkey`. | ||
pub is_signer: bool, | ||
/// True if the account data or metadata may be mutated during program execution. | ||
pub is_writable: bool, | ||
} | ||
|
||
impl AccountMeta { | ||
/// Construct metadata for a writable account. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// # use solana_pubkey::Pubkey; | ||
/// # use solana_instruction::{AccountMeta, Instruction}; | ||
/// # use borsh::{BorshSerialize, BorshDeserialize}; | ||
/// # | ||
/// # #[derive(BorshSerialize, BorshDeserialize)] | ||
/// # #[borsh(crate = "borsh")] | ||
/// # pub struct MyInstruction; | ||
/// # | ||
/// # let instruction = MyInstruction; | ||
/// # let from = Pubkey::new_unique(); | ||
/// # let to = Pubkey::new_unique(); | ||
/// # let program_id = Pubkey::new_unique(); | ||
/// let instr = Instruction::new_with_borsh( | ||
/// program_id, | ||
/// &instruction, | ||
/// vec![ | ||
/// AccountMeta::new(from, true), | ||
/// AccountMeta::new(to, false), | ||
/// ], | ||
/// ); | ||
/// ``` | ||
pub fn new(pubkey: Pubkey, is_signer: bool) -> Self { | ||
Self { | ||
pubkey, | ||
is_signer, | ||
is_writable: true, | ||
} | ||
} | ||
|
||
/// Construct metadata for a read-only account. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// # use solana_pubkey::Pubkey; | ||
/// # use solana_instruction::{AccountMeta, Instruction}; | ||
/// # use borsh::{BorshSerialize, BorshDeserialize}; | ||
/// # | ||
/// # #[derive(BorshSerialize, BorshDeserialize)] | ||
/// # #[borsh(crate = "borsh")] | ||
/// # pub struct MyInstruction; | ||
/// # | ||
/// # let instruction = MyInstruction; | ||
/// # let from = Pubkey::new_unique(); | ||
/// # let to = Pubkey::new_unique(); | ||
/// # let from_account_storage = Pubkey::new_unique(); | ||
/// # let program_id = Pubkey::new_unique(); | ||
/// let instr = Instruction::new_with_borsh( | ||
/// program_id, | ||
/// &instruction, | ||
/// vec![ | ||
/// AccountMeta::new(from, true), | ||
/// AccountMeta::new(to, false), | ||
/// AccountMeta::new_readonly(from_account_storage, false), | ||
/// ], | ||
/// ); | ||
/// ``` | ||
pub fn new_readonly(pubkey: Pubkey, is_signer: bool) -> Self { | ||
Self { | ||
pubkey, | ||
is_signer, | ||
is_writable: false, | ||
} | ||
} | ||
} |
Oops, something went wrong.