More clippy
This commit is contained in:
parent
9fe8c98047
commit
f9f5bc2eb5
|
@ -91,9 +91,10 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
|
||||||
} else {
|
} else {
|
||||||
let default = WalletConfig::default();
|
let default = WalletConfig::default();
|
||||||
if !std::path::Path::new(&default.keypair_path).exists() {
|
if !std::path::Path::new(&default.keypair_path).exists() {
|
||||||
Err(WalletError::KeypairFileNotFound(
|
return Err(WalletError::KeypairFileNotFound(
|
||||||
"Generate a new keypair with `solana-keygen new`".to_string(),
|
"Generate a new keypair with `solana-keygen new`".to_string(),
|
||||||
))?;
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
default.keypair_path
|
default.keypair_path
|
||||||
};
|
};
|
||||||
|
|
|
@ -371,10 +371,11 @@ pub fn process_create_stake_account(
|
||||||
rpc_client.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())?;
|
rpc_client.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())?;
|
||||||
|
|
||||||
if lamports < minimum_balance {
|
if lamports < minimum_balance {
|
||||||
Err(WalletError::BadParameter(format!(
|
return Err(WalletError::BadParameter(format!(
|
||||||
"need atleast {} lamports for stake account to be rent exempt, provided lamports: {}",
|
"need atleast {} lamports for stake account to be rent exempt, provided lamports: {}",
|
||||||
minimum_balance, lamports
|
minimum_balance, lamports
|
||||||
)))?;
|
))
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let ixs = stake_instruction::create_stake_account_with_lockup(
|
let ixs = stake_instruction::create_stake_account_with_lockup(
|
||||||
|
@ -486,9 +487,10 @@ pub fn process_show_stake_account(
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let stake_account = rpc_client.get_account(stake_account_pubkey)?;
|
let stake_account = rpc_client.get_account(stake_account_pubkey)?;
|
||||||
if stake_account.owner != solana_stake_api::id() {
|
if stake_account.owner != solana_stake_api::id() {
|
||||||
Err(WalletError::RpcRequestError(
|
return Err(WalletError::RpcRequestError(
|
||||||
format!("{:?} is not a stake account", stake_account_pubkey).to_string(),
|
format!("{:?} is not a stake account", stake_account_pubkey).to_string(),
|
||||||
))?;
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
fn show_authorized(authorized: &Authorized) {
|
fn show_authorized(authorized: &Authorized) {
|
||||||
println!("authorized staker: {}", authorized.staker);
|
println!("authorized staker: {}", authorized.staker);
|
||||||
|
@ -537,7 +539,8 @@ pub fn process_show_stake_account(
|
||||||
Err(err) => Err(WalletError::RpcRequestError(format!(
|
Err(err) => Err(WalletError::RpcRequestError(format!(
|
||||||
"Account data could not be deserialized to stake state: {:?}",
|
"Account data could not be deserialized to stake state: {:?}",
|
||||||
err
|
err
|
||||||
)))?,
|
))
|
||||||
|
.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,13 +92,14 @@ fn verify_keybase(
|
||||||
if client.head(&url).send()?.status().is_success() {
|
if client.head(&url).send()?.status().is_success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url))?
|
Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url).into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"keybase_username could not be parsed as String: {}",
|
"keybase_username could not be parsed as String: {}",
|
||||||
keybase_username
|
keybase_username
|
||||||
))?
|
)
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +137,8 @@ fn parse_validator_info(
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"account {} found, but could not be parsed as ValidatorInfo",
|
"account {} found, but could not be parsed as ValidatorInfo",
|
||||||
pubkey
|
pubkey
|
||||||
))?
|
)
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,10 @@ pub fn process_show_vote_account(
|
||||||
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
|
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
|
||||||
|
|
||||||
if vote_account.owner != solana_vote_api::id() {
|
if vote_account.owner != solana_vote_api::id() {
|
||||||
Err(WalletError::RpcRequestError(
|
return Err(WalletError::RpcRequestError(
|
||||||
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
|
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
|
||||||
))?;
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
|
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
|
||||||
|
@ -218,9 +219,10 @@ pub fn process_uptime(
|
||||||
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
|
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
|
||||||
|
|
||||||
if vote_account.owner != solana_vote_api::id() {
|
if vote_account.owner != solana_vote_api::id() {
|
||||||
Err(WalletError::RpcRequestError(
|
return Err(WalletError::RpcRequestError(
|
||||||
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
|
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
|
||||||
))?;
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
|
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
|
||||||
|
|
|
@ -423,7 +423,7 @@ fn check_account_for_multiple_fees(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(WalletError::InsufficientFundsForFee)?
|
Err(WalletError::InsufficientFundsForFee.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_unique_pubkeys(
|
pub fn check_unique_pubkeys(
|
||||||
|
@ -462,9 +462,12 @@ fn process_airdrop(
|
||||||
);
|
);
|
||||||
let previous_balance = match rpc_client.retry_get_balance(&config.keypair.pubkey(), 5)? {
|
let previous_balance = match rpc_client.retry_get_balance(&config.keypair.pubkey(), 5)? {
|
||||||
Some(lamports) => lamports,
|
Some(lamports) => lamports,
|
||||||
None => Err(WalletError::RpcRequestError(
|
None => {
|
||||||
"Received result of an unexpected type".to_string(),
|
return Err(WalletError::RpcRequestError(
|
||||||
))?,
|
"Received result of an unexpected type".to_string(),
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, drone_addr, &config.keypair.pubkey(), lamports)?;
|
request_and_confirm_airdrop(&rpc_client, drone_addr, &config.keypair.pubkey(), lamports)?;
|
||||||
|
@ -486,7 +489,8 @@ fn process_balance(
|
||||||
Some(lamports) => Ok(build_balance_message(lamports, use_lamports_unit)),
|
Some(lamports) => Ok(build_balance_message(lamports, use_lamports_unit)),
|
||||||
None => Err(WalletError::RpcRequestError(
|
None => Err(WalletError::RpcRequestError(
|
||||||
"Received result of an unexpected type".to_string(),
|
"Received result of an unexpected type".to_string(),
|
||||||
))?,
|
)
|
||||||
|
.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,10 +506,9 @@ fn process_confirm(rpc_client: &RpcClient, signature: &Signature) -> ProcessResu
|
||||||
Ok("Not found".to_string())
|
Ok("Not found".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(WalletError::RpcRequestError(format!(
|
Err(err) => {
|
||||||
"Unable to confirm: {:?}",
|
Err(WalletError::RpcRequestError(format!("Unable to confirm: {:?}", err)).into())
|
||||||
err
|
}
|
||||||
)))?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,9 +622,10 @@ fn process_show_storage_account(
|
||||||
let account = rpc_client.get_account(storage_account_pubkey)?;
|
let account = rpc_client.get_account(storage_account_pubkey)?;
|
||||||
|
|
||||||
if account.owner != solana_storage_api::id() {
|
if account.owner != solana_storage_api::id() {
|
||||||
Err(WalletError::RpcRequestError(
|
return Err(WalletError::RpcRequestError(
|
||||||
format!("{:?} is not a storage account", storage_account_pubkey).to_string(),
|
format!("{:?} is not a storage account", storage_account_pubkey).to_string(),
|
||||||
))?;
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
use solana_storage_api::storage_contract::StorageContract;
|
use solana_storage_api::storage_contract::StorageContract;
|
||||||
|
@ -771,9 +775,10 @@ fn process_pay(
|
||||||
let witness = if let Some(ref witness_vec) = *witnesses {
|
let witness = if let Some(ref witness_vec) = *witnesses {
|
||||||
witness_vec[0]
|
witness_vec[0]
|
||||||
} else {
|
} else {
|
||||||
Err(WalletError::BadParameter(
|
return Err(WalletError::BadParameter(
|
||||||
"Could not parse required signature pubkey(s)".to_string(),
|
"Could not parse required signature pubkey(s)".to_string(),
|
||||||
))?
|
)
|
||||||
|
.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
let contract_state = Keypair::new();
|
let contract_state = Keypair::new();
|
||||||
|
@ -1361,22 +1366,22 @@ pub fn log_instruction_custom_error<E>(result: Result<String, ClientError>) -> P
|
||||||
where
|
where
|
||||||
E: 'static + std::error::Error + DecodeError<E> + FromPrimitive,
|
E: 'static + std::error::Error + DecodeError<E> + FromPrimitive,
|
||||||
{
|
{
|
||||||
if result.is_err() {
|
match result {
|
||||||
let err = result.unwrap_err();
|
Err(err) => {
|
||||||
if let ClientError::TransactionError(TransactionError::InstructionError(
|
if let ClientError::TransactionError(TransactionError::InstructionError(
|
||||||
_,
|
_,
|
||||||
InstructionError::CustomError(code),
|
InstructionError::CustomError(code),
|
||||||
)) = err
|
)) = err
|
||||||
{
|
{
|
||||||
if let Some(specific_error) = E::decode_custom_error_to_enum(code) {
|
if let Some(specific_error) = E::decode_custom_error_to_enum(code) {
|
||||||
error!("{}::{:?}", E::type_of(), specific_error);
|
error!("{}::{:?}", E::type_of(), specific_error);
|
||||||
Err(specific_error)?
|
return Err(specific_error.into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
error!("{:?}", err);
|
||||||
|
Err(err.into())
|
||||||
}
|
}
|
||||||
error!("{:?}", err);
|
Ok(sig) => Ok(sig),
|
||||||
Err(err)?
|
|
||||||
} else {
|
|
||||||
Ok(result.unwrap())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ impl Blocktree {
|
||||||
"Error: {:?} while submitting write batch for slot {:?} retrying...",
|
"Error: {:?} while submitting write batch for slot {:?} retrying...",
|
||||||
e, from_slot
|
e, from_slot
|
||||||
);
|
);
|
||||||
Err(e)?;
|
return Err(e);
|
||||||
}
|
}
|
||||||
Ok(end)
|
Ok(end)
|
||||||
}
|
}
|
||||||
|
|
|
@ -809,7 +809,7 @@ impl ClusterInfo {
|
||||||
// by a valid tvu port location
|
// by a valid tvu port location
|
||||||
let valid: Vec<_> = self.repair_peers();
|
let valid: Vec<_> = self.repair_peers();
|
||||||
if valid.is_empty() {
|
if valid.is_empty() {
|
||||||
Err(ClusterInfoError::NoPeers)?;
|
return Err(ClusterInfoError::NoPeers.into());
|
||||||
}
|
}
|
||||||
let n = thread_rng().gen::<usize>() % valid.len();
|
let n = thread_rng().gen::<usize>() % valid.len();
|
||||||
let addr = valid[n].gossip; // send the request to the peer's gossip port
|
let addr = valid[n].gossip; // send the request to the peer's gossip port
|
||||||
|
|
|
@ -605,7 +605,7 @@ impl Blob {
|
||||||
"error sending {} byte packet to {:?}: {:?}",
|
"error sending {} byte packet to {:?}: {:?}",
|
||||||
p.meta.size, a, e
|
p.meta.size, a, e
|
||||||
);
|
);
|
||||||
Err(e)?;
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,7 +448,7 @@ impl ReplayStage {
|
||||||
trace!("new root {}", new_root);
|
trace!("new root {}", new_root);
|
||||||
if let Err(e) = root_bank_sender.send(rooted_banks) {
|
if let Err(e) = root_bank_sender.send(rooted_banks) {
|
||||||
trace!("root_bank_sender failed: {:?}", e);
|
trace!("root_bank_sender failed: {:?}", e);
|
||||||
Err(e)?;
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::update_confidence_cache(bank.clone(), total_staked, lockouts_sender);
|
Self::update_confidence_cache(bank.clone(), total_staked, lockouts_sender);
|
||||||
|
|
|
@ -582,10 +582,9 @@ impl Replicator {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// make sure replicator has some balance
|
// make sure replicator has some balance
|
||||||
if client.poll_get_balance(&keypair.pubkey())? == 0 {
|
if client.poll_get_balance(&keypair.pubkey())? == 0 {
|
||||||
Err(io::Error::new(
|
return Err(
|
||||||
io::ErrorKind::Other,
|
io::Error::new(io::ErrorKind::Other, "keypair account has no balance").into(),
|
||||||
"keypair account has no balance",
|
);
|
||||||
))?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the storage account exists
|
// check if the storage account exists
|
||||||
|
@ -705,10 +704,7 @@ impl Replicator {
|
||||||
.as_u64()
|
.as_u64()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
} else {
|
} else {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(io::ErrorKind::Other, "No RPC peers...".to_string()).into())
|
||||||
io::ErrorKind::Other,
|
|
||||||
"No RPC peers...".to_string(),
|
|
||||||
))?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -889,10 +885,9 @@ impl Replicator {
|
||||||
|
|
||||||
// check if all the slots in the segment are complete
|
// check if all the slots in the segment are complete
|
||||||
if !Self::segment_complete(start_slot, slots_per_segment, blocktree) {
|
if !Self::segment_complete(start_slot, slots_per_segment, blocktree) {
|
||||||
Err(io::Error::new(
|
return Err(
|
||||||
ErrorKind::Other,
|
io::Error::new(ErrorKind::Other, "Unable to download the full segment").into(),
|
||||||
"Unable to download the full segment",
|
);
|
||||||
))?
|
|
||||||
}
|
}
|
||||||
Ok(start_slot)
|
Ok(start_slot)
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,7 +572,7 @@ impl Shredder {
|
||||||
shred_bufs.append(&mut pending_shreds);
|
shred_bufs.append(&mut pending_shreds);
|
||||||
|
|
||||||
if shred_bufs.len() != fec_set_size {
|
if shred_bufs.len() != fec_set_size {
|
||||||
Err(reed_solomon_erasure::Error::TooFewShardsPresent)?;
|
return Err(reed_solomon_erasure::Error::TooFewShardsPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
let session = Session::new(num_data, num_coding).unwrap();
|
let session = Session::new(num_data, num_coding).unwrap();
|
||||||
|
@ -623,7 +623,7 @@ impl Shredder {
|
||||||
};
|
};
|
||||||
|
|
||||||
if num_data.saturating_add(first_index) != last_index.saturating_add(1) {
|
if num_data.saturating_add(first_index) != last_index.saturating_add(1) {
|
||||||
Err(reed_solomon_erasure::Error::TooFewDataShards)?;
|
return Err(reed_solomon_erasure::Error::TooFewDataShards);
|
||||||
}
|
}
|
||||||
|
|
||||||
shreds.iter().map(|shred| &shred.payload).collect()
|
shreds.iter().map(|shred| &shred.payload).collect()
|
||||||
|
|
|
@ -432,7 +432,7 @@ impl StorageStage {
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("error encrypting file: {:?}", e);
|
info!("error encrypting file: {:?}", e);
|
||||||
Err(e)?;
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,11 +158,11 @@ impl Tvu {
|
||||||
fork_confidence_cache,
|
fork_confidence_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
let blockstream_service = if blockstream_unix_socket.is_some() {
|
let blockstream_service = if let Some(blockstream_unix_socket) = blockstream_unix_socket {
|
||||||
let blockstream_service = BlockstreamService::new(
|
let blockstream_service = BlockstreamService::new(
|
||||||
blockstream_slot_receiver,
|
blockstream_slot_receiver,
|
||||||
blocktree.clone(),
|
blocktree.clone(),
|
||||||
blockstream_unix_socket.unwrap(),
|
blockstream_unix_socket,
|
||||||
&exit,
|
&exit,
|
||||||
);
|
);
|
||||||
Some(blockstream_service)
|
Some(blockstream_service)
|
||||||
|
|
|
@ -528,8 +528,8 @@ pub fn new_banks_from_blocktree(
|
||||||
dev_halt_at_slot,
|
dev_halt_at_slot,
|
||||||
);
|
);
|
||||||
|
|
||||||
if snapshot_config.is_some() {
|
if let Some(snapshot_config) = snapshot_config {
|
||||||
bank_forks.set_snapshot_config(snapshot_config.unwrap());
|
bank_forks.set_snapshot_config(snapshot_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -77,8 +77,7 @@ fn recv_window<F>(
|
||||||
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
F: Fn(&Shred, u64) -> bool,
|
F: Fn(&Shred, u64) -> bool + Sync,
|
||||||
F: Sync,
|
|
||||||
{
|
{
|
||||||
let timer = Duration::from_millis(200);
|
let timer = Duration::from_millis(200);
|
||||||
let mut packets = r.recv_timeout(timer)?;
|
let mut packets = r.recv_timeout(timer)?;
|
||||||
|
|
|
@ -173,12 +173,14 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if num_nodes_exactly.is_some() && nodes.len() > num_nodes_exactly.unwrap() {
|
if let Some(num_nodes_exactly) = num_nodes_exactly {
|
||||||
eprintln!(
|
if nodes.len() > num_nodes_exactly {
|
||||||
"Error: Extra nodes discovered. Expecting exactly {}",
|
eprintln!(
|
||||||
num_nodes_exactly.unwrap()
|
"Error: Extra nodes discovered. Expecting exactly {}",
|
||||||
);
|
num_nodes_exactly
|
||||||
exit(1);
|
);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
("get-rpc-url", Some(matches)) => {
|
("get-rpc-url", Some(matches)) => {
|
||||||
|
|
|
@ -273,7 +273,7 @@ pub fn process_instruction(
|
||||||
trace!("keyed_accounts: {:?}", keyed_accounts);
|
trace!("keyed_accounts: {:?}", keyed_accounts);
|
||||||
|
|
||||||
if keyed_accounts.is_empty() {
|
if keyed_accounts.is_empty() {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (me, rest) = &mut keyed_accounts.split_at_mut(1);
|
let (me, rest) = &mut keyed_accounts.split_at_mut(1);
|
||||||
|
@ -287,7 +287,7 @@ pub fn process_instruction(
|
||||||
}
|
}
|
||||||
StakeInstruction::DelegateStake => {
|
StakeInstruction::DelegateStake => {
|
||||||
if rest.len() < 3 {
|
if rest.len() < 3 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
let vote = &rest[0];
|
let vote = &rest[0];
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ pub fn process_instruction(
|
||||||
}
|
}
|
||||||
StakeInstruction::RedeemVoteCredits => {
|
StakeInstruction::RedeemVoteCredits => {
|
||||||
if rest.len() != 4 {
|
if rest.len() != 4 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
let (vote, rest) = rest.split_at_mut(1);
|
let (vote, rest) = rest.split_at_mut(1);
|
||||||
let vote = &mut vote[0];
|
let vote = &mut vote[0];
|
||||||
|
@ -316,7 +316,7 @@ pub fn process_instruction(
|
||||||
}
|
}
|
||||||
StakeInstruction::Withdraw(lamports) => {
|
StakeInstruction::Withdraw(lamports) => {
|
||||||
if rest.len() < 3 {
|
if rest.len() < 3 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
let (to, rest) = &mut rest.split_at_mut(1);
|
let (to, rest) = &mut rest.split_at_mut(1);
|
||||||
let mut to = &mut to[0];
|
let mut to = &mut to[0];
|
||||||
|
@ -331,7 +331,7 @@ pub fn process_instruction(
|
||||||
}
|
}
|
||||||
StakeInstruction::Deactivate => {
|
StakeInstruction::Deactivate => {
|
||||||
if rest.len() < 2 {
|
if rest.len() < 2 {
|
||||||
Err(InstructionError::InvalidInstructionData)?;
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
let (vote, rest) = rest.split_at_mut(1);
|
let (vote, rest) = rest.split_at_mut(1);
|
||||||
let vote = &mut vote[0];
|
let vote = &mut vote[0];
|
||||||
|
|
|
@ -614,7 +614,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if lockup.slot > clock.slot && lockup.custodian != *to.unsigned_key() {
|
if lockup.slot > clock.slot && lockup.custodian != *to.unsigned_key() {
|
||||||
return Err(StakeError::LockupInForce)?;
|
return Err(StakeError::LockupInForce.into());
|
||||||
}
|
}
|
||||||
if lamports > self.account.lamports {
|
if lamports > self.account.lamports {
|
||||||
return Err(InstructionError::InsufficientFunds);
|
return Err(InstructionError::InsufficientFunds);
|
||||||
|
|
|
@ -277,8 +277,7 @@ impl Accounts {
|
||||||
/// returns only the latest/current version of B for this fork
|
/// returns only the latest/current version of B for this fork
|
||||||
fn scan_fork<F, B>(&self, fork: Fork, func: F) -> Vec<B>
|
fn scan_fork<F, B>(&self, fork: Fork, func: F) -> Vec<B>
|
||||||
where
|
where
|
||||||
F: Fn(&StoredAccount) -> Option<B>,
|
F: Fn(&StoredAccount) -> Option<B> + Send + Sync,
|
||||||
F: Send + Sync,
|
|
||||||
B: Send + Default,
|
B: Send + Default,
|
||||||
{
|
{
|
||||||
let accumulator: Vec<Vec<(Pubkey, u64, B)>> = self.accounts_db.scan_account_storage(
|
let accumulator: Vec<Vec<(Pubkey, u64, B)>> = self.accounts_db.scan_account_storage(
|
||||||
|
|
|
@ -593,8 +593,7 @@ impl AccountsDB {
|
||||||
// PERF: Sequentially read each storage entry in parallel
|
// PERF: Sequentially read each storage entry in parallel
|
||||||
pub fn scan_account_storage<F, B>(&self, fork_id: Fork, scan_func: F) -> Vec<B>
|
pub fn scan_account_storage<F, B>(&self, fork_id: Fork, scan_func: F) -> Vec<B>
|
||||||
where
|
where
|
||||||
F: Fn(&StoredAccount, AppendVecId, &mut B) -> (),
|
F: Fn(&StoredAccount, AppendVecId, &mut B) -> () + Send + Sync,
|
||||||
F: Send + Sync,
|
|
||||||
B: Send + Default,
|
B: Send + Default,
|
||||||
{
|
{
|
||||||
let storage_maps: Vec<Arc<AccountStorageEntry>> = self
|
let storage_maps: Vec<Arc<AccountStorageEntry>> = self
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn create_system_account(
|
||||||
"CreateAccount: invalid account[from] owner {} ",
|
"CreateAccount: invalid account[from] owner {} ",
|
||||||
&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner
|
&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner
|
||||||
);
|
);
|
||||||
Err(SystemError::SourceNotSystemAccount)?;
|
return Err(SystemError::SourceNotSystemAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !keyed_accounts[TO_ACCOUNT_INDEX].account.data.is_empty()
|
if !keyed_accounts[TO_ACCOUNT_INDEX].account.data.is_empty()
|
||||||
|
@ -30,7 +30,7 @@ fn create_system_account(
|
||||||
"CreateAccount: invalid argument; account {} already in use",
|
"CreateAccount: invalid argument; account {} already in use",
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()
|
keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()
|
||||||
);
|
);
|
||||||
Err(SystemError::AccountAlreadyInUse)?;
|
return Err(SystemError::AccountAlreadyInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if sysvar::check_id(&program_id) {
|
if sysvar::check_id(&program_id) {
|
||||||
|
@ -38,7 +38,7 @@ fn create_system_account(
|
||||||
"CreateAccount: invalid argument; program id {} invalid",
|
"CreateAccount: invalid argument; program id {} invalid",
|
||||||
program_id
|
program_id
|
||||||
);
|
);
|
||||||
Err(SystemError::InvalidProgramId)?;
|
return Err(SystemError::InvalidProgramId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if sysvar::is_sysvar_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) {
|
if sysvar::is_sysvar_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) {
|
||||||
|
@ -46,7 +46,7 @@ fn create_system_account(
|
||||||
"CreateAccount: invalid argument; account id {} invalid",
|
"CreateAccount: invalid argument; account id {} invalid",
|
||||||
program_id
|
program_id
|
||||||
);
|
);
|
||||||
Err(SystemError::InvalidAccountId)?;
|
return Err(SystemError::InvalidAccountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports {
|
if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports {
|
||||||
|
@ -54,7 +54,7 @@ fn create_system_account(
|
||||||
"CreateAccount: insufficient lamports ({}, need {})",
|
"CreateAccount: insufficient lamports ({}, need {})",
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
|
||||||
);
|
);
|
||||||
Err(SystemError::ResultWithNegativeLamports)?;
|
return Err(SystemError::ResultWithNegativeLamports);
|
||||||
}
|
}
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
||||||
|
@ -80,7 +80,7 @@ fn transfer_lamports(
|
||||||
"Transfer: insufficient lamports ({}, need {})",
|
"Transfer: insufficient lamports ({}, need {})",
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
|
||||||
);
|
);
|
||||||
Err(SystemError::ResultWithNegativeLamports)?;
|
return Err(SystemError::ResultWithNegativeLamports);
|
||||||
}
|
}
|
||||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
||||||
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
||||||
|
@ -99,7 +99,7 @@ pub fn process_instruction(
|
||||||
// All system instructions require that accounts_keys[0] be a signer
|
// All system instructions require that accounts_keys[0] be a signer
|
||||||
if keyed_accounts[FROM_ACCOUNT_INDEX].signer_key().is_none() {
|
if keyed_accounts[FROM_ACCOUNT_INDEX].signer_key().is_none() {
|
||||||
debug!("account[from] is unsigned");
|
debug!("account[from] is unsigned");
|
||||||
Err(InstructionError::MissingRequiredSignature)?;
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
match instruction {
|
match instruction {
|
||||||
|
@ -110,7 +110,7 @@ pub fn process_instruction(
|
||||||
} => create_system_account(keyed_accounts, lamports, space, &program_id),
|
} => create_system_account(keyed_accounts, lamports, space, &program_id),
|
||||||
SystemInstruction::Assign { program_id } => {
|
SystemInstruction::Assign { program_id } => {
|
||||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||||
Err(InstructionError::IncorrectProgramId)?;
|
return Err(InstructionError::IncorrectProgramId);
|
||||||
}
|
}
|
||||||
assign_account_to_program(keyed_accounts, &program_id)
|
assign_account_to_program(keyed_accounts, &program_id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue