From ccf193e14e3ee1c1d49d3ba37856690250bf4e35 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sun, 29 Sep 2024 17:13:46 +0400 Subject: [PATCH] extract epoch-info crate --- Cargo.lock | 9 ++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 9 ++++++++ sdk/Cargo.toml | 1 + sdk/epoch-info/Cargo.toml | 23 +++++++++++++++++++ .../epoch_info.rs => epoch-info/src/lib.rs} | 14 ++++++----- sdk/src/lib.rs | 3 ++- 7 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 sdk/epoch-info/Cargo.toml rename sdk/{src/epoch_info.rs => epoch-info/src/lib.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index 3c7c3441eca7b4..bf5ec450940c1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6684,6 +6684,14 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-epoch-info" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-epoch-rewards" version = "2.2.0" @@ -8087,6 +8095,7 @@ dependencies = [ "solana-commitment-config", "solana-decode-error", "solana-derivation-path", + "solana-epoch-info", "solana-feature-set", "solana-fee-structure", "solana-frozen-abi", diff --git a/Cargo.toml b/Cargo.toml index ff38eac7b3ac4e..d95f5667a345e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,6 +113,7 @@ members = [ "sdk/cpi", "sdk/decode-error", "sdk/derivation-path", + "sdk/epoch-info", "sdk/epoch-rewards", "sdk/epoch-schedule", "sdk/feature-set", @@ -428,6 +429,7 @@ solana-derivation-path = { path = "sdk/derivation-path", version = "=2.2.0" } solana-download-utils = { path = "download-utils", version = "=2.2.0" } solana-entry = { path = "entry", version = "=2.2.0" } solana-program-entrypoint = { path = "sdk/program-entrypoint", version = "=2.2.0" } +solana-epoch-info = { path = "sdk/epoch-info", version = "=2.2.0" } solana-epoch-rewards = { path = "sdk/epoch-rewards", version = "=2.2.0" } solana-epoch-schedule = { path = "sdk/epoch-schedule", version = "=2.2.0" } solana-faucet = { path = "faucet", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index ee1c9b2fc8ae09..195dc452f359e7 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5323,6 +5323,14 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-epoch-info" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-epoch-rewards" version = "2.2.0" @@ -6836,6 +6844,7 @@ dependencies = [ "solana-commitment-config", "solana-decode-error", "solana-derivation-path", + "solana-epoch-info", "solana-feature-set", "solana-fee-structure", "solana-inflation", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 3d8b1ac1725267..3673e53c99e40b 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -96,6 +96,7 @@ solana-bn254 = { workspace = true } solana-commitment-config = { workspace = true, optional = true, features = ["serde"] } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } +solana-epoch-info = { workspace = true, features = ["serde"] } solana-feature-set = { workspace = true } solana-fee-structure = { workspace = true, features = ["serde"] } solana-frozen-abi = { workspace = true, optional = true, features = [ diff --git a/sdk/epoch-info/Cargo.toml b/sdk/epoch-info/Cargo.toml new file mode 100644 index 00000000000000..4f20c53e43cbd7 --- /dev/null +++ b/sdk/epoch-info/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "solana-epoch-info" +description = "Information about the current Solana epoch." +documentation = "https://docs.rs/solana-epoch-info" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } + +[features] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/src/epoch_info.rs b/sdk/epoch-info/src/lib.rs similarity index 72% rename from sdk/src/epoch_info.rs rename to sdk/epoch-info/src/lib.rs index c324c38d8a1aa7..ccc46ae5e96426 100644 --- a/sdk/src/epoch_info.rs +++ b/sdk/epoch-info/src/lib.rs @@ -4,13 +4,15 @@ //! //! [`getEpochInfo`]: https://solana.com/docs/rpc/http/getepochinfo -use crate::clock::{Epoch, Slot}; - -#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] -#[serde(rename_all = "camelCase")] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize), + serde(rename_all = "camelCase") +)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct EpochInfo { /// The current epoch - pub epoch: Epoch, + pub epoch: u64, /// The current slot, relative to the start of the current epoch pub slot_index: u64, @@ -19,7 +21,7 @@ pub struct EpochInfo { pub slots_in_epoch: u64, /// The absolute current slot - pub absolute_slot: Slot, + pub absolute_slot: u64, /// The current block height pub block_height: u64, diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 4c4ead3010697e..0912da87bce00a 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -66,7 +66,6 @@ pub mod deserialize_utils; pub mod ed25519_instruction; pub mod entrypoint; pub mod entrypoint_deprecated; -pub mod epoch_info; pub mod epoch_rewards_hasher; pub mod example_mocks; pub mod exit; @@ -115,6 +114,8 @@ pub use solana_bn254 as alt_bn128; pub use solana_decode_error as decode_error; #[deprecated(since = "2.1.0", note = "Use `solana-derivation-path` crate instead")] pub use solana_derivation_path as derivation_path; +#[deprecated(since = "2.1.0", note = "Use `solana-epoch-info` crate instead")] +pub use solana_epoch_info as epoch_info; #[deprecated(since = "2.1.0", note = "Use `solana-feature-set` crate instead")] pub use solana_feature_set as feature_set; #[deprecated(since = "2.2.0", note = "Use `solana-fee-structure` crate instead")]