sdk: put AccountSharedData::set_data() behind feature="dev-context-only-utils" (#33086)
set_data() is deprecated in favor of set_data_from_slice().
This commit is contained in:
parent
b4efbf07f7
commit
16ea141402
|
@ -6924,6 +6924,7 @@ dependencies = [
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"pbkdf2 0.11.0",
|
"pbkdf2 0.11.0",
|
||||||
"qstring",
|
"qstring",
|
||||||
|
"qualifier_attr",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rustc_version 0.4.0",
|
"rustc_version 0.4.0",
|
||||||
|
@ -6939,6 +6940,7 @@ dependencies = [
|
||||||
"solana-frozen-abi-macro",
|
"solana-frozen-abi-macro",
|
||||||
"solana-logger",
|
"solana-logger",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
|
"solana-sdk",
|
||||||
"solana-sdk-macro",
|
"solana-sdk-macro",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn get_append_vec_path(path: &str) -> TempFile {
|
||||||
pub fn create_test_account(sample: usize) -> (StoredMeta, AccountSharedData) {
|
pub fn create_test_account(sample: usize) -> (StoredMeta, AccountSharedData) {
|
||||||
let data_len = sample % 256;
|
let data_len = sample % 256;
|
||||||
let mut account = AccountSharedData::new(sample as u64, 0, &Pubkey::default());
|
let mut account = AccountSharedData::new(sample as u64, 0, &Pubkey::default());
|
||||||
account.set_data((0..data_len).map(|_| data_len as u8).collect());
|
account.set_data_from_slice(&vec![data_len as u8; data_len]);
|
||||||
let stored_meta = StoredMeta {
|
let stored_meta = StoredMeta {
|
||||||
write_version_obsolete: 0,
|
write_version_obsolete: 0,
|
||||||
pubkey: Pubkey::default(),
|
pubkey: Pubkey::default(),
|
||||||
|
|
|
@ -85,6 +85,7 @@ serial_test = { workspace = true }
|
||||||
solana-core = { path = ".", features = ["dev-context-only-utils"] }
|
solana-core = { path = ".", features = ["dev-context-only-utils"] }
|
||||||
solana-logger = { workspace = true }
|
solana-logger = { workspace = true }
|
||||||
solana-program-runtime = { workspace = true }
|
solana-program-runtime = { workspace = true }
|
||||||
|
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
solana-stake-program = { workspace = true }
|
solana-stake-program = { workspace = true }
|
||||||
static_assertions = { workspace = true }
|
static_assertions = { workspace = true }
|
||||||
systemstat = { workspace = true }
|
systemstat = { workspace = true }
|
||||||
|
|
|
@ -87,8 +87,8 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) ->
|
||||||
|
|
||||||
let mut account = AccountSharedData::new(account_details.balance, 0, &owner_program_id);
|
let mut account = AccountSharedData::new(account_details.balance, 0, &owner_program_id);
|
||||||
if account_details.data != "~" {
|
if account_details.data != "~" {
|
||||||
account.set_data(
|
account.set_data_from_slice(
|
||||||
BASE64_STANDARD
|
&BASE64_STANDARD
|
||||||
.decode(account_details.data.as_str())
|
.decode(account_details.data.as_str())
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
|
|
|
@ -493,7 +493,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
|
||||||
if space > 0 {
|
if space > 0 {
|
||||||
let lamports = account_info.lamports.unwrap_or(account.lamports());
|
let lamports = account_info.lamports.unwrap_or(account.lamports());
|
||||||
let mut account = AccountSharedData::new(lamports, space, &owner);
|
let mut account = AccountSharedData::new(lamports, space, &owner);
|
||||||
account.set_data(data);
|
account.set_data_from_slice(&data);
|
||||||
account
|
account
|
||||||
} else {
|
} else {
|
||||||
account
|
account
|
||||||
|
@ -508,7 +508,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
|
||||||
});
|
});
|
||||||
let lamports = account_info.lamports.unwrap_or(0);
|
let lamports = account_info.lamports.unwrap_or(0);
|
||||||
let mut account = AccountSharedData::new(lamports, space, &owner);
|
let mut account = AccountSharedData::new(lamports, space, &owner);
|
||||||
account.set_data(data);
|
account.set_data_from_slice(&data);
|
||||||
account
|
account
|
||||||
};
|
};
|
||||||
transaction_accounts.push((pubkey, account));
|
transaction_accounts.push((pubkey, account));
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub async fn add_lookup_table_account(
|
||||||
data.len(),
|
data.len(),
|
||||||
&solana_address_lookup_table_program::id(),
|
&solana_address_lookup_table_program::id(),
|
||||||
);
|
);
|
||||||
account.set_data(data);
|
account.set_data_from_slice(&data);
|
||||||
context.set_account(&account_address, &account);
|
context.set_account(&account_address, &account);
|
||||||
|
|
||||||
account
|
account
|
||||||
|
|
|
@ -6026,6 +6026,7 @@ dependencies = [
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"pbkdf2 0.11.0",
|
"pbkdf2 0.11.0",
|
||||||
"qstring",
|
"qstring",
|
||||||
|
"qualifier_attr",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
|
|
|
@ -1181,7 +1181,7 @@ mod tests {
|
||||||
let lamports = rent.minimum_balance(version1_14_11_serialized_len);
|
let lamports = rent.minimum_balance(version1_14_11_serialized_len);
|
||||||
let mut vote_account =
|
let mut vote_account =
|
||||||
AccountSharedData::new(lamports, version1_14_11_serialized_len, &id());
|
AccountSharedData::new(lamports, version1_14_11_serialized_len, &id());
|
||||||
vote_account.set_data(version1_14_11_serialized);
|
vote_account.set_data_from_slice(&version1_14_11_serialized);
|
||||||
|
|
||||||
// Create a fake TransactionContext with a fake InstructionContext with a single account which is the
|
// Create a fake TransactionContext with a fake InstructionContext with a single account which is the
|
||||||
// vote account that was just created
|
// vote account that was just created
|
||||||
|
|
|
@ -64,6 +64,7 @@ num-traits = { workspace = true }
|
||||||
num_enum = { workspace = true }
|
num_enum = { workspace = true }
|
||||||
pbkdf2 = { workspace = true }
|
pbkdf2 = { workspace = true }
|
||||||
qstring = { workspace = true }
|
qstring = { workspace = true }
|
||||||
|
qualifier_attr = { workspace = true }
|
||||||
rand = { workspace = true, optional = true }
|
rand = { workspace = true, optional = true }
|
||||||
rand0-7 = { package = "rand", version = "0.7", optional = true }
|
rand0-7 = { package = "rand", version = "0.7", optional = true }
|
||||||
rustversion = { workspace = true }
|
rustversion = { workspace = true }
|
||||||
|
@ -90,6 +91,7 @@ js-sys = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
curve25519-dalek = { workspace = true }
|
curve25519-dalek = { workspace = true }
|
||||||
hex = { workspace = true }
|
hex = { workspace = true }
|
||||||
|
solana-sdk = { path = ".", features = ["dev-context-only-utils"] }
|
||||||
static_assertions = { workspace = true }
|
static_assertions = { workspace = true }
|
||||||
tiny-bip39 = { workspace = true }
|
tiny-bip39 = { workspace = true }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! The Solana [`Account`] type.
|
//! The Solana [`Account`] type.
|
||||||
|
|
||||||
|
#[cfg(feature = "dev-context-only-utils")]
|
||||||
|
use qualifier_attr::qualifiers;
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
clock::{Epoch, INITIAL_RENT_EPOCH},
|
clock::{Epoch, INITIAL_RENT_EPOCH},
|
||||||
|
@ -598,7 +600,8 @@ impl AccountSharedData {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(&mut self, data: Vec<u8>) {
|
#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))]
|
||||||
|
fn set_data(&mut self, data: Vec<u8>) {
|
||||||
self.data = Arc::new(data);
|
self.data = Arc::new(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue