Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract reward-info crate #2971

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
9 changes: 9 additions & 0 deletions programs/sbf/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 sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 }
Expand Down
23 changes: 23 additions & 0 deletions sdk/reward-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
44 changes: 44 additions & 0 deletions sdk/reward-info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
}
10 changes: 8 additions & 2 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ pub mod quic;
pub mod rent_collector;
pub mod rent_debits;
pub mod reserved_account_keys;
pub mod reward_info;
pub mod reward_type;
#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")]
pub mod reward_info {
pub use solana_reward_info::RewardInfo;
}
#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")]
pub mod reward_type {
pub use solana_reward_info::RewardType;
}
pub mod rpc_port;
pub mod secp256k1_instruction;
pub mod shred_version;
Expand Down
13 changes: 0 additions & 13 deletions sdk/src/reward_info.rs

This file was deleted.

27 changes: 0 additions & 27 deletions sdk/src/reward_type.rs

This file was deleted.

Loading