From eb8a31ab1a486cd75e5042b815c201c9b147c33a Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 24 Sep 2024 13:01:22 +0400 Subject: [PATCH] extract reward-info crate --- Cargo.lock | 11 ++++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 9 ++++++++ sdk/Cargo.toml | 2 ++ sdk/reward-info/Cargo.toml | 23 ++++++++++++++++++++ sdk/reward-info/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++ sdk/src/lib.rs | 2 ++ sdk/src/reward_info.rs | 14 +----------- sdk/src/reward_type.rs | 28 +----------------------- 9 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 sdk/reward-info/Cargo.toml create mode 100644 sdk/reward-info/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index cd4377a2bdb21b..938a69426109da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7443,6 +7443,16 @@ dependencies = [ "uriparse", ] +[[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" @@ -7770,6 +7780,7 @@ dependencies = [ "solana-logger", "solana-program", "solana-program-memory", + "solana-reward-info", "solana-sanitize", "solana-sdk", "solana-sdk-macro", diff --git a/Cargo.toml b/Cargo.toml index 3f22cf63d50ca6..8f8aa75c0c5f7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,6 +119,7 @@ members = [ "sdk/program-memory", "sdk/program-option", "sdk/pubkey", + "sdk/reward-info", "sdk/serde-varint", "sdk/sha256-hasher", "sdk/signature", @@ -431,6 +432,7 @@ solana-pubsub-client = { path = "pubsub-client", version = "=2.1.0" } 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-reward-info = { path = "sdk/reward-info", version = "=2.1.0" } solana-sanitize = { path = "sanitize", version = "=2.1.0" } solana-serde-varint = { path = "sdk/serde-varint", version = "=2.1.0" } solana-sha256-hasher = { path = "sdk/sha256-hasher", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 05e8a5b9403ad9..281191c20d5474 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5830,6 +5830,14 @@ dependencies = [ "uriparse", ] +[[package]] +name = "solana-reward-info" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-rpc" version = "2.1.0" @@ -6563,6 +6571,7 @@ dependencies = [ "solana-feature-set", "solana-program", "solana-program-memory", + "solana-reward-info", "solana-sanitize", "solana-sdk-macro", "solana-secp256k1-recover", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 8793f1e58bd1ab..1d899e1f50772e 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -41,6 +41,7 @@ frozen-abi = [ "dep:solana-frozen-abi-macro", "solana-feature-set/frozen-abi", "solana-program/frozen-abi", + "solana-reward-info/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi" ] @@ -95,6 +96,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-program = { workspace = true } solana-program-memory = { workspace = true } +solana-reward-info = { workspace = true, features = ["serde"] } solana-sanitize = { workspace = true } solana-sdk-macro = { workspace = true } solana-secp256k1-recover = { 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 07c92473cbb46a..8c960792ec2630 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -92,7 +92,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;