account.data -> data() (#15778)
This commit is contained in:
parent
8a3135d17b
commit
52e54e1100
|
@ -238,8 +238,8 @@ mod test {
|
|||
));
|
||||
|
||||
let decoded_account = encoded_account.decode::<Account>().unwrap();
|
||||
assert_eq!(decoded_account.data, vec![0; 1024]);
|
||||
assert_eq!(decoded_account.data(), &vec![0; 1024]);
|
||||
let decoded_account = encoded_account.decode::<AccountSharedData>().unwrap();
|
||||
assert_eq!(decoded_account.data, vec![0; 1024]);
|
||||
assert_eq!(decoded_account.data(), &vec![0; 1024]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ mod test {
|
|||
use crate::validator_info::ValidatorInfo;
|
||||
use serde_json::json;
|
||||
use solana_config_program::create_config_account;
|
||||
use solana_sdk::account::ReadableAccount;
|
||||
|
||||
#[test]
|
||||
fn test_parse_config() {
|
||||
|
@ -101,7 +102,7 @@ mod test {
|
|||
let stake_config_account = create_config_account(vec![], &stake_config, 10);
|
||||
assert_eq!(
|
||||
parse_config(
|
||||
&stake_config_account.data,
|
||||
&stake_config_account.data(),
|
||||
&solana_stake_program::config::id()
|
||||
)
|
||||
.unwrap(),
|
||||
|
@ -124,7 +125,7 @@ mod test {
|
|||
10,
|
||||
);
|
||||
assert_eq!(
|
||||
parse_config(&validator_info_config_account.data, &info_pubkey).unwrap(),
|
||||
parse_config(&validator_info_config_account.data(), &info_pubkey).unwrap(),
|
||||
ConfigAccountType::ValidatorInfo(UiConfig {
|
||||
keys: vec![
|
||||
UiConfigKey {
|
||||
|
|
|
@ -49,7 +49,7 @@ use solana_runtime::{
|
|||
snapshot_utils::get_highest_snapshot_archive_path,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account_utils::StateMut,
|
||||
clock::{Slot, UnixTimestamp, MAX_RECENT_BLOCKHASHES},
|
||||
commitment_config::{CommitmentConfig, CommitmentLevel},
|
||||
|
@ -1202,7 +1202,7 @@ impl JsonRpcRequestProcessor {
|
|||
"Invalid param: not a v2.0 Token account".to_string(),
|
||||
));
|
||||
}
|
||||
let token_account = TokenAccount::unpack(&account.data).map_err(|_| {
|
||||
let token_account = TokenAccount::unpack(&account.data()).map_err(|_| {
|
||||
Error::invalid_params("Invalid param: not a v2.0 Token account".to_string())
|
||||
})?;
|
||||
let mint = &Pubkey::from_str(&token_account.mint.to_string())
|
||||
|
@ -1226,7 +1226,7 @@ impl JsonRpcRequestProcessor {
|
|||
"Invalid param: not a v2.0 Token mint".to_string(),
|
||||
));
|
||||
}
|
||||
let mint = Mint::unpack(&mint_account.data).map_err(|_| {
|
||||
let mint = Mint::unpack(&mint_account.data()).map_err(|_| {
|
||||
Error::invalid_params("Invalid param: mint could not be unpacked".to_string())
|
||||
})?;
|
||||
|
||||
|
@ -1250,7 +1250,7 @@ impl JsonRpcRequestProcessor {
|
|||
.get_filtered_spl_token_accounts_by_mint(&bank, &mint, vec![])
|
||||
.into_iter()
|
||||
.map(|(address, account)| {
|
||||
let amount = TokenAccount::unpack(&account.data)
|
||||
let amount = TokenAccount::unpack(&account.data())
|
||||
.map(|account| account.amount)
|
||||
.unwrap_or(0);
|
||||
let amount = token_amount_to_ui_amount(amount, decimals);
|
||||
|
@ -1384,8 +1384,8 @@ impl JsonRpcRequestProcessor {
|
|||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
let filter_closure = |account: &AccountSharedData| {
|
||||
filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
})
|
||||
};
|
||||
if self
|
||||
|
@ -1437,8 +1437,8 @@ impl JsonRpcRequestProcessor {
|
|||
bank.get_filtered_indexed_accounts(&IndexKey::SplTokenOwner(*owner_key), |account| {
|
||||
account.owner == spl_token_id_v2_0()
|
||||
&& filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -1476,8 +1476,8 @@ impl JsonRpcRequestProcessor {
|
|||
bank.get_filtered_indexed_accounts(&IndexKey::SplTokenMint(*mint_key), |account| {
|
||||
account.owner == spl_token_id_v2_0()
|
||||
&& filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -1565,7 +1565,7 @@ fn get_encoded_account(
|
|||
if account.owner == spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
||||
response = Some(get_parsed_token_account(bank.clone(), pubkey, account));
|
||||
} else if (encoding == UiAccountEncoding::Binary || encoding == UiAccountEncoding::Base58)
|
||||
&& account.data.len() > 128
|
||||
&& account.data().len() > 128
|
||||
{
|
||||
let message = "Encoded binary (base 58) data should be less than 128 bytes, please use Base64 encoding.".to_string();
|
||||
return Err(error::Error {
|
||||
|
@ -1643,7 +1643,7 @@ pub(crate) fn get_parsed_token_account(
|
|||
pubkey: &Pubkey,
|
||||
account: AccountSharedData,
|
||||
) -> UiAccount {
|
||||
let additional_data = get_token_account_mint(&account.data)
|
||||
let additional_data = get_token_account_mint(&account.data())
|
||||
.and_then(|mint_pubkey| get_mint_owner_and_decimals(&bank, &mint_pubkey).ok())
|
||||
.map(|(_, decimals)| AccountAdditionalData {
|
||||
spl_token_decimals: Some(decimals),
|
||||
|
@ -1667,7 +1667,7 @@ where
|
|||
{
|
||||
let mut mint_decimals: HashMap<Pubkey, u8> = HashMap::new();
|
||||
keyed_accounts.filter_map(move |(pubkey, account)| {
|
||||
let additional_data = get_token_account_mint(&account.data).map(|mint_pubkey| {
|
||||
let additional_data = get_token_account_mint(&account.data()).map(|mint_pubkey| {
|
||||
let spl_token_decimals = mint_decimals.get(&mint_pubkey).cloned().or_else(|| {
|
||||
let (_, decimals) = get_mint_owner_and_decimals(&bank, &mint_pubkey).ok()?;
|
||||
mint_decimals.insert(mint_pubkey, decimals);
|
||||
|
@ -1731,7 +1731,7 @@ fn get_mint_owner_and_decimals(bank: &Arc<Bank>, mint: &Pubkey) -> Result<(Pubke
|
|||
let mint_account = bank.get_account(mint).ok_or_else(|| {
|
||||
Error::invalid_params("Invalid param: could not find mint".to_string())
|
||||
})?;
|
||||
let decimals = get_mint_decimals(&mint_account.data)?;
|
||||
let decimals = get_mint_decimals(&mint_account.data())?;
|
||||
Ok((mint_account.owner, decimals))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -562,6 +562,7 @@ mod tests {
|
|||
},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
commitment_config::CommitmentConfig,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
|
@ -837,14 +838,14 @@ mod tests {
|
|||
sleep(Duration::from_millis(200));
|
||||
|
||||
// Test signature confirmation notification #1
|
||||
let expected_data = bank_forks
|
||||
let account = bank_forks
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(1)
|
||||
.unwrap()
|
||||
.get_account(&stake_account.pubkey())
|
||||
.unwrap()
|
||||
.data;
|
||||
.unwrap();
|
||||
let expected_data = account.data();
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "accountNotification",
|
||||
|
@ -942,18 +943,18 @@ mod tests {
|
|||
sleep(Duration::from_millis(200));
|
||||
|
||||
// Test signature confirmation notification #1
|
||||
let expected_data = bank_forks
|
||||
let account = bank_forks
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(1)
|
||||
.unwrap()
|
||||
.get_account(&nonce_account.pubkey())
|
||||
.unwrap()
|
||||
.data;
|
||||
.unwrap();
|
||||
let expected_data = account.data();
|
||||
let expected_data = parse_account_data(
|
||||
&nonce_account.pubkey(),
|
||||
&system_program::id(),
|
||||
&expected_data,
|
||||
expected_data,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -28,7 +28,7 @@ use solana_runtime::{
|
|||
commitment::{BlockCommitmentCache, CommitmentSlots},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::{Slot, UnixTimestamp},
|
||||
commitment_config::CommitmentConfig,
|
||||
pubkey::Pubkey,
|
||||
|
@ -332,8 +332,8 @@ fn filter_program_results(
|
|||
let accounts_is_empty = accounts.is_empty();
|
||||
let keyed_accounts = accounts.into_iter().filter(move |(_, account)| {
|
||||
filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||
RpcFilterType::DataSize(size) => account.data().len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data()),
|
||||
})
|
||||
});
|
||||
let accounts: Box<dyn Iterator<Item = RpcKeyedAccount>> = if program_id == &spl_token_id_v2_0()
|
||||
|
|
|
@ -31,7 +31,7 @@ use solana_runtime::{
|
|||
snapshot_utils::SnapshotVersion,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::{Epoch, Slot},
|
||||
feature::{self, Feature},
|
||||
feature_set,
|
||||
|
@ -2085,7 +2085,7 @@ fn main() {
|
|||
|
||||
println!("---");
|
||||
for (pubkey, (account, slot)) in accounts.into_iter() {
|
||||
let data_len = account.data.len();
|
||||
let data_len = account.data().len();
|
||||
println!("{}:", pubkey);
|
||||
println!(" - balance: {} SOL", lamports_to_sol(account.lamports));
|
||||
println!(" - owner: '{}'", account.owner);
|
||||
|
@ -2093,7 +2093,7 @@ fn main() {
|
|||
println!(" - slot: {}", slot);
|
||||
println!(" - rent_epoch: {}", account.rent_epoch);
|
||||
if !exclude_account_data {
|
||||
println!(" - data: '{}'", bs58::encode(account.data).into_string());
|
||||
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
|
||||
}
|
||||
println!(" - data_len: {}", data_len);
|
||||
}
|
||||
|
@ -2567,7 +2567,7 @@ fn main() {
|
|||
owner: format!("{}", base_account.owner),
|
||||
old_balance: base_account.lamports,
|
||||
new_balance: warped_account.lamports,
|
||||
data_size: base_account.data.len(),
|
||||
data_size: base_account.data().len(),
|
||||
delegation: format_or_na(detail.map(|d| d.voter)),
|
||||
delegation_owner: format_or_na(
|
||||
detail.map(|d| d.voter_owner),
|
||||
|
|
|
@ -20,7 +20,7 @@ use {
|
|||
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
|
||||
},
|
||||
solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Slot,
|
||||
genesis_config::GenesisConfig,
|
||||
keyed_account::KeyedAccount,
|
||||
|
@ -310,7 +310,8 @@ impl program_stubs::SyscallStubs for SyscallStubs {
|
|||
**account_info.try_borrow_mut_lamports().unwrap() = account.borrow().lamports;
|
||||
|
||||
let mut data = account_info.try_borrow_mut_data()?;
|
||||
let new_data = &account.borrow().data;
|
||||
let account_borrow = account.borrow();
|
||||
let new_data = account_borrow.data();
|
||||
if *account_info.owner != account.borrow().owner {
|
||||
// TODO Figure out a better way to allow the System Program to set the account owner
|
||||
#[allow(clippy::transmute_ptr_to_ptr)]
|
||||
|
|
|
@ -24,6 +24,7 @@ use solana_rbpf::{
|
|||
};
|
||||
use solana_runtime::message_processor::MessageProcessor;
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
account_utils::State,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||
|
@ -243,7 +244,7 @@ fn process_instruction_common(
|
|||
Some(executor) => executor,
|
||||
None => create_and_cache_executor(
|
||||
program_id,
|
||||
&program.try_account_ref()?.data[offset..],
|
||||
&program.try_account_ref()?.data()[offset..],
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)?,
|
||||
|
@ -445,7 +446,7 @@ fn process_loader_upgradeable_instruction(
|
|||
// Load and verify the program bits
|
||||
let _ = create_and_cache_executor(
|
||||
program_id,
|
||||
&buffer.try_account_ref()?.data[buffer_data_offset..],
|
||||
&buffer.try_account_ref()?.data()[buffer_data_offset..],
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)?;
|
||||
|
@ -457,7 +458,7 @@ fn process_loader_upgradeable_instruction(
|
|||
})?;
|
||||
programdata.try_account_ref_mut()?.data
|
||||
[programdata_data_offset..programdata_data_offset + buffer_data_len]
|
||||
.copy_from_slice(&buffer.try_account_ref()?.data[buffer_data_offset..]);
|
||||
.copy_from_slice(&buffer.try_account_ref()?.data()[buffer_data_offset..]);
|
||||
|
||||
// Update the Program account
|
||||
program.set_state(&UpgradeableLoaderState::Program {
|
||||
|
@ -573,7 +574,7 @@ fn process_loader_upgradeable_instruction(
|
|||
|
||||
let _ = create_and_cache_executor(
|
||||
program.unsigned_key(),
|
||||
&buffer.try_account_ref()?.data[buffer_data_offset..],
|
||||
&buffer.try_account_ref()?.data()[buffer_data_offset..],
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)?;
|
||||
|
@ -587,7 +588,7 @@ fn process_loader_upgradeable_instruction(
|
|||
})?;
|
||||
programdata.try_account_ref_mut()?.data
|
||||
[programdata_data_offset..programdata_data_offset + buffer_data_len]
|
||||
.copy_from_slice(&buffer.try_account_ref()?.data[buffer_data_offset..]);
|
||||
.copy_from_slice(&buffer.try_account_ref()?.data()[buffer_data_offset..]);
|
||||
for i in &mut programdata.try_account_ref_mut()?.data
|
||||
[programdata_data_offset + buffer_data_len..]
|
||||
{
|
||||
|
@ -707,7 +708,7 @@ fn process_loader_instruction(
|
|||
|
||||
let _ = create_and_cache_executor(
|
||||
program.unsigned_key(),
|
||||
&program.try_account_ref()?.data,
|
||||
&program.try_account_ref()?.data(),
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)?;
|
||||
|
@ -977,8 +978,8 @@ mod tests {
|
|||
)
|
||||
);
|
||||
assert_eq!(
|
||||
vec![0, 0, 0, 1, 2, 3],
|
||||
keyed_accounts[0].account.borrow().data
|
||||
&vec![0, 0, 0, 1, 2, 3],
|
||||
keyed_accounts[0].account.borrow().data()
|
||||
);
|
||||
|
||||
// Case: Overflow
|
||||
|
@ -1363,7 +1364,8 @@ mod tests {
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
&buffer_account.borrow().data[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
|
||||
&buffer_account.borrow().data()
|
||||
[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
|
||||
&[42; 9]
|
||||
);
|
||||
|
||||
|
@ -1404,7 +1406,8 @@ mod tests {
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
&buffer_account.borrow().data[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
|
||||
&buffer_account.borrow().data()
|
||||
[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
|
||||
&[0, 0, 0, 42, 42, 42, 42, 42, 42]
|
||||
);
|
||||
|
||||
|
@ -1622,7 +1625,7 @@ mod tests {
|
|||
assert_eq!(post_program_account.lamports, min_program_balance);
|
||||
assert_eq!(post_program_account.owner, bpf_loader_upgradeable::id());
|
||||
assert_eq!(
|
||||
post_program_account.data.len(),
|
||||
post_program_account.data().len(),
|
||||
UpgradeableLoaderState::program_len().unwrap()
|
||||
);
|
||||
let state: UpgradeableLoaderState = post_program_account.state().unwrap();
|
||||
|
@ -1643,7 +1646,7 @@ mod tests {
|
|||
upgrade_authority_address: Some(upgrade_authority_keypair.pubkey())
|
||||
}
|
||||
);
|
||||
for (i, byte) in post_programdata_account.data
|
||||
for (i, byte) in post_programdata_account.data()
|
||||
[UpgradeableLoaderState::programdata_data_offset().unwrap()..]
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
@ -2315,7 +2318,7 @@ mod tests {
|
|||
upgrade_authority_address: Some(upgrade_authority_address)
|
||||
}
|
||||
);
|
||||
for (i, byte) in programdata_account.borrow().data
|
||||
for (i, byte) in programdata_account.borrow().data()
|
||||
[UpgradeableLoaderState::programdata_data_offset().unwrap()
|
||||
..UpgradeableLoaderState::programdata_data_offset().unwrap() + elf_new.len()]
|
||||
.iter()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
||||
use solana_sdk::{
|
||||
bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE, instruction::InstructionError,
|
||||
keyed_account::KeyedAccount, pubkey::Pubkey,
|
||||
account::ReadableAccount, bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE,
|
||||
instruction::InstructionError, keyed_account::KeyedAccount, pubkey::Pubkey,
|
||||
};
|
||||
use std::{
|
||||
io::prelude::*,
|
||||
|
@ -86,7 +86,8 @@ pub fn serialize_parameters_unaligned(
|
|||
.unwrap();
|
||||
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
|
||||
.unwrap();
|
||||
v.write_all(&keyed_account.try_account_ref()?.data).unwrap();
|
||||
v.write_all(&keyed_account.try_account_ref()?.data())
|
||||
.unwrap();
|
||||
v.write_all(keyed_account.owner()?.as_ref()).unwrap();
|
||||
v.write_u8(keyed_account.executable()? as u8).unwrap();
|
||||
v.write_u64::<LittleEndian>(keyed_account.rent_epoch()? as u64)
|
||||
|
@ -181,7 +182,8 @@ pub fn serialize_parameters_aligned(
|
|||
.unwrap();
|
||||
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
|
||||
.unwrap();
|
||||
v.write_all(&keyed_account.try_account_ref()?.data).unwrap();
|
||||
v.write_all(&keyed_account.try_account_ref()?.data())
|
||||
.unwrap();
|
||||
v.resize(
|
||||
v.len()
|
||||
+ MAX_PERMITTED_DATA_INCREASE
|
||||
|
@ -323,7 +325,7 @@ mod tests {
|
|||
assert_eq!(key, *account_info.key);
|
||||
let account = account.borrow();
|
||||
assert_eq!(account.lamports, account_info.lamports());
|
||||
assert_eq!(&account.data[..], &account_info.data.borrow()[..]);
|
||||
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]);
|
||||
assert_eq!(&account.owner, account_info.owner);
|
||||
assert_eq!(account.executable, account_info.executable);
|
||||
assert_eq!(account.rent_epoch, account_info.rent_epoch);
|
||||
|
@ -360,7 +362,7 @@ mod tests {
|
|||
assert_eq!(key, *account_info.key);
|
||||
let account = account.borrow();
|
||||
assert_eq!(account.lamports, account_info.lamports());
|
||||
assert_eq!(&account.data[..], &account_info.data.borrow()[..]);
|
||||
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]);
|
||||
assert_eq!(&account.owner, account_info.owner);
|
||||
assert_eq!(account.executable, account_info.executable);
|
||||
assert_eq!(account.rent_epoch, account_info.rent_epoch);
|
||||
|
|
|
@ -10,7 +10,7 @@ use solana_rbpf::{
|
|||
};
|
||||
use solana_runtime::message_processor::MessageProcessor;
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account_info::AccountInfo,
|
||||
account_utils::StateMut,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
|
@ -1665,7 +1665,7 @@ fn call<'a>(
|
|||
if message.is_writable(i) && !account.executable {
|
||||
*account_ref.lamports = account.lamports;
|
||||
*account_ref.owner = account.owner;
|
||||
if account_ref.data.len() != account.data.len() {
|
||||
if account_ref.data.len() != account.data().len() {
|
||||
if !account_ref.data.is_empty() {
|
||||
// Only support for `CreateAccount` at this time.
|
||||
// Need a way to limit total realloc size across multiple CPI calls
|
||||
|
@ -1678,7 +1678,8 @@ fn call<'a>(
|
|||
)
|
||||
.into());
|
||||
}
|
||||
if account.data.len() > account_ref.data.len() + MAX_PERMITTED_DATA_INCREASE
|
||||
if account.data().len()
|
||||
> account_ref.data.len() + MAX_PERMITTED_DATA_INCREASE
|
||||
{
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
|
@ -1694,14 +1695,14 @@ fn call<'a>(
|
|||
memory_mapping,
|
||||
AccessType::Store,
|
||||
account_ref.vm_data_addr,
|
||||
account.data.len() as u64,
|
||||
account.data().len() as u64,
|
||||
)?;
|
||||
*account_ref.ref_to_len_in_vm = account.data.len() as u64;
|
||||
*account_ref.serialized_len_ptr = account.data.len() as u64;
|
||||
*account_ref.ref_to_len_in_vm = account.data().len() as u64;
|
||||
*account_ref.serialized_len_ptr = account.data().len() as u64;
|
||||
}
|
||||
account_ref
|
||||
.data
|
||||
.clone_from_slice(&account.data[0..account_ref.data.len()]);
|
||||
.clone_from_slice(&account.data()[0..account_ref.data.len()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
|||
use chrono::prelude::{DateTime, Utc};
|
||||
use log::*;
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
hash::hash,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
|
@ -95,7 +96,7 @@ fn apply_account_data(
|
|||
if let Some(ref mut expr) = budget_state.pending_budget {
|
||||
let key = witness_keyed_account.unsigned_key();
|
||||
let program_id = witness_keyed_account.owner()?;
|
||||
let actual_hash = hash(&witness_keyed_account.try_account_ref()?.data);
|
||||
let actual_hash = hash(&witness_keyed_account.try_account_ref()?.data());
|
||||
expr.apply_witness(&Witness::AccountData(actual_hash, program_id), key);
|
||||
final_payment = expr.final_payment();
|
||||
}
|
||||
|
@ -136,7 +137,8 @@ pub fn process_instruction(
|
|||
return Ok(());
|
||||
}
|
||||
let existing =
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref_mut()?.data).ok();
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref_mut()?.data())
|
||||
.ok();
|
||||
if Some(true) == existing.map(|x| x.initialized) {
|
||||
trace!("contract already exists");
|
||||
return Err(InstructionError::AccountAlreadyInitialized);
|
||||
|
@ -151,7 +153,7 @@ pub fn process_instruction(
|
|||
let witness_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let contract_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let mut budget_state =
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data)?;
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data())?;
|
||||
if !budget_state.is_pending() {
|
||||
return Ok(()); // Nothing to do here.
|
||||
}
|
||||
|
@ -177,7 +179,7 @@ pub fn process_instruction(
|
|||
let witness_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let contract_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let mut budget_state =
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data)?;
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data())?;
|
||||
if !budget_state.is_pending() {
|
||||
return Ok(()); // Nothing to do here.
|
||||
}
|
||||
|
@ -202,7 +204,7 @@ pub fn process_instruction(
|
|||
let witness_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let contract_keyed_account = next_keyed_account(keyed_accounts_iter)?;
|
||||
let mut budget_state =
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data)?;
|
||||
BudgetState::deserialize(&contract_keyed_account.try_account_ref()?.data())?;
|
||||
if !budget_state.is_pending() {
|
||||
return Ok(()); // Nothing to do here.
|
||||
}
|
||||
|
@ -528,7 +530,10 @@ mod tests {
|
|||
..AccountSharedData::default()
|
||||
};
|
||||
bank.store_account(&game_pubkey, &game_account);
|
||||
assert_eq!(bank.get_account(&game_pubkey).unwrap().data, vec![1, 2, 3]);
|
||||
assert_eq!(
|
||||
bank.get_account(&game_pubkey).unwrap().data(),
|
||||
&vec![1, 2, 3]
|
||||
);
|
||||
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::ConfigKeys;
|
||||
use bincode::deserialize;
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
feature_set, ic_msg,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
|
@ -29,7 +30,7 @@ pub fn process_instruction(
|
|||
return Err(InstructionError::InvalidAccountOwner);
|
||||
}
|
||||
|
||||
deserialize(&config_account.data).map_err(|err| {
|
||||
deserialize(&config_account.data()).map_err(|err| {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Unable to deserialize config account: {}",
|
||||
|
@ -206,7 +207,7 @@ mod tests {
|
|||
let (_, config_account) = create_config_account(keys);
|
||||
assert_eq!(
|
||||
Some(MyConfig::default()),
|
||||
deserialize(get_config_data(&config_account.borrow().data).unwrap()).ok()
|
||||
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
Some(my_config),
|
||||
deserialize(get_config_data(&config_account.borrow().data).unwrap()).ok()
|
||||
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -315,11 +316,11 @@ mod tests {
|
|||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
|
||||
assert_eq!(meta_data.keys, keys);
|
||||
assert_eq!(
|
||||
Some(my_config),
|
||||
deserialize(get_config_data(&config_account.borrow().data).unwrap()).ok()
|
||||
deserialize(get_config_data(&config_account.borrow().data()).unwrap()).ok()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -453,11 +454,12 @@ mod tests {
|
|||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
|
||||
assert_eq!(meta_data.keys, keys);
|
||||
assert_eq!(
|
||||
new_config,
|
||||
MyConfig::deserialize(get_config_data(&config_account.borrow().data).unwrap()).unwrap()
|
||||
MyConfig::deserialize(get_config_data(&config_account.borrow().data()).unwrap())
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
// Attempt update with incomplete signatures
|
||||
|
@ -558,11 +560,12 @@ mod tests {
|
|||
),
|
||||
Ok(())
|
||||
);
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data).unwrap();
|
||||
let meta_data: ConfigKeys = deserialize(&config_account.borrow().data()).unwrap();
|
||||
assert_eq!(meta_data.keys, keys);
|
||||
assert_eq!(
|
||||
new_config,
|
||||
MyConfig::deserialize(get_config_data(&config_account.borrow().data).unwrap()).unwrap()
|
||||
MyConfig::deserialize(get_config_data(&config_account.borrow().data()).unwrap())
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
// Attempt update with incomplete signatures
|
||||
|
|
|
@ -8,8 +8,9 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
|||
use serde_derive::Serialize;
|
||||
use solana_metrics::inc_new_counter_info;
|
||||
use solana_sdk::{
|
||||
decode_error::DecodeError, instruction::InstructionError, keyed_account::KeyedAccount,
|
||||
process_instruction::InvokeContext, program_utils::limited_deserialize, pubkey::Pubkey,
|
||||
account::ReadableAccount, decode_error::DecodeError, instruction::InstructionError,
|
||||
keyed_account::KeyedAccount, process_instruction::InvokeContext,
|
||||
program_utils::limited_deserialize, pubkey::Pubkey,
|
||||
};
|
||||
use std::cmp;
|
||||
use thiserror::Error;
|
||||
|
@ -188,7 +189,7 @@ impl ExchangeProcessor {
|
|||
error!("Not enough accounts");
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
Self::is_account_unallocated(&keyed_accounts[NEW_ACCOUNT_INDEX].try_account_ref()?.data)?;
|
||||
Self::is_account_unallocated(&keyed_accounts[NEW_ACCOUNT_INDEX].try_account_ref()?.data())?;
|
||||
Self::serialize(
|
||||
&ExchangeState::Account(
|
||||
TokenAccountInfo::default()
|
||||
|
@ -216,13 +217,13 @@ impl ExchangeProcessor {
|
|||
}
|
||||
|
||||
let mut to_account =
|
||||
Self::deserialize_account(&keyed_accounts[TO_ACCOUNT_INDEX].try_account_ref()?.data)?;
|
||||
Self::deserialize_account(&keyed_accounts[TO_ACCOUNT_INDEX].try_account_ref()?.data())?;
|
||||
|
||||
if &faucet::id() == keyed_accounts[FROM_ACCOUNT_INDEX].unsigned_key() {
|
||||
to_account.tokens[token] += tokens;
|
||||
} else {
|
||||
let state: ExchangeState =
|
||||
bincode::deserialize(&keyed_accounts[FROM_ACCOUNT_INDEX].try_account_ref()?.data)
|
||||
bincode::deserialize(&keyed_accounts[FROM_ACCOUNT_INDEX].try_account_ref()?.data())
|
||||
.map_err(Self::map_to_invalid_arg)?;
|
||||
match state {
|
||||
ExchangeState::Account(mut from_account) => {
|
||||
|
@ -302,10 +303,11 @@ impl ExchangeProcessor {
|
|||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
|
||||
Self::is_account_unallocated(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data)?;
|
||||
Self::is_account_unallocated(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
|
||||
|
||||
let mut account =
|
||||
Self::deserialize_account(&keyed_accounts[ACCOUNT_INDEX].try_account_ref_mut()?.data)?;
|
||||
let mut account = Self::deserialize_account(
|
||||
&keyed_accounts[ACCOUNT_INDEX].try_account_ref_mut()?.data(),
|
||||
)?;
|
||||
|
||||
if &account.owner != keyed_accounts[OWNER_INDEX].unsigned_key() {
|
||||
error!("Signer does not own account");
|
||||
|
@ -355,7 +357,8 @@ impl ExchangeProcessor {
|
|||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
|
||||
let order = Self::deserialize_order(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data)?;
|
||||
let order =
|
||||
Self::deserialize_order(&keyed_accounts[ORDER_INDEX].try_account_ref()?.data())?;
|
||||
|
||||
if &order.owner != keyed_accounts[OWNER_INDEX].unsigned_key() {
|
||||
error!("Signer does not own order");
|
||||
|
@ -389,11 +392,13 @@ impl ExchangeProcessor {
|
|||
}
|
||||
|
||||
let mut to_order =
|
||||
Self::deserialize_order(&keyed_accounts[TO_ORDER_INDEX].try_account_ref()?.data)?;
|
||||
Self::deserialize_order(&keyed_accounts[TO_ORDER_INDEX].try_account_ref()?.data())?;
|
||||
let mut from_order =
|
||||
Self::deserialize_order(&keyed_accounts[FROM_ORDER_INDEX].try_account_ref()?.data)?;
|
||||
Self::deserialize_order(&keyed_accounts[FROM_ORDER_INDEX].try_account_ref()?.data())?;
|
||||
let mut profit_account = Self::deserialize_account(
|
||||
&keyed_accounts[PROFIT_ACCOUNT_INDEX].try_account_ref()?.data,
|
||||
&keyed_accounts[PROFIT_ACCOUNT_INDEX]
|
||||
.try_account_ref()?
|
||||
.data(),
|
||||
)?;
|
||||
|
||||
if to_order.side != OrderSide::Ask {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::ownable_instruction::OwnableError;
|
||||
use bincode::serialize_into;
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
process_instruction::InvokeContext,
|
||||
|
@ -37,7 +38,7 @@ pub fn process_instruction(
|
|||
let keyed_accounts_iter = &mut keyed_accounts.iter();
|
||||
let account_keyed_account = &mut next_keyed_account(keyed_accounts_iter)?;
|
||||
let mut account_owner_pubkey: Pubkey =
|
||||
limited_deserialize(&account_keyed_account.try_account_ref()?.data)?;
|
||||
limited_deserialize(&account_keyed_account.try_account_ref()?.data())?;
|
||||
|
||||
if account_owner_pubkey == Pubkey::default() {
|
||||
account_owner_pubkey = new_owner_pubkey;
|
||||
|
|
|
@ -51,7 +51,7 @@ impl ConfigState for Config {
|
|||
|
||||
pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
|
||||
let mut account = create_config_account(vec![], &Config::default(), 0);
|
||||
let lamports = genesis_config.rent.minimum_balance(account.data.len());
|
||||
let lamports = genesis_config.rent.minimum_balance(account.data().len());
|
||||
|
||||
account.lamports = lamports.max(1);
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ use crate::{
|
|||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::ReadableAccount,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account_utils::{State, StateMut},
|
||||
clock::{Clock, Epoch, UnixTimestamp},
|
||||
ic_msg,
|
||||
|
@ -1544,7 +1543,7 @@ pub fn rewrite_stakes(
|
|||
) -> Result<RewriteStakeStatus, InstructionError> {
|
||||
match stake_account.state()? {
|
||||
StakeState::Initialized(mut meta) => {
|
||||
let meta_status = meta.rewrite_rent_exempt_reserve(rent, stake_account.data.len());
|
||||
let meta_status = meta.rewrite_rent_exempt_reserve(rent, stake_account.data().len());
|
||||
|
||||
if meta_status.is_none() {
|
||||
return Err(InstructionError::InvalidAccountData);
|
||||
|
@ -1554,7 +1553,7 @@ pub fn rewrite_stakes(
|
|||
Ok(("initialized", meta_status.unwrap_or_default(), (0, 0)))
|
||||
}
|
||||
StakeState::Stake(mut meta, mut stake) => {
|
||||
let meta_status = meta.rewrite_rent_exempt_reserve(rent, stake_account.data.len());
|
||||
let meta_status = meta.rewrite_rent_exempt_reserve(rent, stake_account.data().len());
|
||||
let stake_status = stake
|
||||
.delegation
|
||||
.rewrite_stake(stake_account.lamports, meta.rent_exempt_reserve);
|
||||
|
@ -1613,7 +1612,7 @@ pub fn create_lockup_stake_account(
|
|||
let mut stake_account =
|
||||
AccountSharedData::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
||||
|
||||
let rent_exempt_reserve = rent.minimum_balance(stake_account.data.len());
|
||||
let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
|
||||
assert!(
|
||||
lamports >= rent_exempt_reserve,
|
||||
"lamports: {} is less than rent_exempt_reserve {}",
|
||||
|
@ -1682,7 +1681,7 @@ fn do_create_account(
|
|||
|
||||
let vote_state = VoteState::from(vote_account).expect("vote_state");
|
||||
|
||||
let rent_exempt_reserve = rent.minimum_balance(stake_account.data.len());
|
||||
let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
|
||||
|
||||
stake_account
|
||||
.set_state(&StakeState::Stake(
|
||||
|
|
|
@ -7,7 +7,7 @@ use chrono::prelude::*;
|
|||
use solana_config_program::date_instruction::DateConfig;
|
||||
use solana_config_program::get_config_data;
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
feature_set,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
|
@ -28,7 +28,7 @@ fn verify_date_account(
|
|||
let account = verify_account(keyed_account, expected_pubkey)?;
|
||||
|
||||
let config_data =
|
||||
get_config_data(&account.data).map_err(|_| InstructionError::InvalidAccountData)?;
|
||||
get_config_data(&account.data()).map_err(|_| InstructionError::InvalidAccountData)?;
|
||||
let date_config =
|
||||
DateConfig::deserialize(config_data).ok_or(InstructionError::InvalidAccountData)?;
|
||||
|
||||
|
@ -90,7 +90,7 @@ pub fn process_instruction(
|
|||
..VestState::default()
|
||||
}
|
||||
} else {
|
||||
VestState::deserialize(&contract_account.data)?
|
||||
VestState::deserialize(&contract_account.data())?
|
||||
};
|
||||
|
||||
match instruction {
|
||||
|
|
|
@ -119,7 +119,7 @@ impl VestState {
|
|||
mod test {
|
||||
use super::*;
|
||||
use crate::id;
|
||||
use solana_sdk::account::AccountSharedData;
|
||||
use solana_sdk::account::{AccountSharedData, ReadableAccount};
|
||||
use solana_sdk::system_program;
|
||||
|
||||
#[test]
|
||||
|
@ -127,7 +127,7 @@ mod test {
|
|||
let mut a = AccountSharedData::new(0, 512, &id());
|
||||
let b = VestState::default();
|
||||
b.serialize(&mut a.data).unwrap();
|
||||
let c = VestState::deserialize(&a.data).unwrap();
|
||||
let c = VestState::deserialize(&a.data()).unwrap();
|
||||
assert_eq!(b, c);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use solana_runtime::append_vec::{
|
|||
test_utils::{create_test_account, get_append_vec_path},
|
||||
AppendVec,
|
||||
};
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::{account::ReadableAccount, hash::Hash};
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
thread::sleep,
|
||||
|
@ -51,7 +51,7 @@ fn append_vec_sequential_read(bencher: &mut Bencher) {
|
|||
println!("reading pos {} {}", sample, pos);
|
||||
let (account, _next) = vec.get_account(pos).unwrap();
|
||||
let (_meta, test) = create_test_account(sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
assert_eq!(account.data, test.data().as_slice());
|
||||
indexes.push((sample, pos));
|
||||
});
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ fn append_vec_random_read(bencher: &mut Bencher) {
|
|||
let (sample, pos) = &indexes[random_index];
|
||||
let (account, _next) = vec.get_account(*pos).unwrap();
|
||||
let (_meta, test) = create_test_account(*sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
assert_eq!(account.data, test.data().as_slice());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ fn append_vec_concurrent_append_read(bencher: &mut Bencher) {
|
|||
let (sample, pos) = *indexes.lock().unwrap().get(random_index).unwrap();
|
||||
let (account, _next) = vec.get_account(pos).unwrap();
|
||||
let (_meta, test) = create_test_account(sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
assert_eq!(account.data, test.data().as_slice());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ fn append_vec_concurrent_read_append(bencher: &mut Bencher) {
|
|||
let (sample, pos) = *indexes1.lock().unwrap().get(random_index % len).unwrap();
|
||||
let (account, _next) = vec1.get_account(pos).unwrap();
|
||||
let (_meta, test) = create_test_account(sample);
|
||||
assert_eq!(account.data, test.data.as_slice());
|
||||
assert_eq!(account.data, test.data().as_slice());
|
||||
});
|
||||
bencher.iter(|| {
|
||||
let sample: usize = thread_rng().gen_range(0, 256);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
use dashmap::DashMap;
|
||||
use solana_sdk::{account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey};
|
||||
use solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Slot,
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
ops::Deref,
|
||||
|
@ -46,10 +51,10 @@ impl SlotCacheInner {
|
|||
if self.cache.contains_key(pubkey) {
|
||||
self.same_account_writes.fetch_add(1, Ordering::Relaxed);
|
||||
self.same_account_writes_size
|
||||
.fetch_add(account.data.len() as u64, Ordering::Relaxed);
|
||||
.fetch_add(account.data().len() as u64, Ordering::Relaxed);
|
||||
} else {
|
||||
self.unique_account_writes_size
|
||||
.fetch_add(account.data.len() as u64, Ordering::Relaxed);
|
||||
.fetch_add(account.data().len() as u64, Ordering::Relaxed);
|
||||
}
|
||||
self.cache.insert(*pubkey, CachedAccount { account, hash });
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ use serde::{Deserialize, Serialize};
|
|||
use solana_measure::measure::Measure;
|
||||
use solana_rayon_threadlimit::get_thread_count;
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::{Epoch, Slot},
|
||||
genesis_config::ClusterType,
|
||||
hash::{Hash, Hasher},
|
||||
|
@ -575,7 +575,9 @@ impl BankHashStats {
|
|||
} else {
|
||||
self.num_updated_accounts += 1;
|
||||
}
|
||||
self.total_data_len = self.total_data_len.wrapping_add(account.data.len() as u64);
|
||||
self.total_data_len = self
|
||||
.total_data_len
|
||||
.wrapping_add(account.data().len() as u64);
|
||||
if account.executable {
|
||||
self.num_executable_accounts += 1;
|
||||
}
|
||||
|
@ -2840,7 +2842,7 @@ impl AccountsDb {
|
|||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
&account.data,
|
||||
&account.data(),
|
||||
pubkey,
|
||||
include_owner,
|
||||
)
|
||||
|
@ -2851,7 +2853,7 @@ impl AccountsDb {
|
|||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
&account.data,
|
||||
&account.data(),
|
||||
pubkey,
|
||||
include_owner,
|
||||
)
|
||||
|
@ -2861,7 +2863,7 @@ impl AccountsDb {
|
|||
fn hash_frozen_account_data(account: &AccountSharedData) -> Hash {
|
||||
let mut hasher = Hasher::default();
|
||||
|
||||
hasher.hash(&account.data);
|
||||
hasher.hash(&account.data());
|
||||
hasher.hash(&account.owner.as_ref());
|
||||
|
||||
if account.executable {
|
||||
|
@ -2981,7 +2983,7 @@ impl AccountsDb {
|
|||
let mut storage_find = Measure::start("storage_finder");
|
||||
let storage = storage_finder(
|
||||
slot,
|
||||
accounts_and_meta_to_store[infos.len()].1.data.len() + STORE_META_OVERHEAD,
|
||||
accounts_and_meta_to_store[infos.len()].1.data().len() + STORE_META_OVERHEAD,
|
||||
);
|
||||
storage_find.stop();
|
||||
total_storage_find_us += storage_find.as_us();
|
||||
|
@ -2997,7 +2999,7 @@ impl AccountsDb {
|
|||
storage.set_status(AccountStorageStatus::Full);
|
||||
|
||||
// See if an account overflows the append vecs in the slot.
|
||||
let data_len = (accounts_and_meta_to_store[infos.len()].1.data.len()
|
||||
let data_len = (accounts_and_meta_to_store[infos.len()].1.data().len()
|
||||
+ STORE_META_OVERHEAD) as u64;
|
||||
if !self.has_space_available(slot, data_len) {
|
||||
let special_store_size = std::cmp::max(data_len * 2, self.file_size);
|
||||
|
@ -3204,7 +3206,7 @@ impl AccountsDb {
|
|||
true
|
||||
}
|
||||
Occupied(_occupied_entry) => {
|
||||
*account_bytes_saved += account.data.len();
|
||||
*account_bytes_saved += account.data().len();
|
||||
*num_accounts_saved += 1;
|
||||
// If a later root already wrote this account, no point
|
||||
// in flushing it
|
||||
|
@ -3283,7 +3285,7 @@ impl AccountsDb {
|
|||
.unwrap_or(true);
|
||||
if should_flush {
|
||||
let hash = iter_item.value().hash;
|
||||
total_size += (account.data.len() + STORE_META_OVERHEAD) as u64;
|
||||
total_size += (account.data().len() + STORE_META_OVERHEAD) as u64;
|
||||
num_flushed += 1;
|
||||
Some(((key, account), hash))
|
||||
} else {
|
||||
|
@ -3394,7 +3396,7 @@ impl AccountsDb {
|
|||
} else {
|
||||
*account
|
||||
};
|
||||
let data_len = account.data.len() as u64;
|
||||
let data_len = account.data().len() as u64;
|
||||
let meta = StoredMeta {
|
||||
write_version: write_version_producer.next().unwrap(),
|
||||
pubkey: **pubkey,
|
||||
|
@ -3948,7 +3950,7 @@ impl AccountsDb {
|
|||
slot,
|
||||
pubkey,
|
||||
&pubkey_account.1.owner,
|
||||
&pubkey_account.1.data,
|
||||
&pubkey_account.1.data(),
|
||||
&self.account_indexes,
|
||||
info,
|
||||
&mut reclaims,
|
||||
|
@ -4129,7 +4131,7 @@ impl AccountsDb {
|
|||
let hashes: Vec<_> = accounts
|
||||
.iter()
|
||||
.map(|(pubkey, account)| {
|
||||
total_data += account.data.len();
|
||||
total_data += account.data().len();
|
||||
stats.update(account);
|
||||
Self::hash_account(slot, account, pubkey, cluster_type)
|
||||
})
|
||||
|
@ -5049,7 +5051,11 @@ pub mod tests {
|
|||
};
|
||||
use assert_matches::assert_matches;
|
||||
use rand::{thread_rng, Rng};
|
||||
use solana_sdk::{account::AccountSharedData, hash::HASH_BYTES, pubkey::PUBKEY_BYTES};
|
||||
use solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
hash::HASH_BYTES,
|
||||
pubkey::PUBKEY_BYTES,
|
||||
};
|
||||
use std::{
|
||||
iter::FromIterator,
|
||||
str::FromStr,
|
||||
|
@ -6750,7 +6756,7 @@ pub mod tests {
|
|||
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
let ret = db.load_slow(&ancestors, &key).unwrap();
|
||||
assert_eq!(ret.0.data.len(), data_len);
|
||||
assert_eq!(ret.0.data().len(), data_len);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -5,7 +5,7 @@ use log::*;
|
|||
use memmap2::MmapMut;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::{Epoch, Slot},
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
|
@ -468,7 +468,7 @@ impl AppendVec {
|
|||
let account_meta = AccountMeta::from(*account);
|
||||
let account_meta_ptr = &account_meta as *const AccountMeta;
|
||||
let data_len = stored_meta.data_len as usize;
|
||||
let data_ptr = account.data.as_ptr();
|
||||
let data_ptr = account.data().as_ptr();
|
||||
let hash_ptr = hash.as_ref().as_ptr();
|
||||
let ptrs = [
|
||||
(meta_ptr as *const u8, mem::size_of::<StoredMeta>()),
|
||||
|
|
|
@ -31,7 +31,10 @@ use rayon::ThreadPool;
|
|||
use solana_measure::measure::Measure;
|
||||
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
|
||||
use solana_sdk::{
|
||||
account::{create_account_shared_data as create_account, from_account, AccountSharedData},
|
||||
account::{
|
||||
create_account_shared_data as create_account, from_account, AccountSharedData,
|
||||
ReadableAccount,
|
||||
},
|
||||
clock::{
|
||||
Epoch, Slot, SlotCount, SlotIndex, UnixTimestamp, DEFAULT_TICKS_PER_SECOND,
|
||||
MAX_PROCESSING_AGE, MAX_RECENT_BLOCKHASHES, MAX_TRANSACTION_FORWARDING_DELAY,
|
||||
|
@ -2189,7 +2192,7 @@ impl Bank {
|
|||
name, program_id
|
||||
),
|
||||
Some(account) => {
|
||||
if *name == String::from_utf8_lossy(&account.data) {
|
||||
if *name == String::from_utf8_lossy(&account.data()) {
|
||||
// nop; it seems that already AccountsDb is updated.
|
||||
return;
|
||||
}
|
||||
|
@ -5276,7 +5279,7 @@ pub(crate) mod tests {
|
|||
let system_program_id = system_program::id();
|
||||
let mut system_program_account = bank.get_account(&system_program_id).unwrap();
|
||||
system_program_account.lamports =
|
||||
bank.get_minimum_balance_for_rent_exemption(system_program_account.data.len());
|
||||
bank.get_minimum_balance_for_rent_exemption(system_program_account.data().len());
|
||||
bank.store_account(&system_program_id, &system_program_account);
|
||||
bank_with_success_txs.store_account(&system_program_id, &system_program_account);
|
||||
|
||||
|
@ -6050,7 +6053,7 @@ pub(crate) mod tests {
|
|||
// Then, at store time we deducted `magic_rent_number` rent for the current epoch, once it has balance
|
||||
assert_eq!(account10.rent_epoch, bank.epoch + 1);
|
||||
// account data is blank now
|
||||
assert_eq!(account10.data.len(), 0);
|
||||
assert_eq!(account10.data().len(), 0);
|
||||
// 10 - 10(Rent) + 929(Transfer) - magic_rent_number(Rent)
|
||||
assert_eq!(account10.lamports, 929 - magic_rent_number);
|
||||
rent_collected += magic_rent_number + 10;
|
||||
|
@ -8974,7 +8977,7 @@ pub(crate) mod tests {
|
|||
);
|
||||
let new_vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap();
|
||||
// Vote loader account should not be updated since it was included in the genesis config.
|
||||
assert_eq!(vote_loader_account.data, new_vote_loader_account.data);
|
||||
assert_eq!(vote_loader_account.data(), new_vote_loader_account.data());
|
||||
assert_eq!(
|
||||
bank.process_transaction(&transaction),
|
||||
Err(TransactionError::InstructionError(
|
||||
|
@ -9020,11 +9023,11 @@ pub(crate) mod tests {
|
|||
assert_eq!(bank.calculate_capitalization(), bank.capitalization());
|
||||
assert_eq!(
|
||||
"mock_program1",
|
||||
String::from_utf8_lossy(&bank.get_account(&vote_id).unwrap_or_default().data)
|
||||
String::from_utf8_lossy(&bank.get_account(&vote_id).unwrap_or_default().data())
|
||||
);
|
||||
assert_eq!(
|
||||
"mock_program2",
|
||||
String::from_utf8_lossy(&bank.get_account(&stake_id).unwrap_or_default().data)
|
||||
String::from_utf8_lossy(&bank.get_account(&stake_id).unwrap_or_default().data())
|
||||
);
|
||||
|
||||
// Re-adding builtin programs should be no-op
|
||||
|
@ -9040,11 +9043,11 @@ pub(crate) mod tests {
|
|||
assert_eq!(bank.calculate_capitalization(), bank.capitalization());
|
||||
assert_eq!(
|
||||
"mock_program1",
|
||||
String::from_utf8_lossy(&bank.get_account(&vote_id).unwrap_or_default().data)
|
||||
String::from_utf8_lossy(&bank.get_account(&vote_id).unwrap_or_default().data())
|
||||
);
|
||||
assert_eq!(
|
||||
"mock_program2",
|
||||
String::from_utf8_lossy(&bank.get_account(&stake_id).unwrap_or_default().data)
|
||||
String::from_utf8_lossy(&bank.get_account(&stake_id).unwrap_or_default().data())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -10157,7 +10160,7 @@ pub(crate) mod tests {
|
|||
for (key, name) in &program_keys {
|
||||
let account = bank.get_account(key).unwrap();
|
||||
assert!(account.executable);
|
||||
assert_eq!(account.data, *name);
|
||||
assert_eq!(account.data(), name);
|
||||
}
|
||||
info!("result: {:?}", result);
|
||||
let result_key = format!("{:?}", result);
|
||||
|
@ -10762,7 +10765,7 @@ pub(crate) mod tests {
|
|||
let native_mint_account = bank
|
||||
.get_account(&inline_spl_token_v2_0::native_mint::id())
|
||||
.unwrap();
|
||||
assert_eq!(native_mint_account.data.len(), 82);
|
||||
assert_eq!(native_mint_account.data().len(), 82);
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
4200000000
|
||||
|
@ -10787,7 +10790,7 @@ pub(crate) mod tests {
|
|||
let native_mint_account = bank
|
||||
.get_account(&inline_spl_token_v2_0::native_mint::id())
|
||||
.unwrap();
|
||||
assert_eq!(native_mint_account.data.len(), 82);
|
||||
assert_eq!(native_mint_account.data().len(), 82);
|
||||
assert_eq!(
|
||||
bank.get_balance(&inline_spl_token_v2_0::native_mint::id()),
|
||||
4200000000
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
use log::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account_utils::StateMut,
|
||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||
feature_set::{instructions_sysvar_enabled, track_writable_deescalation, FeatureSet},
|
||||
|
@ -121,7 +121,7 @@ impl PreAccount {
|
|||
&& (!is_writable // line coverage used to get branch coverage
|
||||
|| pre.executable
|
||||
|| *program_id != pre.owner
|
||||
|| !Self::is_zeroed(&post.data))
|
||||
|| !Self::is_zeroed(&post.data()))
|
||||
{
|
||||
return Err(InstructionError::ModifiedProgramId);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ impl PreAccount {
|
|||
|
||||
// Only the system program can change the size of the data
|
||||
// and only if the system program owns the account
|
||||
let data_len_changed = pre.data.len() != post.data.len();
|
||||
let data_len_changed = pre.data().len() != post.data().len();
|
||||
if data_len_changed
|
||||
&& (!system_program::check_id(program_id) // line coverage used to get branch coverage
|
||||
|| !system_program::check_id(&pre.owner))
|
||||
|
@ -160,7 +160,7 @@ impl PreAccount {
|
|||
if !(*program_id == pre.owner
|
||||
&& is_writable // line coverage used to get branch coverage
|
||||
&& !pre.executable)
|
||||
&& pre.data != post.data
|
||||
&& pre.data() != post.data()
|
||||
{
|
||||
if pre.executable {
|
||||
return Err(InstructionError::ExecutableDataModified);
|
||||
|
@ -174,7 +174,7 @@ impl PreAccount {
|
|||
// executable is one-way (false->true) and only the account owner may set it.
|
||||
let executable_changed = pre.executable != post.executable;
|
||||
if executable_changed {
|
||||
if !rent.is_exempt(post.lamports, post.data.len()) {
|
||||
if !rent.is_exempt(post.lamports, post.data().len()) {
|
||||
return Err(InstructionError::ExecutableAccountNotRentExempt);
|
||||
}
|
||||
if !is_writable // line coverage used to get branch coverage
|
||||
|
@ -192,7 +192,7 @@ impl PreAccount {
|
|||
}
|
||||
|
||||
timings.total_account_count += 1;
|
||||
timings.total_data_size += post.data.len();
|
||||
timings.total_data_size += post.data().len();
|
||||
if owner_changed
|
||||
|| lamports_changed
|
||||
|| data_len_changed
|
||||
|
@ -201,7 +201,7 @@ impl PreAccount {
|
|||
|| self.changed
|
||||
{
|
||||
timings.changed_account_count += 1;
|
||||
timings.data_size_changed += post.data.len();
|
||||
timings.data_size_changed += post.data().len();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -213,7 +213,7 @@ impl PreAccount {
|
|||
pre.lamports = account.lamports;
|
||||
pre.owner = account.owner;
|
||||
pre.executable = account.executable;
|
||||
if pre.data.len() != account.data.len() {
|
||||
if pre.data().len() != account.data().len() {
|
||||
// Only system account can change data size, copy with alloc
|
||||
pre.data = account.data.clone();
|
||||
} else {
|
||||
|
@ -789,7 +789,8 @@ impl MessageProcessor {
|
|||
if message.is_writable(i) && !account.executable {
|
||||
account_ref.try_account_ref_mut()?.lamports = account.lamports;
|
||||
account_ref.try_account_ref_mut()?.owner = account.owner;
|
||||
if account_ref.data_len()? != account.data.len() && account_ref.data_len()? != 0
|
||||
if account_ref.data_len()? != account.data().len()
|
||||
&& account_ref.data_len()? != 0
|
||||
{
|
||||
// Only support for `CreateAccount` at this time.
|
||||
// Need a way to limit total realloc size across multiple CPI calls
|
||||
|
@ -1193,12 +1194,12 @@ mod tests {
|
|||
invoke_context.pre_accounts[owned_index]
|
||||
.account
|
||||
.borrow()
|
||||
.data[0],
|
||||
.data()[0],
|
||||
(MAX_DEPTH + owned_index) as u8
|
||||
);
|
||||
|
||||
// modify account not owned by the program
|
||||
let data = accounts[not_owned_index].borrow_mut().data[0];
|
||||
let data = accounts[not_owned_index].borrow_mut().data()[0];
|
||||
accounts[not_owned_index].borrow_mut().data[0] = (MAX_DEPTH + not_owned_index) as u8;
|
||||
assert_eq!(
|
||||
invoke_context.verify_and_update(
|
||||
|
@ -1213,7 +1214,7 @@ mod tests {
|
|||
invoke_context.pre_accounts[not_owned_index]
|
||||
.account
|
||||
.borrow()
|
||||
.data[0],
|
||||
.data()[0],
|
||||
data
|
||||
);
|
||||
accounts[not_owned_index].borrow_mut().data[0] = data;
|
||||
|
@ -1956,7 +1957,7 @@ mod tests {
|
|||
assert_eq!(result, Ok(()));
|
||||
assert_eq!(accounts[0].borrow().lamports, 80);
|
||||
assert_eq!(accounts[1].borrow().lamports, 20);
|
||||
assert_eq!(accounts[0].borrow().data, vec![42]);
|
||||
assert_eq!(accounts[0].borrow().data(), &vec![42]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -6,6 +6,7 @@ use libloading::os::windows::*;
|
|||
use log::*;
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
decode_error::DecodeError,
|
||||
entrypoint_native::ProgramEntrypoint,
|
||||
instruction::InstructionError,
|
||||
|
@ -150,8 +151,8 @@ impl NativeLoader {
|
|||
}
|
||||
|
||||
let params = keyed_accounts_iter.as_slice();
|
||||
let name_vec = &program.try_account_ref()?.data;
|
||||
let name = match str::from_utf8(name_vec) {
|
||||
let account = program.try_account_ref()?;
|
||||
let name = match str::from_utf8(account.data()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("Invalid UTF-8 sequence: {}", e);
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
//! calculate and collect rent from Accounts
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData, clock::Epoch, epoch_schedule::EpochSchedule,
|
||||
genesis_config::GenesisConfig, incinerator, pubkey::Pubkey, rent::Rent, sysvar,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Epoch,
|
||||
epoch_schedule::EpochSchedule,
|
||||
genesis_config::GenesisConfig,
|
||||
incinerator,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
sysvar,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)]
|
||||
|
@ -75,7 +81,7 @@ impl RentCollector {
|
|||
|
||||
let (rent_due, exempt) =
|
||||
self.rent
|
||||
.due(account.lamports, account.data.len(), years_elapsed);
|
||||
.due(account.lamports, account.data().len(), years_elapsed);
|
||||
|
||||
if exempt || rent_due != 0 {
|
||||
if account.lamports > rent_due {
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
//! node stakes
|
||||
use crate::vote_account::{ArcVoteAccount, VoteAccounts};
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData, clock::Epoch, pubkey::Pubkey, sysvar::stake_history::StakeHistory,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
clock::Epoch,
|
||||
pubkey::Pubkey,
|
||||
sysvar::stake_history::StakeHistory,
|
||||
};
|
||||
use solana_stake_program::stake_state::{new_stake_history_entry, Delegation, StakeState};
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
|
@ -109,7 +112,7 @@ impl Stakes {
|
|||
pub fn is_stake(account: &AccountSharedData) -> bool {
|
||||
solana_vote_program::check_id(&account.owner)
|
||||
|| solana_stake_program::check_id(&account.owner)
|
||||
&& account.data.len() >= std::mem::size_of::<StakeState>()
|
||||
&& account.data().len() >= std::mem::size_of::<StakeState>()
|
||||
}
|
||||
|
||||
pub fn store(
|
||||
|
@ -127,7 +130,7 @@ impl Stakes {
|
|||
// when account is removed (lamports == 0 or data uninitialized), don't read so that
|
||||
// given `pubkey` can be used for any owner in the future, while not affecting Stakes.
|
||||
if account.lamports != 0
|
||||
&& !(check_vote_init && VoteState::is_uninitialized_no_deser(&account.data))
|
||||
&& !(check_vote_init && VoteState::is_uninitialized_no_deser(&account.data()))
|
||||
{
|
||||
let stake = old.as_ref().map_or_else(
|
||||
|| {
|
||||
|
@ -409,7 +412,7 @@ pub mod tests {
|
|||
}
|
||||
|
||||
// Vote account too big
|
||||
let cache_data = vote_account.data.clone();
|
||||
let cache_data = vote_account.data().to_vec();
|
||||
vote_account.data.push(0);
|
||||
stakes.store(&vote_pubkey, &vote_account, true, true);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use log::*;
|
||||
use solana_sdk::{
|
||||
account::AccountSharedData,
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account_utils::StateMut,
|
||||
ic_msg,
|
||||
instruction::InstructionError,
|
||||
|
@ -79,7 +79,7 @@ fn allocate(
|
|||
|
||||
// if it looks like the `to` account is already in use, bail
|
||||
// (note that the id check is also enforced by message_processor)
|
||||
if !account.data.is_empty() || !system_program::check_id(&account.owner) {
|
||||
if !account.data().is_empty() || !system_program::check_id(&account.owner) {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Allocate: account {:?} already in use",
|
||||
|
@ -423,9 +423,9 @@ pub enum SystemAccountKind {
|
|||
|
||||
pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAccountKind> {
|
||||
if system_program::check_id(&account.owner) {
|
||||
if account.data.is_empty() {
|
||||
if account.data().is_empty() {
|
||||
Some(SystemAccountKind::System)
|
||||
} else if account.data.len() == nonce::State::size() {
|
||||
} else if account.data().len() == nonce::State::size() {
|
||||
match account.state().ok()? {
|
||||
nonce::state::Versions::Current(state) => match *state {
|
||||
nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce),
|
||||
|
@ -530,7 +530,7 @@ mod tests {
|
|||
assert_eq!(from_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().owner, new_owner);
|
||||
assert_eq!(to_account.borrow().data, [0, 0]);
|
||||
assert_eq!(to_account.borrow().data(), &[0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -564,7 +564,7 @@ mod tests {
|
|||
assert_eq!(from_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().owner, new_owner);
|
||||
assert_eq!(to_account.borrow().data, [0, 0]);
|
||||
assert_eq!(to_account.borrow().data(), &[0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -601,7 +601,7 @@ mod tests {
|
|||
assert_eq!(from_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().lamports, 50);
|
||||
assert_eq!(to_account.borrow().owner, new_owner);
|
||||
assert_eq!(to_account.borrow().data, [0, 0]);
|
||||
assert_eq!(to_account.borrow().data(), &[0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -681,11 +681,10 @@ mod tests {
|
|||
let from_lamports = from_account.borrow().lamports;
|
||||
let to_lamports = to_account.borrow().lamports;
|
||||
let to_owner = to_account.borrow().owner;
|
||||
let to_data = &to_account.borrow().data;
|
||||
assert_eq!(from_lamports, 100);
|
||||
assert_eq!(to_lamports, 0);
|
||||
assert_eq!(to_owner, new_owner);
|
||||
assert_eq!(*to_data, [0, 0]);
|
||||
assert_eq!(to_account.borrow().data(), &[0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -752,7 +751,7 @@ mod tests {
|
|||
assert!(result.is_ok());
|
||||
assert_eq!(to_account.borrow().lamports, 50);
|
||||
assert_eq!(
|
||||
to_account.borrow().data.len() as u64,
|
||||
to_account.borrow().data().len() as u64,
|
||||
MAX_PERMITTED_DATA_LENGTH
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
account::{from_account, AccountSharedData},
|
||||
account::{from_account, AccountSharedData, ReadableAccount},
|
||||
account_utils::{State, StateMut},
|
||||
};
|
||||
use solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey, sysvar::Sysvar};
|
||||
|
@ -39,11 +39,11 @@ impl<'a> KeyedAccount<'a> {
|
|||
}
|
||||
|
||||
pub fn data_len(&self) -> Result<usize, InstructionError> {
|
||||
Ok(self.try_borrow()?.data.len())
|
||||
Ok(self.try_borrow()?.data().len())
|
||||
}
|
||||
|
||||
pub fn data_is_empty(&self) -> Result<bool, InstructionError> {
|
||||
Ok(self.try_borrow()?.data.is_empty())
|
||||
Ok(self.try_borrow()?.data().is_empty())
|
||||
}
|
||||
|
||||
pub fn owner(&self) -> Result<Pubkey, InstructionError> {
|
||||
|
|
|
@ -5,7 +5,7 @@ use solana_account_decoder::parse_token::{
|
|||
use solana_runtime::{
|
||||
bank::Bank, transaction_batch::TransactionBatch, transaction_utils::OrderedIterator,
|
||||
};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::{account::ReadableAccount, pubkey::Pubkey};
|
||||
use spl_token_v2_0::{
|
||||
solana_program::program_pack::Pack,
|
||||
state::{Account as TokenAccount, Mint},
|
||||
|
@ -42,7 +42,7 @@ fn get_mint_decimals(bank: &Bank, mint: &Pubkey) -> Option<u8> {
|
|||
} else {
|
||||
let mint_account = bank.get_account(mint)?;
|
||||
|
||||
let decimals = Mint::unpack(&mint_account.data)
|
||||
let decimals = Mint::unpack(&mint_account.data())
|
||||
.map(|mint| mint.decimals)
|
||||
.ok()?;
|
||||
|
||||
|
@ -96,7 +96,7 @@ pub fn collect_token_balance_from_account(
|
|||
) -> Option<(String, UiTokenAmount)> {
|
||||
let account = bank.get_account(account_id)?;
|
||||
|
||||
let token_account = TokenAccount::unpack(&account.data).ok()?;
|
||||
let token_account = TokenAccount::unpack(&account.data()).ok()?;
|
||||
let mint_string = &token_account.mint.to_string();
|
||||
let mint = &Pubkey::from_str(&mint_string).unwrap_or_default();
|
||||
|
||||
|
|
Loading…
Reference in New Issue