Skip to content

Commit ea99cc0

Browse files
committed
client: deprecate instructions_bincode
1 parent 20dc653 commit ea99cc0

File tree

10 files changed

+22
-96
lines changed

10 files changed

+22
-96
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = { workspace = true }
1010

1111
[features]
1212
fetch = ["dep:solana-client", "dep:solana-sdk"]
13-
serde = ["dep:bincode", "dep:serde", "kaigan/serde"]
13+
serde = ["dep:bincode", "dep:serde", "kaigan/serde", "solana-config-interface/bincode"]
1414
test-sbf = []
1515

1616
[dependencies]
@@ -19,6 +19,7 @@ borsh = { workspace = true }
1919
kaigan = { workspace = true }
2020
serde = { workspace = true, features = ["derive"], optional = true }
2121
solana-client = { workspace = true, optional = true }
22+
solana-config-interface = { workspace = true, features = ["serde"] }
2223
solana-program = { workspace = true, features = ["borsh"] }
2324
solana-sdk = { workspace = true, optional = true }
2425

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
//! Program instruction helpers.
22
3-
use {
4-
crate::{ConfigKeys, ID},
5-
bincode::serialized_size,
6-
solana_program::{
7-
instruction::{AccountMeta, Instruction},
8-
pubkey::Pubkey,
9-
system_instruction,
10-
},
11-
};
3+
pub use solana_config_interface::instruction::{create_account_with_max_config_space, store};
4+
use solana_program::{instruction::Instruction, pubkey::Pubkey};
125

136
/// Trait defining config state to be stored at the end of the account data.
147
#[deprecated(since = "1.0.0", note = "This trait is no longer supported")]
@@ -17,12 +10,6 @@ pub trait ConfigState: serde::Serialize + Default {
1710
fn max_space() -> u64;
1811
}
1912

20-
fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction {
21-
let account_metas = vec![AccountMeta::new(*config_pubkey, true)];
22-
let account_data = (ConfigKeys { keys: vec![] }, T::default());
23-
Instruction::new_with_bincode(ID, &account_data, account_metas)
24-
}
25-
2613
/// Create a new, empty configuration account
2714
#[deprecated(
2815
since = "1.0.0",
@@ -43,41 +30,3 @@ pub fn create_account<T: ConfigState>(
4330
keys,
4431
)
4532
}
46-
47-
/// Create a new, empty configuration account
48-
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
49-
from_account_pubkey: &Pubkey,
50-
config_account_pubkey: &Pubkey,
51-
lamports: u64,
52-
max_config_space: u64,
53-
keys: Vec<(Pubkey, bool)>,
54-
) -> Vec<Instruction> {
55-
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
56-
vec![
57-
system_instruction::create_account(
58-
from_account_pubkey,
59-
config_account_pubkey,
60-
lamports,
61-
space,
62-
&ID,
63-
),
64-
initialize_account::<T>(config_account_pubkey),
65-
]
66-
}
67-
68-
/// Store new data in a configuration account
69-
pub fn store<T: serde::Serialize>(
70-
config_account_pubkey: &Pubkey,
71-
is_config_signer: bool,
72-
keys: Vec<(Pubkey, bool)>,
73-
data: &T,
74-
) -> Instruction {
75-
let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)];
76-
for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) {
77-
if signer_pubkey != config_account_pubkey {
78-
account_metas.push(AccountMeta::new(*signer_pubkey, true));
79-
}
80-
}
81-
let account_data = (ConfigKeys { keys }, data);
82-
Instruction::new_with_bincode(ID, &account_data, account_metas)
83-
}

clients/rust/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
mod generated;
44
mod hooked;
5-
6-
#[cfg(feature = "serde")]
5+
#[deprecated(since = "1.0.0", note = "use `solana_config_interface` crate instead")]
76
pub mod instructions_bincode;
87

