diff --git a/Cargo.lock b/Cargo.lock index 7492ea20dc02f3..db0ad2dc4e3160 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7565,6 +7565,16 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "solana-reward-info" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", +] + [[package]] name = "solana-rpc" version = "2.1.0" @@ -7900,6 +7910,7 @@ dependencies = [ "solana-program", "solana-program-memory", "solana-pubkey", + "solana-reward-info", "solana-sanitize", "solana-sdk", "solana-sdk-macro", diff --git a/Cargo.toml b/Cargo.toml index cdecc0af7dcfe4..510cee3f9ee6b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -453,6 +453,7 @@ solana-quic-client = { path = "quic-client", version = "=2.1.0" } solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.1.0" } solana-remote-wallet = { path = "remote-wallet", version = "=2.1.0", default-features = false } solana-rent = { path = "sdk/rent", version = "=2.1.0", default-features = false } +solana-reward-info = { path = "sdk/reward-info", version = "=2.1.0" } solana-sanitize = { path = "sdk/sanitize", version = "=2.1.0" } solana-serde-varint = { path = "sdk/serde-varint", version = "=2.1.0" } solana-serialize-utils = { path = "sdk/serialize-utils", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index e16c7d4a3a926c..8470b345fe0396 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5921,6 +5921,14 @@ dependencies = [ "solana-sdk-macro", ] +[[package]] +name = "solana-reward-info" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-rpc" version = "2.1.0" @@ -6661,6 +6669,7 @@ dependencies = [ "solana-program", "solana-program-memory", "solana-pubkey", + "solana-reward-info", "solana-sanitize", "solana-sdk-macro", "solana-secp256k1-recover", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 938e21a2aed8c0..079c2c06a2cbf8 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -43,6 +43,7 @@ frozen-abi = [ "solana-feature-set/frozen-abi", "solana-account/frozen-abi", "solana-program/frozen-abi", + "solana-reward-info/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi" ] @@ -99,7 +100,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ solana-program = { workspace = true } solana-program-memory = { workspace = true } solana-pubkey = { workspace = true, default-features = false, features = ["std"] } -solana-sanitize = { workspace = true } +solana-reward-info = { workspace = true, features = ["serde"] } solana-sdk-macro = { workspace = true } solana-secp256k1-recover = { workspace = true } solana-serde-varint = { workspace = true } diff --git a/sdk/reward-info/Cargo.toml b/sdk/reward-info/Cargo.toml new file mode 100644 index 00000000000000..00ab24b1179b93 --- /dev/null +++ b/sdk/reward-info/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "solana-reward-info" +description = "Solana vote reward info types" +documentation = "https://docs.rs/solana-reward-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 } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/reward-info/src/lib.rs b/sdk/reward-info/src/lib.rs new file mode 100644 index 00000000000000..226237cfbb93e1 --- /dev/null +++ b/sdk/reward-info/src/lib.rs @@ -0,0 +1,44 @@ +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] +#[cfg(feature = "serde")] +use serde_derive::{Deserialize, Serialize}; +#[cfg(feature = "frozen-abi")] +use solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample}; +use std::fmt; + +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub enum RewardType { + Fee, + Rent, + Staking, + Voting, +} + +impl fmt::Display for RewardType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + RewardType::Fee => "fee", + RewardType::Rent => "rent", + RewardType::Staking => "staking", + RewardType::Voting => "voting", + } + ) + } +} + +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub struct RewardInfo { + pub reward_type: RewardType, + /// Reward amount + pub lamports: i64, + /// Account balance in lamports after `lamports` was applied + pub post_balance: u64, + /// Vote account commission when the reward was credited, only present for voting and staking rewards + pub commission: Option, +} diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index ed07e8c7806b57..956efc91cde1a9 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -91,7 +91,9 @@ pub mod quic; pub mod rent_collector; pub mod rent_debits; pub mod reserved_account_keys; +#[deprecated(since = "2.1.0", note = "Use `solana-reward-info` crate instead")] pub mod reward_info; +#[deprecated(since = "2.1.0", note = "Use `solana-reward-info` crate instead")] pub mod reward_type; pub mod rpc_port; pub mod secp256k1_instruction; diff --git a/sdk/src/reward_info.rs b/sdk/src/reward_info.rs index 9153d7032da39e..f8188669d9187a 100644 --- a/sdk/src/reward_info.rs +++ b/sdk/src/reward_info.rs @@ -1,13 +1 @@ -use crate::reward_type::RewardType; - -#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] -pub struct RewardInfo { - pub reward_type: RewardType, - /// Reward amount - pub lamports: i64, - /// Account balance in lamports after `lamports` was applied - pub post_balance: u64, - /// Vote account commission when the reward was credited, only present for voting and staking rewards - pub commission: Option, -} +pub use solana_reward_info::RewardInfo; diff --git a/sdk/src/reward_type.rs b/sdk/src/reward_type.rs index a0765e0b745f02..a51a9287736fd5 100644 --- a/sdk/src/reward_type.rs +++ b/sdk/src/reward_type.rs @@ -1,27 +1 @@ -//! Enumeration of reward types. - -use std::fmt; - -#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] -pub enum RewardType { - Fee, - Rent, - Staking, - Voting, -} - -impl fmt::Display for RewardType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match self { - RewardType::Fee => "fee", - RewardType::Rent => "rent", - RewardType::Staking => "staking", - RewardType::Voting => "voting", - } - ) - } -} +pub use solana_reward_info::RewardType;