From 2924c7e360753165cfdc1bceebc26beec3c82b80 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 | 1 + 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, 94 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 2501d6130bd5b6..94fefcf92ee8b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7700,6 +7700,16 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "solana-reward-info" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", +] + [[package]] name = "solana-rpc" version = "2.2.0" @@ -8041,6 +8051,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 ce605a1dc6c5dc..39d947ebcb5a00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -473,6 +473,7 @@ solana-quic-client = { path = "quic-client", version = "=2.2.0" } solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.2.0" } solana-remote-wallet = { path = "remote-wallet", version = "=2.2.0", default-features = false } solana-rent = { path = "sdk/rent", version = "=2.2.0", default-features = false } +solana-reward-info = { path = "sdk/reward-info", version = "=2.2.0" } solana-sanitize = { path = "sdk/sanitize", version = "=2.2.0" } solana-serde-varint = { path = "sdk/serde-varint", version = "=2.2.0" } solana-serialize-utils = { path = "sdk/serialize-utils", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 40107c372d5edf..7b36c6b8c90ea4 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -6040,6 +6040,14 @@ dependencies = [ "solana-sdk-macro", ] +[[package]] +name = "solana-reward-info" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-rpc" version = "2.2.0" @@ -6795,6 +6803,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 59e9cfabbbfe22..0b348c2e401403 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -46,6 +46,7 @@ frozen-abi = [ "solana-account/frozen-abi", "solana-inflation/frozen-abi", "solana-program/frozen-abi", + "solana-reward-info/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi", "solana-transaction-error/frozen-abi" @@ -108,6 +109,7 @@ solana-precompile-error = { workspace = true, optional = true } solana-program = { workspace = true } solana-program-memory = { workspace = true } solana-pubkey = { workspace = true, default-features = false, features = ["std"] } +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 7b5b8e472ea602..5a0842e46f3568 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -88,7 +88,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;