2020-06-30 21:55:11 -07:00
|
|
|
use crate::client_error;
|
2020-08-07 10:37:39 -07:00
|
|
|
use solana_account_decoder::{parse_token::UiTokenAmount, UiAccount};
|
2020-01-14 23:25:45 -08:00
|
|
|
use solana_sdk::{
|
2021-01-20 22:10:35 -08:00
|
|
|
clock::{Epoch, Slot, UnixTimestamp},
|
2020-02-28 12:27:01 -08:00
|
|
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
2020-05-29 11:50:25 -07:00
|
|
|
inflation::Inflation,
|
2020-04-04 16:13:26 -07:00
|
|
|
transaction::{Result, TransactionError},
|
2020-01-14 23:25:45 -08:00
|
|
|
};
|
2020-07-27 11:42:49 -07:00
|
|
|
use solana_transaction_status::ConfirmedTransactionStatusWithSignature;
|
2020-09-21 20:20:51 -07:00
|
|
|
use std::{collections::HashMap, fmt, net::SocketAddr};
|
2020-01-14 23:25:45 -08:00
|
|
|
|
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
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct RpcResponseContext {
|
|
|
|
pub slot: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Response<T> {
|
|
|
|
pub context: RpcResponseContext,
|
|
|
|
pub value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockCommitment<T> {
|
|
|
|
pub commitment: Option<T>,
|
|
|
|
pub total_stake: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcBlockhashFeeCalculator {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
}
|
|
|
|
|
2020-05-26 12:06:21 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcFees {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
pub last_valid_slot: Slot,
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:01:31 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcFeeCalculator {
|
|
|
|
pub fee_calculator: FeeCalculator,
|
|
|
|
}
|
|
|
|
|
2020-02-28 12:27:01 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[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,
|
|
|
|
}
|
|
|
|
|
2020-01-14 23:25:45 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[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
|
|
|
}
|
|
|
|
|
2020-09-03 17:14:45 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
|
|
|
|
pub struct SlotInfo {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub parent: Slot,
|
|
|
|
pub root: Slot,
|
|
|
|
}
|
|
|
|
|
2020-09-01 22:06:06 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
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
|
|
|
}
|
|
|
|
|
2020-11-20 13:52:58 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcLogsResponse {
|
|
|
|
pub signature: String, // Signature as base58 string
|
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
pub logs: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:13:26 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[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>,
|
|
|
|
}
|
|
|
|
|
2020-09-03 17:14:45 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum ReceivedSignatureResult {
|
|
|
|
ReceivedSignature,
|
|
|
|
}
|
|
|
|
|
2020-01-14 23:25:45 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
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>,
|
|
|
|
/// Tpu port
|
|
|
|
pub tpu: Option<SocketAddr>,
|
|
|
|
/// JSON RPC port
|
|
|
|
pub rpc: 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>,
|
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>>;
|
|
|
|
|
2020-09-21 20:20:51 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
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
|
|
|
|
write!(f, "{}", version)
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", self.solana_core)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 14:44:21 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct RpcIdentity {
|
|
|
|
/// The current node identity pubkey
|
|
|
|
pub identity: String,
|
|
|
|
}
|
|
|
|
|
2020-01-14 23:25:45 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcVoteAccountStatus {
|
|
|
|
pub current: Vec<RpcVoteAccountInfo>,
|
|
|
|
pub delinquent: Vec<RpcVoteAccountInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcVoteAccountInfo {
|
|
|
|
/// Vote account pubkey as base-58 encoded string
|
|
|
|
pub vote_pubkey: String,
|
|
|
|
|
|
|
|
/// The pubkey of the node that votes using this account
|
|
|
|
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,
|
|
|
|
|
|
|
|
/// History of how many credits earned by the end of each epoch
|
|
|
|
/// 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,
|
|
|
|
|
|
|
|
/// Current root slot for this vote account (0 if not root slot exists)
|
|
|
|
pub root_slot: Slot,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcSignatureConfirmation {
|
|
|
|
pub confirmations: usize,
|
|
|
|
pub status: Result<()>,
|
|
|
|
}
|
|
|
|
|
2020-06-06 10:18:28 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcSimulateTransactionResult {
|
|
|
|
pub err: Option<TransactionError>,
|
|
|
|
pub logs: Option<Vec<String>>,
|
|
|
|
}
|
|
|
|
|
2020-01-14 23:25:45 -08:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcStorageTurn {
|
|
|
|
pub blockhash: String,
|
|
|
|
pub slot: Slot,
|
|
|
|
}
|
2020-05-04 16:46:10 -07:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcAccountBalance {
|
|
|
|
pub address: String,
|
|
|
|
pub lamports: u64,
|
|
|
|
}
|
2020-05-09 11:05:29 -07:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[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
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum StakeActivationState {
|
|
|
|
Activating,
|
|
|
|
Active,
|
|
|
|
Deactivating,
|
|
|
|
Inactive,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
|
#[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
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[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>,
|
2020-07-27 11:42:49 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 14:22:22 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct RpcPerfSample {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub num_transactions: u64,
|
|
|
|
pub num_slots: u64,
|
|
|
|
pub sample_period_secs: u16,
|
|
|
|
}
|
|
|
|
|
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,
|
2020-07-27 11:42:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|