-
Notifications
You must be signed in to change notification settings - Fork 7
Add interface crate #47
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1d9bff
add interface crate
kevinheavey 23e02a3
use solana-config-interface in solana-config-program
kevinheavey 841b6f0
rename config_instruction to instruction
kevinheavey f7da53f
explicit feature activation
kevinheavey f6760cb
move to state.rs
kevinheavey 20dc653
remove code no longer required externally
kevinheavey 82d07a1
client: deprecate instructions_bincode
buffalojoec 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| [workspace] | ||
| resolver = "2" | ||
| members = ["clients/rust", "program"] | ||
| members = [ | ||
| "clients/rust", | ||
| "interface", | ||
| "program", | ||
| ] | ||
|
|
||
| [workspace.package] | ||
| authors = ["Anza Technology Maintainers <[email protected]>"] | ||
|
|
@@ -28,7 +32,15 @@ mollusk-svm-bencher = "0.1.3" | |
| num-derive = "0.4" | ||
| num-traits = "0.2" | ||
| serde = "1.0.193" | ||
| serde_derive = "1.0.193" | ||
| solana-account = "2.2.1" | ||
| solana-client = "2.2.1" | ||
| solana-config-interface = { path = "interface", version = "1.0.0" } | ||
| solana-instruction = "2.2.1" | ||
| solana-program = "2.2.1" | ||
| solana-pubkey = "2.2.1" | ||
| solana-sdk = "2.2.1" | ||
| solana-sdk-ids = "2.2.1" | ||
| solana-short-vec = "2.2.1" | ||
| solana-system-interface = "1.0.0" | ||
| thiserror = "1.0.61" | ||
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
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,44 @@ | ||
| [package] | ||
| name = "solana-config-interface" | ||
| description = "Solana config program interface." | ||
| documentation = "https://docs.rs/solana-config-interface" | ||
| version = "1.0.0" | ||
| authors = { workspace = true } | ||
| repository = { workspace = true } | ||
| license-file = { workspace = true } | ||
| edition = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| bincode = { workspace = true, optional = true } | ||
| serde = { workspace = true, optional = true } | ||
| serde_derive = { workspace = true, optional = true } | ||
| solana-account = { workspace = true, optional = true } | ||
| solana-instruction = { workspace = true, optional = true, features = [ | ||
| "bincode", | ||
| ] } | ||
| solana-pubkey = { workspace = true } | ||
| solana-sdk-ids = { workspace = true } | ||
| solana-short-vec = { workspace = true, optional = true } | ||
| solana-system-interface = { workspace = true, optional = true, features = [ | ||
| "bincode", | ||
| ] } | ||
|
|
||
| [features] | ||
| bincode = [ | ||
| "dep:bincode", | ||
| "dep:solana-account", | ||
| "dep:solana-instruction", | ||
| "dep:solana-system-interface", | ||
| "serde", | ||
| ] | ||
| serde = [ | ||
| "dep:serde", | ||
| "dep:serde_derive", | ||
| "dep:solana-short-vec", | ||
| "solana-pubkey/serde", | ||
| ] | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
| all-features = true | ||
| rustdoc-args = ["--cfg=docsrs"] |
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,52 @@ | ||
| //! Program instruction helpers. | ||
|
|
||
| use { | ||
| crate::{id, state::ConfigKeys}, | ||
| bincode::serialized_size, | ||
| solana_instruction::{AccountMeta, Instruction}, | ||
| solana_pubkey::Pubkey, | ||
| }; | ||
|
|
||
| fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction { | ||
| let account_metas = vec![AccountMeta::new(*config_pubkey, true)]; | ||
| let account_data = (ConfigKeys { keys: vec![] }, T::default()); | ||
| Instruction::new_with_bincode(id(), &account_data, account_metas) | ||
| } | ||
|
|
||
| /// Create a new, empty configuration account | ||
| pub fn create_account_with_max_config_space<T: Default + serde::Serialize>( | ||
| from_account_pubkey: &Pubkey, | ||
| config_account_pubkey: &Pubkey, | ||
| lamports: u64, | ||
| max_config_space: u64, | ||
| keys: Vec<(Pubkey, bool)>, | ||
| ) -> Vec<Instruction> { | ||
| let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap()); | ||
| vec![ | ||
| solana_system_interface::instruction::create_account( | ||
| from_account_pubkey, | ||
| config_account_pubkey, | ||
| lamports, | ||
| space, | ||
| &id(), | ||
| ), | ||
| initialize_account::<T>(config_account_pubkey), | ||
| ] | ||
| } | ||
|
|
||
| /// Store new data in a configuration account | ||
| pub fn store<T: serde::Serialize>( | ||
| config_account_pubkey: &Pubkey, | ||
| is_config_signer: bool, | ||
| keys: Vec<(Pubkey, bool)>, | ||
| data: &T, | ||
| ) -> Instruction { | ||
| let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)]; | ||
| for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) { | ||
| if signer_pubkey != config_account_pubkey { | ||
| account_metas.push(AccountMeta::new(*signer_pubkey, true)); | ||
| } | ||
| } | ||
| let account_data = (ConfigKeys { keys }, data); | ||
| Instruction::new_with_bincode(id(), &account_data, account_metas) | ||
| } |
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,6 @@ | ||
| #![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
| #![allow(clippy::arithmetic_side_effects)] | ||
| #[cfg(feature = "bincode")] | ||
| pub mod instruction; | ||
| pub mod state; | ||
| pub use solana_sdk_ids::config::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,16 @@ | ||
| use solana_pubkey::Pubkey; | ||
| #[cfg(feature = "serde")] | ||
| use { | ||
| serde_derive::{Deserialize, Serialize}, | ||
| solana_short_vec as short_vec, | ||
| }; | ||
|
|
||
| /// A collection of keys to be stored in Config account data. | ||
| #[derive(Debug, Default)] | ||
| #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
| pub struct ConfigKeys { | ||
| // Each key tuple comprises a unique `Pubkey` identifier, | ||
| // and `bool` whether that key is a signer of the data | ||
| #[cfg_attr(feature = "serde", serde(with = "short_vec"))] | ||
| pub keys: Vec<(Pubkey, bool)>, | ||
| } |
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
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 was deleted.
Oops, something went wrong.
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
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.
https://github.com/solana-program/config/blob/main/clients/rust/src/instructions_bincode.rs