2021-03-26 20:26:06 -07:00
|
|
|
use {
|
|
|
|
crate::client_error,
|
2022-05-11 21:17:21 -07:00
|
|
|
serde::{Deserialize, Deserializer, Serialize, Serializer},
|
2021-03-26 20:26:06 -07:00
|
|
|
solana_account_decoder::{parse_token::UiTokenAmount, UiAccount},
|
|
|
|
solana_sdk::{
|
|
|
|
clock::{Epoch, Slot, UnixTimestamp},
|
|
|
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
2021-07-12 18:41:27 -07:00
|
|
|
hash::Hash,
|
2021-03-26 20:26:06 -07:00
|
|
|
inflation::Inflation,
|
|
|
|
transaction::{Result, TransactionError},
|
|
|
|
},
|
2021-03-31 21:35:57 -07:00
|
|
|
solana_transaction_status::{
|
2021-12-17 15:03:09 -08:00
|
|
|
ConfirmedTransactionStatusWithSignature, TransactionConfirmationStatus, UiConfirmedBlock,
|
2022-09-08 14:10:57 -07:00
|
|
|
UiTransactionReturnData,
|
2021-03-31 21:35:57 -07:00
|
|
|
},
|
2022-05-11 21:17:21 -07:00
|
|
|
std::{collections::HashMap, fmt, net::SocketAddr, str::FromStr},
|
2021-12-17 15:03:09 -08:00
|
|
|
thiserror::Error,
|
2020-01-14 23:25:45 -08:00
|
|
|
};
|
|
|
|
|
2022-11-16 13:35:35 -08:00
|
|
|
/// Wrapper for rpc return types of methods that provide responses both with and without context.
|
|
|
|
/// Main purpose of this is to fix methods that lack context information in their return type,
|
|
|
|
/// without breaking backwards compatibility.
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum OptionalContext<T> {
|
|
|
|
Context(Response<T>),
|
|
|
|
NoContext(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> OptionalContext<T> {
|
|
|
|
pub fn parse_value(self) -> T {
|
|
|
|
match self {
|
|
|
|
Self::Context(response) => response.value,
|
|
|
|
Self::NoContext(value) => value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-12 23:20:49 -07:00
|
|
|
pub type RpcResult<T> = client_error::Result<Response<T>>;
|
2020-01-14 23:25:45 -08:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2022-05-11 21:17:21 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-01-14 23:25:45 -08:00
|
|
|
pub struct RpcResponseContext {
|
2022-05-11 21:17:21 -07:00
|
|
|
pub slot: Slot,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub api_version: Option<RpcApiVersion>,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2022-05-11 21:17:21 -07:00
|
|
|
pub struct RpcApiVersion(semver::Version);
|
|
|
|
|
|
|
|
impl std::ops::Deref for RpcApiVersion {
|
|
|
|
type Target = semver::Version;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RpcApiVersion {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self(solana_version::Version::default().as_semver_version())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Serialize for RpcApiVersion {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
serializer.serialize_str(&self.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'de> Deserialize<'de> for RpcApiVersion {
|
|
|
|
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
|
|
|
let s: String = Deserialize::deserialize(deserializer)?;
|
|
|
|
Ok(RpcApiVersion(
|
|
|
|
semver::Version::from_str(&s).map_err(serde::de::Error::custom)?,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RpcResponseContext {
|
|
|
|
pub fn new(slot: Slot) -> Self {
|
|
|
|
Self {
|
|
|
|
slot,
|
|
|
|
api_version: Some(RpcApiVersion::default()),
|
|
|
|
}
|
|
|
|
}
|
2020-01-14 23:25:45 -08:00
|
|
|
}
|
|
|
|
|
2022-06-21 13:26:51 -07:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2020-01-14 23:25:45 -08:00
|
|
|
pub struct Response<T> {
|
|
|
|
pub context: RpcResponseContext,
|
|
|
|
pub value: T,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockCommitment<T> {
|
|
|
|
pub commitment: Option<T>,
|
|
|
|
pub total_stake: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockhashFeeCalculator {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2021-08-13 09:08:20 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockhash {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub last_valid_block_height: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-05-26 12:06:21 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcFees {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
pub last_valid_slot: Slot,
|
2021-05-26 00:26:19 -07:00
|
|
|
pub last_valid_block_height: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2021-05-26 00:26:19 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct DeprecatedRpcFees {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
pub last_valid_slot: Slot,
|
2020-05-26 12:06:21 -07:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2021-07-12 18:41:27 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Fees {
|
|
|
|
pub blockhash: Hash,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
pub last_valid_block_height: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-03-06 16:01:31 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcFeeCalculator {
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-02-28 12:27:01 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcFeeRateGovernor {
|
|
|
|
pub fee_rate_governor: FeeRateGovernor,
|
|
|
|
}
|
|
|
|
|
2020-05-29 11:50:25 -07:00
|
|
|
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcInflationGovernor {
|
|
|
|
pub initial: f64,
|
|
|
|
pub terminal: f64,
|
|
|
|
pub taper: f64,
|
|
|
|
pub foundation: f64,
|
|
|
|
pub foundation_term: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Inflation> for RpcInflationGovernor {
|
|
|
|
fn from(inflation: Inflation) -> Self {
|
|
|
|
Self {
|
|
|
|
initial: inflation.initial,
|
|
|
|
terminal: inflation.terminal,
|
|
|
|
taper: inflation.taper,
|
|
|
|
foundation: inflation.foundation,
|
|
|
|
foundation_term: inflation.foundation_term,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcInflationRate {
|
|
|
|
pub total: f64,
|
|
|
|
pub validator: f64,
|
|
|
|
pub foundation: f64,
|
|
|
|
pub epoch: Epoch,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcKeyedAccount {
|
|
|
|
pub pubkey: String,
|
2020-06-30 21:55:11 -07:00
|
|
|
pub account: UiAccount,
|
2020-01-15 14:33:53 -08:00
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
2020-09-03 17:14:45 -07:00
|
|
|
pub struct SlotInfo {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub parent: Slot,
|
|
|
|
pub root: Slot,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
2021-03-12 05:44:06 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct SlotTransactionStats {
|
|
|
|
pub num_transaction_entries: u64,
|
|
|
|
pub num_successful_transactions: u64,
|
|
|
|
pub num_failed_transactions: u64,
|
|
|
|
pub max_transactions_per_entry: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
2021-02-28 23:29:11 -08:00
|
|
|
#[serde(rename_all = "camelCase", tag = "type")]
|
|
|
|
pub enum SlotUpdate {
|
2021-03-12 05:44:06 -08:00
|
|
|
FirstShredReceived {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
},
|
|
|
|
Completed {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
},
|
|
|
|
CreatedBank {
|
|
|
|
slot: Slot,
|
|
|
|
parent: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
},
|
|
|
|
Frozen {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
stats: SlotTransactionStats,
|
|
|
|
},
|
|
|
|
Dead {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
err: String,
|
|
|
|
},
|
|
|
|
OptimisticConfirmation {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
},
|
|
|
|
Root {
|
|
|
|
slot: Slot,
|
|
|
|
timestamp: u64,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SlotUpdate {
|
|
|
|
pub fn slot(&self) -> Slot {
|
|
|
|
match self {
|
|
|
|
Self::FirstShredReceived { slot, .. } => *slot,
|
|
|
|
Self::Completed { slot, .. } => *slot,
|
|
|
|
Self::CreatedBank { slot, .. } => *slot,
|
|
|
|
Self::Frozen { slot, .. } => *slot,
|
|
|
|
Self::Dead { slot, .. } => *slot,
|
|
|
|
Self::OptimisticConfirmation { slot, .. } => *slot,
|
|
|
|
Self::Root { slot, .. } => *slot,
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 23:29:11 -08:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-09-03 17:14:45 -07:00
|
|
|
#[serde(rename_all = "camelCase", untagged)]
|
2020-09-01 22:06:06 -07:00
|
|
|
pub enum RpcSignatureResult {
|
2020-09-03 17:14:45 -07:00
|
|
|
ProcessedSignature(ProcessedSignatureResult),
|
|
|
|
ReceivedSignature(ReceivedSignatureResult),
|
2020-09-01 22:06:06 -07:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-11-20 13:52:58 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcLogsResponse {
|
|
|
|
pub signature: String, // Signature as base58 string
|
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
pub logs: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-04-04 16:13:26 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-09-01 22:06:06 -07:00
|
|
|
pub struct ProcessedSignatureResult {
|
2020-04-04 16:13:26 -07:00
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-09-03 17:14:45 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum ReceivedSignatureResult {
|
|
|
|
ReceivedSignature,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-09-21 19:54:43 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-01-14 23:25:45 -08:00
|
|
|
pub struct RpcContactInfo {
|
|
|
|
/// Pubkey of the node as a base-58 string
|
|
|
|
pub pubkey: String,
|
|
|
|
/// Gossip port
|
|
|
|
pub gossip: Option<SocketAddr>,
|
2023-04-22 13:18:58 -07:00
|
|
|
/// Tpu UDP port
|
2020-01-14 23:25:45 -08:00
|
|
|
pub tpu: Option<SocketAddr>,
|
2023-04-22 13:18:58 -07:00
|
|
|
/// Tpu QUIC port
|
|
|
|
pub tpu_quic: Option<SocketAddr>,
|
2020-01-14 23:25:45 -08:00
|
|
|
/// JSON RPC port
|
|
|
|
pub rpc: Option<SocketAddr>,
|
2023-01-08 21:25:56 -08:00
|
|
|
/// WebSocket PubSub port
|
|
|
|
pub pubsub: Option<SocketAddr>,
|
2020-05-11 21:30:01 -07:00
|
|
|
/// Software version
|
|
|
|
pub version: Option<String>,
|
2020-09-21 19:54:43 -07:00
|
|
|
/// First 4 bytes of the FeatureSet identifier
|
|
|
|
pub feature_set: Option<u32>,
|
2021-05-13 20:33:57 -07:00
|
|
|
/// Shred version
|
|
|
|
pub shred_version: Option<u16>,
|
2020-01-14 23:25:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Map of leader base58 identity pubkeys to the slot indices relative to the first epoch slot
|
|
|
|
pub type RpcLeaderSchedule = HashMap<String, Vec<usize>>;
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2021-04-28 09:57:05 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockProductionRange {
|
|
|
|
pub first_slot: Slot,
|
|
|
|
pub last_slot: Slot,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2021-04-28 09:57:05 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockProduction {
|
|
|
|
/// Map of leader base58 identity pubkeys to a tuple of `(number of leader slots, number of blocks produced)`
|
|
|
|
pub by_identity: HashMap<String, (usize, usize)>,
|
|
|
|
pub range: RpcBlockProductionRange,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct RpcVersionInfo {
|
|
|
|
/// The current version of solana-core
|
|
|
|
pub solana_core: String,
|
2020-09-21 19:54:43 -07:00
|
|
|
/// first 4 bytes of the FeatureSet identifier
|
|
|
|
pub feature_set: Option<u32>,
|
2020-01-14 23:25:45 -08:00
|
|
|
}
|
|
|
|
|
2020-09-21 20:20:51 -07:00
|
|
|
impl fmt::Debug for RpcVersionInfo {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.solana_core)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for RpcVersionInfo {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
if let Some(version) = self.solana_core.split_whitespace().next() {
|
|
|
|
// Display just the semver if possible
|
2022-12-06 06:30:06 -08:00
|
|
|
write!(f, "{version}")
|
2020-09-21 20:20:51 -07:00
|
|
|
} else {
|
|
|
|
write!(f, "{}", self.solana_core)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-03-04 14:44:21 -08:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct RpcIdentity {
|
|
|
|
/// The current node identity pubkey
|
|
|
|
pub identity: String,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2021-10-29 10:11:20 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcVote {
|
2022-01-26 22:03:03 -08:00
|
|
|
/// Vote account address, as base-58 encoded string
|
|
|
|
pub vote_pubkey: String,
|
2021-10-29 10:11:20 -07:00
|
|
|
pub slots: Vec<Slot>,
|
|
|
|
pub hash: String,
|
|
|
|
pub timestamp: Option<UnixTimestamp>,
|
2022-05-19 18:28:46 -07:00
|
|
|
pub signature: String,
|
2021-10-29 10:11:20 -07:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcVoteAccountStatus {
|
|
|
|
pub current: Vec<RpcVoteAccountInfo>,
|
|
|
|
pub delinquent: Vec<RpcVoteAccountInfo>,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcVoteAccountInfo {
|
2021-04-21 14:13:41 -07:00
|
|
|
/// Vote account address, as base-58 encoded string
|
2020-01-14 23:25:45 -08:00
|
|
|
pub vote_pubkey: String,
|
|
|
|
|
2021-04-21 14:13:41 -07:00
|
|
|
/// The validator identity, as base-58 encoded string
|
2020-01-14 23:25:45 -08:00
|
|
|
pub node_pubkey: String,
|
|
|
|
|
|
|
|
/// The current stake, in lamports, delegated to this vote account
|
|
|
|
pub activated_stake: u64,
|
|
|
|
|
|
|
|
/// An 8-bit integer used as a fraction (commission/MAX_U8) for rewards payout
|
|
|
|
pub commission: u8,
|
|
|
|
|
|
|
|
/// Whether this account is staked for the current epoch
|
|
|
|
pub epoch_vote_account: bool,
|
|
|
|
|
2022-09-26 16:28:29 -07:00
|
|
|
/// Latest history of earned credits for up to `MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY` epochs
|
2020-01-14 23:25:45 -08:00
|
|
|
/// each tuple is (Epoch, credits, prev_credits)
|
|
|
|
pub epoch_credits: Vec<(Epoch, u64, u64)>,
|
|
|
|
|
|
|
|
/// Most recent slot voted on by this vote account (0 if no votes exist)
|
|
|
|
pub last_vote: u64,
|
|
|
|
|
2022-09-22 12:59:31 -07:00
|
|
|
/// Current root slot for this vote account (0 if no root slot exists)
|
2020-01-14 23:25:45 -08:00
|
|
|
pub root_slot: Slot,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcSignatureConfirmation {
|
|
|
|
pub confirmations: usize,
|
|
|
|
pub status: Result<()>,
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-06-06 10:18:28 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcSimulateTransactionResult {
|
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
pub logs: Option<Vec<String>>,
|
2021-05-25 16:44:18 -07:00
|
|
|
pub accounts: Option<Vec<Option<UiAccount>>>,
|
2021-07-16 14:58:15 -07:00
|
|
|
pub units_consumed: Option<u64>,
|
2022-09-08 14:10:57 -07:00
|
|
|
pub return_data: Option<UiTransactionReturnData>,
|
2020-06-06 10:18:28 -07:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-01-14 23:25:45 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcStorageTurn {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub slot: Slot,
|
|
|
|
}
|
2020-05-04 16:46:10 -07:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-05-04 16:46:10 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcAccountBalance {
|
|
|
|
pub address: String,
|
|
|
|
pub lamports: u64,
|
|
|
|
}
|
2020-05-09 11:05:29 -07:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-05-09 11:05:29 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcSupply {
|
|
|
|
pub total: u64,
|
|
|
|
pub circulating: u64,
|
|
|
|
pub non_circulating: u64,
|
|
|
|
pub non_circulating_accounts: Vec<String>,
|
|
|
|
}
|
2020-07-06 12:28:40 -07:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-07-06 12:28:40 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum StakeActivationState {
|
|
|
|
Activating,
|
|
|
|
Active,
|
|
|
|
Deactivating,
|
|
|
|
Inactive,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
2020-07-06 12:28:40 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcStakeActivation {
|
|
|
|
pub state: StakeActivationState,
|
|
|
|
pub active: u64,
|
|
|
|
pub inactive: u64,
|
|
|
|
}
|
2020-08-02 09:23:44 -07:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcTokenAccountBalance {
|
|
|
|
pub address: String,
|
2020-08-04 23:48:09 -07:00
|
|
|
#[serde(flatten)]
|
2020-08-07 10:37:39 -07:00
|
|
|
pub amount: UiTokenAmount,
|
2020-08-02 09:23:44 -07:00
|
|
|
}
|
2020-07-27 11:42:49 -07:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
2020-07-27 11:42:49 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcConfirmedTransactionStatusWithSignature {
|
|
|
|
pub signature: String,
|
|
|
|
pub slot: Slot,
|
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
pub memo: Option<String>,
|
2021-01-20 22:10:35 -08:00
|
|
|
pub block_time: Option<UnixTimestamp>,
|
2021-03-31 21:35:57 -07:00
|
|
|
pub confirmation_status: Option<TransactionConfirmationStatus>,
|
2020-07-27 11:42:49 -07:00
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
2020-09-24 14:22:22 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcPerfSample {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub num_transactions: u64,
|
2023-01-18 00:22:47 -08:00
|
|
|
pub num_non_vote_transactions: Option<u64>,
|
2020-09-24 14:22:22 -07:00
|
|
|
pub num_slots: u64,
|
|
|
|
pub sample_period_secs: u16,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
2021-04-06 18:10:53 -07:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcInflationReward {
|
|
|
|
pub epoch: Epoch,
|
|
|
|
pub effective_slot: Slot,
|
2021-07-10 23:18:42 -07:00
|
|
|
pub amount: u64, // lamports
|
|
|
|
pub post_balance: u64, // lamports
|
|
|
|
pub commission: Option<u8>, // Vote account commission when the reward was credited
|
2021-04-06 18:10:53 -07:00
|
|
|
}
|
|
|
|
|
2021-12-17 15:03:09 -08:00
|
|
|
#[derive(Clone, Deserialize, Serialize, Debug, Error, Eq, PartialEq)]
|
|
|
|
pub enum RpcBlockUpdateError {
|
|
|
|
#[error("block store error")]
|
|
|
|
BlockStoreError,
|
2022-01-13 23:24:41 -08:00
|
|
|
|
2022-03-07 23:20:34 -08:00
|
|
|
#[error("unsupported transaction version ({0})")]
|
|
|
|
UnsupportedTransactionVersion(u8),
|
2021-12-17 15:03:09 -08:00
|
|
|
}
|
|
|
|
|
2022-08-22 17:12:32 -07:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
2021-12-17 15:03:09 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockUpdate {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub block: Option<UiConfirmedBlock>,
|
|
|
|
pub err: Option<RpcBlockUpdateError>,
|
|
|
|
}
|
|
|
|
|
2020-07-27 11:42:49 -07:00
|
|
|
impl From<ConfirmedTransactionStatusWithSignature> for RpcConfirmedTransactionStatusWithSignature {
|
|
|
|
fn from(value: ConfirmedTransactionStatusWithSignature) -> Self {
|
|
|
|
let ConfirmedTransactionStatusWithSignature {
|
|
|
|
signature,
|
|
|
|
slot,
|
|
|
|
err,
|
|
|
|
memo,
|
2021-01-20 22:10:35 -08:00
|
|
|
block_time,
|
2020-07-27 11:42:49 -07:00
|
|
|
} = value;
|
|
|
|
Self {
|
|
|
|
signature: signature.to_string(),
|
|
|
|
slot,
|
|
|
|
err,
|
|
|
|
memo,
|
2021-01-20 22:10:35 -08:00
|
|
|
block_time,
|
2021-03-31 21:35:57 -07:00
|
|
|
confirmation_status: None,
|
2020-07-27 11:42:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 13:25:42 -07:00
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
2021-09-02 13:25:42 -07:00
|
|
|
pub struct RpcSnapshotSlotInfo {
|
|
|
|
pub full: Slot,
|
|
|
|
pub incremental: Option<Slot>,
|
|
|
|
}
|
2022-09-01 16:12:12 -07:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
2023-02-07 12:42:58 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2022-09-01 16:12:12 -07:00
|
|
|
pub struct RpcPrioritizationFee {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub prioritization_fee: u64,
|
|
|
|
}
|
2023-01-18 00:22:47 -08:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub mod tests {
|
|
|
|
|
|
|
|
use {super::*, serde_json::json};
|
|
|
|
|
|
|
|
// Make sure that `RpcPerfSample` can read previous version JSON, one without the
|
|
|
|
// `num_non_vote_transactions` field.
|
|
|
|
#[test]
|
|
|
|
fn rpc_perf_sample_deserialize_old() {
|
|
|
|
let slot = 424;
|
|
|
|
let num_transactions = 2597;
|
|
|
|
let num_slots = 2783;
|
|
|
|
let sample_period_secs = 398;
|
|
|
|
|
|
|
|
let input = json!({
|
|
|
|
"slot": slot,
|
|
|
|
"numTransactions": num_transactions,
|
|
|
|
"numSlots": num_slots,
|
|
|
|
"samplePeriodSecs": sample_period_secs,
|
|
|
|
})
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let actual: RpcPerfSample =
|
|
|
|
serde_json::from_str(&input).expect("Can parse RpcPerfSample from string as JSON");
|
|
|
|
let expected = RpcPerfSample {
|
|
|
|
slot,
|
|
|
|
num_transactions,
|
|
|
|
num_non_vote_transactions: None,
|
|
|
|
num_slots,
|
|
|
|
sample_period_secs,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that `RpcPerfSample` serializes into the new `num_non_vote_transactions` field.
|
|
|
|
#[test]
|
|
|
|
fn rpc_perf_sample_serializes_num_non_vote_transactions() {
|
|
|
|
let slot = 1286;
|
|
|
|
let num_transactions = 1732;
|
|
|
|
let num_non_vote_transactions = Some(757);
|
|
|
|
let num_slots = 393;
|
|
|
|
let sample_period_secs = 197;
|
|
|
|
|
|
|
|
let input = RpcPerfSample {
|
|
|
|
slot,
|
|
|
|
num_transactions,
|
|
|
|
num_non_vote_transactions,
|
|
|
|
num_slots,
|
|
|
|
sample_period_secs,
|
|
|
|
};
|
|
|
|
let actual =
|
2023-02-16 08:12:51 -08:00
|
|
|
serde_json::to_value(input).expect("Can convert RpcPerfSample into a JSON value");
|
2023-01-18 00:22:47 -08:00
|
|
|
let expected = json!({
|
|
|
|
"slot": slot,
|
|
|
|
"numTransactions": num_transactions,
|
|
|
|
"numNonVoteTransactions": num_non_vote_transactions,
|
|
|
|
"numSlots": num_slots,
|
|
|
|
"samplePeriodSecs": sample_period_secs,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|
|
|
|
}
|