Move KeyedAccount out of solana-program. Native programs are not supported by solana-program
This commit is contained in:
@ -216,7 +216,7 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
|
||||
let keyed_accounts: Vec<_> = keys
|
||||
.iter()
|
||||
.zip(&accounts)
|
||||
.map(|(key, account)| solana_sdk::account::KeyedAccount::new(&key, false, &account))
|
||||
.map(|(key, account)| solana_sdk::keyed_account::KeyedAccount::new(&key, false, &account))
|
||||
.collect();
|
||||
let instruction_data = vec![0u8];
|
||||
|
||||
|
@ -18,12 +18,13 @@ use solana_runtime::{
|
||||
},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
account::Account,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
client::SyncClient,
|
||||
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||
keyed_account::KeyedAccount,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -21,11 +21,11 @@ use solana_runtime::{
|
||||
process_instruction::{ComputeMeter, Executor, InvokeContext},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::{is_executable, next_keyed_account, KeyedAccount},
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
decode_error::DecodeError,
|
||||
entrypoint::SUCCESS,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{is_executable, next_keyed_account, KeyedAccount},
|
||||
loader_instruction::LoaderInstruction,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
||||
use solana_sdk::{
|
||||
account::KeyedAccount, bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE,
|
||||
instruction::InstructionError, pubkey::Pubkey,
|
||||
bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE, instruction::InstructionError,
|
||||
keyed_account::KeyedAccount, pubkey::Pubkey,
|
||||
};
|
||||
use std::{
|
||||
io::prelude::*,
|
||||
|
@ -16,12 +16,12 @@ use solana_runtime::{
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::KeyedAccount,
|
||||
account_info::AccountInfo,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
keyed_account::KeyedAccount,
|
||||
message::Message,
|
||||
program_error::ProgramError,
|
||||
pubkey::{Pubkey, PubkeyError},
|
||||
|
@ -7,9 +7,9 @@ use crate::{
|
||||
use chrono::prelude::{DateTime, Utc};
|
||||
use log::*;
|
||||
use solana_sdk::{
|
||||
account::{next_keyed_account, KeyedAccount},
|
||||
hash::hash,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -3,8 +3,8 @@
|
||||
use crate::ConfigKeys;
|
||||
use bincode::deserialize;
|
||||
use log::*;
|
||||
use solana_sdk::account::{next_keyed_account, KeyedAccount};
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::keyed_account::{next_keyed_account, KeyedAccount};
|
||||
use solana_sdk::program_utils::limited_deserialize;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
@ -107,7 +107,8 @@ mod tests {
|
||||
use bincode::serialized_size;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::{create_keyed_is_signer_accounts, Account},
|
||||
account::Account,
|
||||
keyed_account::create_keyed_is_signer_accounts,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction::SystemInstruction,
|
||||
};
|
||||
|
@ -8,7 +8,7 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use serde_derive::Serialize;
|
||||
use solana_metrics::inc_new_counter_info;
|
||||
use solana_sdk::{
|
||||
account::KeyedAccount, decode_error::DecodeError, instruction::InstructionError,
|
||||
decode_error::DecodeError, instruction::InstructionError, keyed_account::KeyedAccount,
|
||||
program_utils::limited_deserialize, pubkey::Pubkey,
|
||||
};
|
||||
use std::cmp;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::keyed_account::KeyedAccount;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
solana_sdk::declare_program!(
|
||||
|
@ -1,6 +1,6 @@
|
||||
use log::*;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::keyed_account::KeyedAccount;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
solana_sdk::declare_program!(
|
||||
|
@ -3,8 +3,8 @@
|
||||
use crate::ownable_instruction::OwnableError;
|
||||
use bincode::serialize_into;
|
||||
use solana_sdk::{
|
||||
account::{next_keyed_account, KeyedAccount},
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::{
|
||||
account::KeyedAccount,
|
||||
instruction::{Instruction, InstructionError},
|
||||
keyed_account::KeyedAccount,
|
||||
};
|
||||
|
||||
pub fn process_instruction(
|
||||
|
@ -4,9 +4,8 @@ use bincode::{deserialize, serialized_size};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_config_program::{create_config_account, get_config_data, ConfigState};
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
genesis_config::GenesisConfig,
|
||||
instruction::InstructionError,
|
||||
account::Account, genesis_config::GenesisConfig, instruction::InstructionError,
|
||||
keyed_account::KeyedAccount,
|
||||
};
|
||||
|
||||
// stake config ID
|
||||
|
@ -6,14 +6,14 @@ use log::*;
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::{get_signers, next_keyed_account, KeyedAccount},
|
||||
clock::{Epoch, UnixTimestamp},
|
||||
decode_error::DecodeError,
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
keyed_account::{from_keyed_account, get_signers, next_keyed_account, KeyedAccount},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
system_instruction,
|
||||
sysvar::{self, clock::Clock, rent::Rent, stake_history::StakeHistory, Sysvar},
|
||||
sysvar::{self, clock::Clock, rent::Rent, stake_history::StakeHistory},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
@ -459,7 +459,7 @@ pub fn process_instruction(
|
||||
StakeInstruction::Initialize(authorized, lockup) => me.initialize(
|
||||
&authorized,
|
||||
&lockup,
|
||||
&Rent::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Rent>(next_keyed_account(keyed_accounts)?)?,
|
||||
),
|
||||
StakeInstruction::Authorize(authorized_pubkey, stake_authorize) => {
|
||||
me.authorize(&signers, &authorized_pubkey, stake_authorize)
|
||||
@ -479,8 +479,8 @@ pub fn process_instruction(
|
||||
|
||||
me.delegate(
|
||||
&vote,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
&config::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
)
|
||||
@ -493,8 +493,8 @@ pub fn process_instruction(
|
||||
let source_stake = &next_keyed_account(keyed_accounts)?;
|
||||
me.merge(
|
||||
source_stake,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
)
|
||||
}
|
||||
@ -504,14 +504,14 @@ pub fn process_instruction(
|
||||
me.withdraw(
|
||||
lamports,
|
||||
to,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
next_keyed_account(keyed_accounts)?,
|
||||
keyed_accounts.next(),
|
||||
)
|
||||
}
|
||||
StakeInstruction::Deactivate => me.deactivate(
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
),
|
||||
|
||||
@ -523,7 +523,11 @@ pub fn process_instruction(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bincode::serialize;
|
||||
use solana_sdk::{account::Account, rent::Rent, sysvar::stake_history::StakeHistory};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
rent::Rent,
|
||||
sysvar::{stake_history::StakeHistory, Sysvar},
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
fn create_default_account() -> RefCell<Account> {
|
||||
|
@ -10,10 +10,11 @@ use crate::{
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
account::Account,
|
||||
account_utils::{State, StateMut},
|
||||
clock::{Clock, Epoch, UnixTimestamp},
|
||||
instruction::InstructionError,
|
||||
keyed_account::KeyedAccount,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
stake_history::{StakeHistory, StakeHistoryEntry},
|
||||
|
@ -7,8 +7,9 @@ use chrono::prelude::*;
|
||||
use solana_config_program::date_instruction::DateConfig;
|
||||
use solana_config_program::get_config_data;
|
||||
use solana_sdk::{
|
||||
account::{next_keyed_account, Account, KeyedAccount},
|
||||
account::Account,
|
||||
instruction::InstructionError,
|
||||
keyed_account::{next_keyed_account, KeyedAccount},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -10,14 +10,14 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_metrics::inc_new_counter_info;
|
||||
use solana_sdk::{
|
||||
account::{get_signers, next_keyed_account, KeyedAccount},
|
||||
decode_error::DecodeError,
|
||||
hash::Hash,
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
keyed_account::{from_keyed_account, get_signers, next_keyed_account, KeyedAccount},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
system_instruction,
|
||||
sysvar::{self, clock::Clock, slot_hashes::SlotHashes, Sysvar},
|
||||
sysvar::{self, clock::Clock, slot_hashes::SlotHashes},
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use thiserror::Error;
|
||||
@ -261,6 +261,18 @@ pub fn withdraw(
|
||||
Instruction::new(id(), &VoteInstruction::Withdraw(lamports), account_metas)
|
||||
}
|
||||
|
||||
fn verify_rent_exemption(
|
||||
keyed_account: &KeyedAccount,
|
||||
rent_sysvar_account: &KeyedAccount,
|
||||
) -> Result<(), InstructionError> {
|
||||
let rent: sysvar::rent::Rent = from_keyed_account(rent_sysvar_account)?;
|
||||
if !rent.is_exempt(keyed_account.lamports()?, keyed_account.data_len()?) {
|
||||
Err(InstructionError::InsufficientFunds)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
@ -276,12 +288,12 @@ pub fn process_instruction(
|
||||
|
||||
match limited_deserialize(data)? {
|
||||
VoteInstruction::InitializeAccount(vote_init) => {
|
||||
sysvar::rent::verify_rent_exemption(me, next_keyed_account(keyed_accounts)?)?;
|
||||
verify_rent_exemption(me, next_keyed_account(keyed_accounts)?)?;
|
||||
vote_state::initialize_account(
|
||||
me,
|
||||
&vote_init,
|
||||
&signers,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
)
|
||||
}
|
||||
VoteInstruction::Authorize(voter_pubkey, vote_authorize) => vote_state::authorize(
|
||||
@ -289,7 +301,7 @@ pub fn process_instruction(
|
||||
&voter_pubkey,
|
||||
vote_authorize,
|
||||
&signers,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
),
|
||||
VoteInstruction::UpdateValidatorIdentity => vote_state::update_validator_identity(
|
||||
me,
|
||||
@ -303,8 +315,8 @@ pub fn process_instruction(
|
||||
inc_new_counter_info!("vote-native", 1);
|
||||
vote_state::process_vote(
|
||||
me,
|
||||
&SlotHashes::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<SlotHashes>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&vote,
|
||||
&signers,
|
||||
)
|
||||
@ -319,7 +331,7 @@ pub fn process_instruction(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::{account::Account, rent::Rent};
|
||||
use solana_sdk::{account::Account, rent::Rent, sysvar::Sysvar};
|
||||
use std::cell::RefCell;
|
||||
|
||||
// these are for 100% coverage in this file
|
||||
|
@ -6,12 +6,13 @@ use bincode::{deserialize, serialize_into, serialized_size, ErrorKind};
|
||||
use log::*;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
account::Account,
|
||||
account_utils::State,
|
||||
clock::{Epoch, Slot, UnixTimestamp},
|
||||
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
keyed_account::KeyedAccount,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
slot_hashes::SlotHash,
|
||||
@ -759,9 +760,10 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::vote_state;
|
||||
use solana_sdk::{
|
||||
account::{get_signers, next_keyed_account, Account},
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
hash::hash,
|
||||
keyed_account::{get_signers, next_keyed_account},
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
|
Reference in New Issue
Block a user