Skip to content

Commit

Permalink
extract nonce-account crate (#4036)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey authored Dec 11, 2024
1 parent 9a35fe7 commit d5218e7
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 18 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ members = [
"sdk/msg",
"sdk/native-token",
"sdk/nonce",
"sdk/nonce-account",
"sdk/offchain-message",
"sdk/package-metadata",
"sdk/package-metadata-macro",
Expand Down Expand Up @@ -513,6 +514,7 @@ solana-native-token = { path = "sdk/native-token", version = "=2.2.0" }
solana-net-utils = { path = "net-utils", version = "=2.2.0" }
solana-nohash-hasher = "0.2.1"
solana-nonce = { path = "sdk/nonce", version = "=2.2.0" }
solana-nonce-account = { path = "sdk/nonce-account", version = "=2.2.0" }
solana-notifier = { path = "notifier", version = "=2.2.0" }
solana-offchain-message = { path = "sdk/offchain-message", version = "=2.2.0" }
solana-package-metadata = { path = "sdk/package-metadata", version = "=2.2.0" }
Expand Down
11 changes: 11 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ solana-keypair = { workspace = true, optional = true, features = [
"seed-derivable",
] }
solana-native-token = { workspace = true }
solana-nonce-account = { workspace = true }
solana-offchain-message = { workspace = true, optional = true, features = ["verify"] }
solana-packet = { workspace = true, features = ["bincode", "serde"] }
solana-poh-config = { workspace = true, features = ["serde"] }
Expand Down
23 changes: 23 additions & 0 deletions sdk/nonce-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "solana-nonce-account"
description = "Solana nonce account utils."
documentation = "https://docs.rs/solana-nonce-account"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
solana-account = { workspace = true, features = ["bincode"] }
solana-hash = { workspace = true }
solana-nonce = { workspace = true, features = ["serde"] }
solana-sdk-ids = { workspace = true }

[dev-dependencies]
solana-fee-calculator = { workspace = true }
solana-pubkey = { workspace = true }
29 changes: 12 additions & 17 deletions sdk/src/nonce_account.rs → sdk/nonce-account/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//! Functions related to nonce accounts.
use {
crate::{
account_utils::StateMut,
hash::Hash,
nonce::{
state::{Data, Versions},
State,
},
solana_account::{state_traits::StateMut, AccountSharedData, ReadableAccount},
solana_hash::Hash,
solana_nonce::{
state::{Data, State},
versions::Versions,
},
solana_account::{AccountSharedData, ReadableAccount},
solana_sdk_ids::system_program,
std::cell::RefCell,
};

Expand All @@ -19,7 +17,7 @@ pub fn create_account(lamports: u64) -> RefCell<AccountSharedData> {
lamports,
&Versions::new(State::Uninitialized),
State::size(),
&crate::system_program::id(),
&system_program::id(),
)
.expect("nonce_account"),
)
Expand All @@ -31,7 +29,7 @@ pub fn verify_nonce_account(
account: &AccountSharedData,
recent_blockhash: &Hash, // Transaction.message.recent_blockhash
) -> Option<Data> {
(account.owner() == &crate::system_program::id())
(account.owner() == &system_program::id())
.then(|| {
StateMut::<Versions>::state(account)
.ok()?
Expand All @@ -52,18 +50,15 @@ pub fn lamports_per_signature_of(account: &AccountSharedData) -> Option<u64> {
mod tests {
use {
super::*,
crate::{
fee_calculator::FeeCalculator,
nonce::state::{Data, DurableNonce},
pubkey::Pubkey,
system_program,
},
solana_fee_calculator::FeeCalculator,
solana_nonce::state::{Data, DurableNonce},
solana_pubkey::Pubkey,
};

#[test]
fn test_verify_bad_account_owner_fails() {
let program_id = Pubkey::new_unique();
assert_ne!(program_id, crate::system_program::id());
assert_ne!(program_id, system_program::id());
let account = AccountSharedData::new_data_with_space(
42,
&Versions::new(State::Uninitialized),
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub mod inner_instruction;
pub mod log;
pub mod native_loader;
pub mod net;
pub mod nonce_account;
pub mod precompiles;
pub mod program_utils;
pub mod pubkey;
Expand Down Expand Up @@ -135,6 +134,8 @@ pub use solana_feature_set as feature_set;
pub use solana_fee_structure as fee;
#[deprecated(since = "2.1.0", note = "Use `solana-inflation` crate instead")]
pub use solana_inflation as inflation;
#[deprecated(since = "2.2.0", note = "Use `solana-nonce-account` crate instead")]
pub use solana_nonce_account as nonce_account;
#[cfg(feature = "full")]
#[deprecated(since = "2.2.0", note = "Use `solana-offchain-message` crate instead")]
pub use solana_offchain_message as offchain_message;
Expand Down
11 changes: 11 additions & 0 deletions svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5218e7

Please sign in to comment.