SDK: Re-org nonce state module to facilitate versioning (#8603)
automerge
This commit is contained in:
@@ -2482,7 +2482,7 @@ mod tests {
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
nonce_state::{Meta as NonceMeta, NonceState},
|
||||
nonce,
|
||||
pubkey::Pubkey,
|
||||
signature::{keypair_from_seed, read_keypair_file, write_keypair_file, Presigner},
|
||||
system_program,
|
||||
@@ -3266,8 +3266,8 @@ mod tests {
|
||||
value: json!(RpcAccount::encode(
|
||||
Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(
|
||||
NonceMeta::new(&config.signers[0].pubkey()),
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&config.signers[0].pubkey()),
|
||||
blockhash
|
||||
),
|
||||
&system_program::ID,
|
||||
@@ -3297,7 +3297,7 @@ mod tests {
|
||||
value: json!(RpcAccount::encode(
|
||||
Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(NonceMeta::new(&bob_pubkey), blockhash),
|
||||
&nonce::State::Initialized(nonce::state::Meta::new(&bob_pubkey), blockhash),
|
||||
&system_program::ID,
|
||||
)
|
||||
.unwrap()
|
||||
|
@@ -14,7 +14,7 @@ use solana_sdk::{
|
||||
account_utils::StateMut,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
nonce_state::{Meta, NonceState},
|
||||
nonce::{self, State},
|
||||
pubkey::Pubkey,
|
||||
system_instruction::{
|
||||
advance_nonce_account, authorize_nonce_account, create_address_with_seed,
|
||||
@@ -363,11 +363,11 @@ pub fn check_nonce_account(
|
||||
if nonce_account.owner != system_program::ID {
|
||||
return Err(CliError::InvalidNonce(CliNonceError::InvalidAccountOwner).into());
|
||||
}
|
||||
let nonce_state: NonceState = nonce_account
|
||||
let nonce_state: State = nonce_account
|
||||
.state()
|
||||
.map_err(|_| Box::new(CliError::InvalidNonce(CliNonceError::InvalidAccountData)))?;
|
||||
match nonce_state {
|
||||
NonceState::Initialized(meta, hash) => {
|
||||
State::Initialized(meta, hash) => {
|
||||
if &hash != nonce_hash {
|
||||
Err(CliError::InvalidNonce(CliNonceError::InvalidHash).into())
|
||||
} else if nonce_authority != &meta.nonce_authority {
|
||||
@@ -376,9 +376,7 @@ pub fn check_nonce_account(
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
NonceState::Uninitialized => {
|
||||
Err(CliError::InvalidNonce(CliNonceError::InvalidState).into())
|
||||
}
|
||||
State::Uninitialized => Err(CliError::InvalidNonce(CliNonceError::InvalidState).into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +427,7 @@ pub fn process_create_nonce_account(
|
||||
|
||||
if let Ok(nonce_account) = rpc_client.get_account(&nonce_account_address) {
|
||||
let err_msg = if nonce_account.owner == system_program::id()
|
||||
&& StateMut::<NonceState>::state(&nonce_account).is_ok()
|
||||
&& StateMut::<State>::state(&nonce_account).is_ok()
|
||||
{
|
||||
format!("Nonce account {} already exists", nonce_account_address)
|
||||
} else {
|
||||
@@ -441,7 +439,7 @@ pub fn process_create_nonce_account(
|
||||
return Err(CliError::BadParameter(err_msg).into());
|
||||
}
|
||||
|
||||
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(NonceState::size())?;
|
||||
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(State::size())?;
|
||||
if lamports < minimum_balance {
|
||||
return Err(CliError::BadParameter(format!(
|
||||
"need at least {} lamports for nonce account to be rent exempt, provided lamports: {}",
|
||||
@@ -496,8 +494,8 @@ pub fn process_get_nonce(rpc_client: &RpcClient, nonce_account_pubkey: &Pubkey)
|
||||
.into());
|
||||
}
|
||||
match nonce_account.state() {
|
||||
Ok(NonceState::Uninitialized) => Ok("Nonce account is uninitialized".to_string()),
|
||||
Ok(NonceState::Initialized(_, hash)) => Ok(format!("{:?}", hash)),
|
||||
Ok(State::Uninitialized) => Ok("Nonce account is uninitialized".to_string()),
|
||||
Ok(State::Initialized(_, hash)) => Ok(format!("{:?}", hash)),
|
||||
Err(err) => Err(CliError::RpcRequestError(format!(
|
||||
"Account data could not be deserialized to nonce state: {:?}",
|
||||
err
|
||||
@@ -554,7 +552,7 @@ pub fn process_show_nonce_account(
|
||||
))
|
||||
.into());
|
||||
}
|
||||
let print_account = |data: Option<(Meta, Hash)>| {
|
||||
let print_account = |data: Option<(nonce::state::Meta, Hash)>| {
|
||||
println!(
|
||||
"Balance: {}",
|
||||
build_balance_message(nonce_account.lamports, use_lamports_unit, true)
|
||||
@@ -562,7 +560,7 @@ pub fn process_show_nonce_account(
|
||||
println!(
|
||||
"Minimum Balance Required: {}",
|
||||
build_balance_message(
|
||||
rpc_client.get_minimum_balance_for_rent_exemption(NonceState::size())?,
|
||||
rpc_client.get_minimum_balance_for_rent_exemption(State::size())?,
|
||||
use_lamports_unit,
|
||||
true
|
||||
)
|
||||
@@ -580,8 +578,8 @@ pub fn process_show_nonce_account(
|
||||
Ok("".to_string())
|
||||
};
|
||||
match nonce_account.state() {
|
||||
Ok(NonceState::Uninitialized) => print_account(None),
|
||||
Ok(NonceState::Initialized(meta, hash)) => print_account(Some((meta, hash))),
|
||||
Ok(State::Uninitialized) => print_account(None),
|
||||
Ok(State::Initialized(meta, hash)) => print_account(Some((meta, hash))),
|
||||
Err(err) => Err(CliError::RpcRequestError(format!(
|
||||
"Account data could not be deserialized to nonce state: {:?}",
|
||||
err
|
||||
@@ -627,7 +625,7 @@ mod tests {
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
hash::hash,
|
||||
nonce_state::{Meta as NonceMeta, NonceState},
|
||||
nonce::{self, State},
|
||||
signature::{read_keypair_file, write_keypair, Keypair, Signer},
|
||||
system_program,
|
||||
};
|
||||
@@ -905,14 +903,14 @@ mod tests {
|
||||
let nonce_pubkey = Pubkey::new_rand();
|
||||
let valid = Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), blockhash),
|
||||
&State::Initialized(nonce::state::Meta::new(&nonce_pubkey), blockhash),
|
||||
&system_program::ID,
|
||||
);
|
||||
assert!(check_nonce_account(&valid.unwrap(), &nonce_pubkey, &blockhash).is_ok());
|
||||
|
||||
let invalid_owner = Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), blockhash),
|
||||
&State::Initialized(nonce::state::Meta::new(&nonce_pubkey), blockhash),
|
||||
&Pubkey::new(&[1u8; 32]),
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -932,7 +930,7 @@ mod tests {
|
||||
|
||||
let invalid_hash = Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(NonceMeta::new(&nonce_pubkey), hash(b"invalid")),
|
||||
&State::Initialized(nonce::state::Meta::new(&nonce_pubkey), hash(b"invalid")),
|
||||
&system_program::ID,
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -942,7 +940,7 @@ mod tests {
|
||||
|
||||
let invalid_authority = Account::new_data(
|
||||
1,
|
||||
&NonceState::Initialized(NonceMeta::new(&Pubkey::new_rand()), blockhash),
|
||||
&State::Initialized(nonce::state::Meta::new(&Pubkey::new_rand()), blockhash),
|
||||
&system_program::ID,
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -952,7 +950,7 @@ mod tests {
|
||||
))),
|
||||
);
|
||||
|
||||
let invalid_state = Account::new_data(1, &NonceState::Uninitialized, &system_program::ID);
|
||||
let invalid_state = Account::new_data(1, &State::Uninitialized, &system_program::ID);
|
||||
assert_eq!(
|
||||
check_nonce_account(&invalid_state.unwrap(), &nonce_pubkey, &blockhash),
|
||||
Err(Box::new(CliError::InvalidNonce(
|
||||
|
Reference in New Issue
Block a user