35 lines
993 B
Rust
35 lines
993 B
Rust
#![allow(clippy::arithmetic_side_effects)]
|
|
pub mod system_instruction;
|
|
pub mod system_processor;
|
|
|
|
use solana_sdk::{
|
|
account::{AccountSharedData, ReadableAccount},
|
|
account_utils::StateMut,
|
|
nonce, system_program,
|
|
};
|
|
pub use system_program::id;
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
pub enum SystemAccountKind {
|
|
System,
|
|
Nonce,
|
|
}
|
|
|
|
pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAccountKind> {
|
|
if system_program::check_id(account.owner()) {
|
|
if account.data().is_empty() {
|
|
Some(SystemAccountKind::System)
|
|
} else if account.data().len() == nonce::State::size() {
|
|
let nonce_versions: nonce::state::Versions = account.state().ok()?;
|
|
match nonce_versions.state() {
|
|
nonce::State::Uninitialized => None,
|
|
nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce),
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
}
|