98
pub use {

interface/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ solana-instruction = { workspace = true, optional = true, features = [
1919
solana-pubkey = { workspace = true }
2020
solana-sdk-ids = { workspace = true }
2121
solana-short-vec = { workspace = true, optional = true }
22-
solana-stake-interface = { workspace = true, optional = true, features = [
23-
"bincode",
24-
] }
2522
solana-system-interface = { workspace = true, optional = true, features = [
2623
"bincode",
2724
] }
@@ -31,7 +28,6 @@ bincode = [
3128
"dep:bincode",
3229
"dep:solana-account",
3330
"dep:solana-instruction",
34-
"dep:solana-stake-interface",
3531
"dep:solana-system-interface",
3632
"serde",
3733
]

interface/src/instruction.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
//! Program instruction helpers.
2+
13
use {
2-
crate::{
3-
id,
4-
state::{ConfigKeys, ConfigState},
5-
},
4+
crate::{id, state::ConfigKeys},
5+
bincode::serialized_size,
66
solana_instruction::{AccountMeta, Instruction},
77
solana_pubkey::Pubkey,
8-
solana_system_interface::instruction as system_instruction,
98
};
109

11-
fn initialize_account<T: ConfigState>(config_pubkey: &Pubkey) -> Instruction {
10+
fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction {
1211
let account_metas = vec![AccountMeta::new(*config_pubkey, true)];
1312
let account_data = (ConfigKeys { keys: vec![] }, T::default());
1413
Instruction::new_with_bincode(id(), &account_data, account_metas)
1514
}
1615

1716
/// Create a new, empty configuration account
18-
pub fn create_account<T: ConfigState>(
17+
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
1918
from_account_pubkey: &Pubkey,
2019
config_account_pubkey: &Pubkey,
2120
lamports: u64,
21+
max_config_space: u64,
2222
keys: Vec<(Pubkey, bool)>,
2323
) -> Vec<Instruction> {
24-
let space = T::max_space() + bincode::serialized_size(&ConfigKeys { keys }).unwrap();
24+
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
2525
vec![
26-
system_instruction::create_account(
26+
solana_system_interface::instruction::create_account(
2727
from_account_pubkey,
2828
config_account_pubkey,
2929
lamports,
@@ -35,7 +35,7 @@ pub fn create_account<T: ConfigState>(
3535
}
3636

3737
/// Store new data in a configuration account
38-
pub fn store<T: ConfigState>(
38+
pub fn store<T: serde::Serialize>(
3939
config_account_pubkey: &Pubkey,
4040
is_config_signer: bool,
4141
keys: Vec<(Pubkey, bool)>,

interface/src/state.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1-
use solana_pubkey::Pubkey;
21
#[cfg(feature = "bincode")]
32
#[allow(deprecated)]
4-
use {
5-
bincode::{deserialize, serialized_size},
6-
solana_stake_interface::config::Config as StakeConfig,
7-
};
3+
use bincode::{deserialize, serialized_size};
4+
use solana_pubkey::Pubkey;
85
#[cfg(feature = "serde")]
96
use {
107
serde_derive::{Deserialize, Serialize},
118
solana_short_vec as short_vec,
129
};
1310

14-
#[cfg(feature = "serde")]
15-
pub trait ConfigState: serde::Serialize + Default {
16-
/// Maximum space that the serialized representation will require
17-
fn max_space() -> u64;
18-
}
19-
20-
// TODO move ConfigState into `solana_program` to implement trait locally
21-
#[cfg(feature = "bincode")]
22-
#[allow(deprecated)]
23-
impl ConfigState for StakeConfig {
24-
fn max_space() -> u64 {
25-
serialized_size(&StakeConfig::default()).unwrap()
26-
}
27-
}
28-
2911
/// A collection of keys to be stored in Config account data.
3012
#[derive(Debug, Default)]
3113
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]

program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ thiserror = { workspace = true }
2727
[dev-dependencies]
2828
mollusk-svm = { workspace = true, features = ["fuzz-fd"] }
2929
mollusk-svm-bencher = { workspace = true }
30-
solana-config-program-client = { path = "../clients/rust", features = ["serde"] }
30+
solana-config-interface = { workspace = true, features = ["bincode", "serde"] }
3131
solana-sdk = { workspace = true }
3232

3333
[lib]

program/benches/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use {
22
mollusk_svm_bencher::Bench,
33
serde::Serialize,
4+
solana_config_interface::instruction::store,
45
solana_config_program::state::ConfigKeys,
5-
solana_config_program_client::instructions_bincode::store,
66
solana_sdk::{
77
account::Account,
88
hash::Hash,
@@ -27,7 +27,7 @@ impl BenchContext {
2727
}
2828

2929
/// Trait to avoid re-defining the same instruction and account constructors
30-
/// for each `ConfigState`.
30+
/// for each config state.
3131
pub trait BenchSetup: Default + serde::Serialize {
3232
const BENCH_ID: &'static str;
3333

program/tests/functional.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use {
55
bincode::serialized_size,
66
mollusk_svm::{result::Check, Mollusk},
77
serde::{Deserialize, Serialize},
8+
solana_config_interface::instruction::{self as config_instruction},
89
solana_config_program::{error::ConfigError, state::ConfigKeys},
9-
solana_config_program_client::instructions_bincode::{self as config_instruction},
1010
solana_sdk::{
1111
account::Account,
1212
instruction::{AccountMeta, Instruction},

0 commit comments

Comments
 (0)