2021-03-26 20:26:06 -07:00
|
|
|
use {
|
2022-08-23 22:34:35 -07:00
|
|
|
crate::response::RpcSimulateTransactionResult,
|
2021-03-26 20:26:06 -07:00
|
|
|
serde_json::{json, Value},
|
|
|
|
solana_sdk::{clock::Slot, pubkey::Pubkey},
|
|
|
|
std::fmt,
|
|
|
|
thiserror::Error,
|
|
|
|
};
|
2019-10-06 20:30:22 -07:00
|
|
|
|
2020-05-10 08:51:53 -07:00
|
|
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
2019-03-12 17:26:07 -07:00
|
|
|
pub enum RpcRequest {
|
2021-08-13 09:08:20 -07:00
|
|
|
Custom {
|
|
|
|
method: &'static str,
|
|
|
|
},
|
2019-04-25 07:52:53 -07:00
|
|
|
DeregisterNode,
|
2019-03-12 17:26:07 -07:00
|
|
|
GetAccountInfo,
|
|
|
|
GetBalance,
|
2021-04-15 16:00:14 -07:00
|
|
|
GetBlock,
|
2021-05-26 00:26:19 -07:00
|
|
|
GetBlockHeight,
|
2021-04-28 09:57:05 -07:00
|
|
|
GetBlockProduction,
|
2021-04-15 16:00:14 -07:00
|
|
|
GetBlocks,
|
|
|
|
GetBlocksWithLimit,
|
2019-11-25 23:40:36 -08:00
|
|
|
GetBlockTime,
|
2019-04-25 07:52:53 -07:00
|
|
|
GetClusterNodes,
|
2021-04-15 16:00:14 -07:00
|
|
|
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlock instead")]
|
2019-12-18 21:31:38 -08:00
|
|
|
GetConfirmedBlock,
|
2021-04-15 16:00:14 -07:00
|
|
|
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlocks instead")]
|
2019-12-18 21:31:38 -08:00
|
|
|
GetConfirmedBlocks,
|
2021-04-15 16:00:14 -07:00
|
|
|
#[deprecated(
|
|
|
|
since = "1.7.0",
|
|
|
|
note = "Please use RpcRequest::GetBlocksWithLimit instead"
|
|
|
|
)]
|
2020-09-30 13:47:12 -07:00
|
|
|
GetConfirmedBlocksWithLimit,
|
2021-04-13 13:05:42 -07:00
|
|
|
#[deprecated(
|
2021-04-15 16:00:14 -07:00
|
|
|
since = "1.7.0",
|
|
|
|
note = "Please use RpcRequest::GetSignaturesForAddress instead"
|
2021-04-13 13:05:42 -07:00
|
|
|
)]
|
2020-07-27 11:42:49 -07:00
|
|
|
GetConfirmedSignaturesForAddress2,
|
2021-04-15 16:00:14 -07:00
|
|
|
#[deprecated(
|
|
|
|
since = "1.7.0",
|
|
|
|
note = "Please use RpcRequest::GetTransaction instead"
|
|
|
|
)]
|
2020-04-15 20:51:05 -07:00
|
|
|
GetConfirmedTransaction,
|
2019-09-27 22:00:30 -07:00
|
|
|
GetEpochInfo,
|
2019-10-22 13:41:18 -07:00
|
|
|
GetEpochSchedule,
|
2021-08-13 09:08:20 -07:00
|
|
|
#[deprecated(
|
2021-10-26 09:06:41 -07:00
|
|
|
since = "1.9.0",
|
2021-08-13 09:08:20 -07:00
|
|
|
note = "Please use RpcRequest::GetFeeForMessage instead"
|
|
|
|
)]
|
2020-05-26 12:06:21 -07:00
|
|
|
GetFeeCalculatorForBlockhash,
|
2021-08-13 09:08:20 -07:00
|
|
|
GetFeeForMessage,
|
|
|
|
#[deprecated(
|
2021-10-26 09:06:41 -07:00
|
|
|
since = "1.9.0",
|
2021-08-13 09:08:20 -07:00
|
|
|
note = "Please do not use, will no longer be available in the future"
|
|
|
|
)]
|
2020-05-26 12:06:21 -07:00
|
|
|
GetFeeRateGovernor,
|
2021-08-13 09:08:20 -07:00
|
|
|
#[deprecated(
|
2021-10-26 09:06:41 -07:00
|
|
|
since = "1.9.0",
|
2021-08-13 09:08:20 -07:00
|
|
|
note = "Please use RpcRequest::GetFeeForMessage instead"
|
|
|
|
)]
|
2020-05-26 12:06:21 -07:00
|
|
|
GetFees,
|
2020-09-06 10:54:01 -07:00
|
|
|
GetFirstAvailableBlock,
|
2019-11-08 20:56:57 -08:00
|
|
|
GetGenesisHash,
|
2021-01-14 21:45:11 -08:00
|
|
|
GetHealth,
|
2020-03-04 14:44:21 -08:00
|
|
|
GetIdentity,
|
2020-05-29 11:50:25 -07:00
|
|
|
GetInflationGovernor,
|
|
|
|
GetInflationRate,
|
2021-04-06 18:10:53 -07:00
|
|
|
GetInflationReward,
|
2020-05-12 20:05:05 -07:00
|
|
|
GetLargestAccounts,
|
2021-08-13 09:08:20 -07:00
|
|
|
GetLatestBlockhash,
|
2019-12-17 15:26:31 -08:00
|
|
|
GetLeaderSchedule,
|
2021-03-30 14:22:41 -07:00
|
|
|
GetMaxRetransmitSlot,
|
|
|
|
GetMaxShredInsertSlot,
|
2020-05-26 12:06:21 -07:00
|
|
|
GetMinimumBalanceForRentExemption,
|
2020-09-03 10:35:06 -07:00
|
|
|
GetMultipleAccounts,
|
2019-07-11 11:38:52 -07:00
|
|
|
GetProgramAccounts,
|
2021-08-13 09:08:20 -07:00
|
|
|
#[deprecated(
|
2021-10-26 09:06:41 -07:00
|
|
|
since = "1.9.0",
|
2021-08-13 09:08:20 -07:00
|
|
|
note = "Please use RpcRequest::GetLatestBlockhash instead"
|
|
|
|
)]
|
2019-03-12 17:26:07 -07:00
|
|
|
GetRecentBlockhash,
|
2021-03-16 01:35:27 -07:00
|
|
|
GetRecentPerformanceSamples,
|
2023-01-06 22:04:34 -08:00
|
|
|
GetRecentPrioritizationFees,
|
2021-09-02 13:25:42 -07:00
|
|
|
GetHighestSnapshotSlot,
|
|
|
|
#[deprecated(
|
2021-10-26 09:06:41 -07:00
|
|
|
since = "1.9.0",
|
2021-09-02 13:25:42 -07:00
|
|
|
note = "Please use RpcRequest::GetHighestSnapshotSlot instead"
|
|
|
|
)]
|
2021-01-14 21:45:11 -08:00
|
|
|
GetSnapshotSlot,
|
2021-04-15 16:00:14 -07:00
|
|
|
GetSignaturesForAddress,
|
2020-04-01 11:30:58 -07:00
|
|
|
GetSignatureStatuses,
|
2019-06-12 16:43:05 -07:00
|
|
|
GetSlot,
|
2019-04-25 07:52:53 -07:00
|
|
|
GetSlotLeader,
|
2021-03-23 10:48:54 -07:00
|
|
|
GetSlotLeaders,
|
2019-07-10 13:33:29 -07:00
|
|
|
GetStorageTurn,
|
|
|
|
GetStorageTurnRate,
|
2019-07-09 16:48:40 -07:00
|
|
|
GetSlotsPerSegment,
|
2021-03-26 18:11:11 -07:00
|
|
|
GetStakeActivation,
|
2022-07-17 11:39:39 -07:00
|
|
|
GetStakeMinimumDelegation,
|
2019-05-03 16:27:53 -07:00
|
|
|
GetStoragePubkeysForSlot,
|
2020-05-10 11:05:14 -07:00
|
|
|
GetSupply,
|
2020-07-31 13:53:49 -07:00
|
|
|
GetTokenAccountBalance,
|
|
|
|
GetTokenAccountsByDelegate,
|
|
|
|
GetTokenAccountsByOwner,
|
2022-08-16 13:32:38 -07:00
|
|
|
GetTokenLargestAccounts,
|
2020-07-31 13:53:49 -07:00
|
|
|
GetTokenSupply,
|
2021-04-15 16:00:14 -07:00
|
|
|
GetTransaction,
|
2019-03-12 17:26:07 -07:00
|
|
|
GetTransactionCount,
|
2019-08-08 10:13:06 -07:00
|
|
|
GetVersion,
|
2019-08-16 16:02:19 -07:00
|
|
|
GetVoteAccounts,
|
2021-08-13 09:08:20 -07:00
|
|
|
IsBlockhashValid,
|
2020-05-26 12:06:21 -07:00
|
|
|
MinimumLedgerSlot,
|
2019-04-25 07:52:53 -07:00
|
|
|
RegisterNode,
|
2019-03-12 17:26:07 -07:00
|
|
|
RequestAirdrop,
|
|
|
|
SendTransaction,
|
2020-05-19 12:08:19 -07:00
|
|
|
SimulateTransaction,
|
2019-03-12 17:26:07 -07:00
|
|
|
SignVote,
|
|
|
|
}
|
|
|
|
|
2021-04-13 13:05:42 -07:00
|
|
|
#[allow(deprecated)]
|
2020-05-10 08:51:53 -07:00
|
|
|
impl fmt::Display for RpcRequest {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2019-03-12 17:26:07 -07:00
|
|
|
let method = match self {
|
2021-08-13 09:08:20 -07:00
|
|
|
RpcRequest::Custom { method } => method,
|
2019-04-25 07:52:53 -07:00
|
|
|
RpcRequest::DeregisterNode => "deregisterNode",
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequest::GetAccountInfo => "getAccountInfo",
|
|
|
|
RpcRequest::GetBalance => "getBalance",
|
2021-04-15 16:00:14 -07:00
|
|
|
RpcRequest::GetBlock => "getBlock",
|
2021-05-26 00:26:19 -07:00
|
|
|
RpcRequest::GetBlockHeight => "getBlockHeight",
|
2021-04-28 09:57:05 -07:00
|
|
|
RpcRequest::GetBlockProduction => "getBlockProduction",
|
2021-04-15 16:00:14 -07:00
|
|
|
RpcRequest::GetBlocks => "getBlocks",
|
|
|
|
RpcRequest::GetBlocksWithLimit => "getBlocksWithLimit",
|
2019-11-25 23:40:36 -08:00
|
|
|
RpcRequest::GetBlockTime => "getBlockTime",
|
2019-04-25 07:52:53 -07:00
|
|
|
RpcRequest::GetClusterNodes => "getClusterNodes",
|
2019-12-18 21:31:38 -08:00
|
|
|
RpcRequest::GetConfirmedBlock => "getConfirmedBlock",
|
|
|
|
RpcRequest::GetConfirmedBlocks => "getConfirmedBlocks",
|
2020-09-30 13:47:12 -07:00
|
|
|
RpcRequest::GetConfirmedBlocksWithLimit => "getConfirmedBlocksWithLimit",
|
2020-07-27 11:42:49 -07:00
|
|
|
RpcRequest::GetConfirmedSignaturesForAddress2 => "getConfirmedSignaturesForAddress2",
|
2020-04-15 20:51:05 -07:00
|
|
|
RpcRequest::GetConfirmedTransaction => "getConfirmedTransaction",
|
2019-09-27 22:00:30 -07:00
|
|
|
RpcRequest::GetEpochInfo => "getEpochInfo",
|
2019-10-22 13:41:18 -07:00
|
|
|
RpcRequest::GetEpochSchedule => "getEpochSchedule",
|
2020-05-26 12:06:21 -07:00
|
|
|
RpcRequest::GetFeeCalculatorForBlockhash => "getFeeCalculatorForBlockhash",
|
2021-08-13 09:08:20 -07:00
|
|
|
RpcRequest::GetFeeForMessage => "getFeeForMessage",
|
2020-05-26 12:06:21 -07:00
|
|
|
RpcRequest::GetFeeRateGovernor => "getFeeRateGovernor",
|
|
|
|
RpcRequest::GetFees => "getFees",
|
2020-09-06 10:54:01 -07:00
|
|
|
RpcRequest::GetFirstAvailableBlock => "getFirstAvailableBlock",
|
2019-11-08 20:56:57 -08:00
|
|
|
RpcRequest::GetGenesisHash => "getGenesisHash",
|
2021-01-14 21:45:11 -08:00
|
|
|
RpcRequest::GetHealth => "getHealth",
|
2020-03-04 14:44:21 -08:00
|
|
|
RpcRequest::GetIdentity => "getIdentity",
|
2020-05-29 11:50:25 -07:00
|
|
|
RpcRequest::GetInflationGovernor => "getInflationGovernor",
|
|
|
|
RpcRequest::GetInflationRate => "getInflationRate",
|
2021-04-06 18:10:53 -07:00
|
|
|
RpcRequest::GetInflationReward => "getInflationReward",
|
2020-05-12 20:05:05 -07:00
|
|
|
RpcRequest::GetLargestAccounts => "getLargestAccounts",
|
2021-08-13 09:08:20 -07:00
|
|
|
RpcRequest::GetLatestBlockhash => "getLatestBlockhash",
|
2019-12-17 15:26:31 -08:00
|
|
|
RpcRequest::GetLeaderSchedule => "getLeaderSchedule",
|
2021-03-30 14:22:41 -07:00
|
|
|
RpcRequest::GetMaxRetransmitSlot => "getMaxRetransmitSlot",
|
|
|
|
RpcRequest::GetMaxShredInsertSlot => "getMaxShredInsertSlot",
|
2020-05-26 12:06:21 -07:00
|
|
|
RpcRequest::GetMinimumBalanceForRentExemption => "getMinimumBalanceForRentExemption",
|
2020-09-03 10:35:06 -07:00
|
|
|
RpcRequest::GetMultipleAccounts => "getMultipleAccounts",
|
2019-07-11 11:38:52 -07:00
|
|
|
RpcRequest::GetProgramAccounts => "getProgramAccounts",
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequest::GetRecentBlockhash => "getRecentBlockhash",
|
2021-03-16 01:35:27 -07:00
|
|
|
RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples",
|
2023-01-06 22:04:34 -08:00
|
|
|
RpcRequest::GetRecentPrioritizationFees => "getRecentPrioritizationFees",
|
2021-09-02 13:25:42 -07:00
|
|
|
RpcRequest::GetHighestSnapshotSlot => "getHighestSnapshotSlot",
|
2021-01-14 21:45:11 -08:00
|
|
|
RpcRequest::GetSnapshotSlot => "getSnapshotSlot",
|
2021-04-15 16:00:14 -07:00
|
|
|
RpcRequest::GetSignaturesForAddress => "getSignaturesForAddress",
|
2020-04-01 11:30:58 -07:00
|
|
|
RpcRequest::GetSignatureStatuses => "getSignatureStatuses",
|
2019-06-12 16:43:05 -07:00
|
|
|
RpcRequest::GetSlot => "getSlot",
|
2019-04-25 07:52:53 -07:00
|
|
|
RpcRequest::GetSlotLeader => "getSlotLeader",
|
2021-03-23 10:48:54 -07:00
|
|
|
RpcRequest::GetSlotLeaders => "getSlotLeaders",
|
2021-03-26 18:11:11 -07:00
|
|
|
RpcRequest::GetStakeActivation => "getStakeActivation",
|
2022-07-17 11:39:39 -07:00
|
|
|
RpcRequest::GetStakeMinimumDelegation => "getStakeMinimumDelegation",
|
2019-07-10 13:33:29 -07:00
|
|
|
RpcRequest::GetStorageTurn => "getStorageTurn",
|
|
|
|
RpcRequest::GetStorageTurnRate => "getStorageTurnRate",
|
2019-07-09 16:48:40 -07:00
|
|
|
RpcRequest::GetSlotsPerSegment => "getSlotsPerSegment",
|
2019-05-03 16:27:53 -07:00
|
|
|
RpcRequest::GetStoragePubkeysForSlot => "getStoragePubkeysForSlot",
|
2020-05-10 11:05:14 -07:00
|
|
|
RpcRequest::GetSupply => "getSupply",
|
2020-07-31 13:53:49 -07:00
|
|
|
RpcRequest::GetTokenAccountBalance => "getTokenAccountBalance",
|
|
|
|
RpcRequest::GetTokenAccountsByDelegate => "getTokenAccountsByDelegate",
|
|
|
|
RpcRequest::GetTokenAccountsByOwner => "getTokenAccountsByOwner",
|
|
|
|
RpcRequest::GetTokenSupply => "getTokenSupply",
|
2022-08-16 13:32:38 -07:00
|
|
|
RpcRequest::GetTokenLargestAccounts => "getTokenLargestAccounts",
|
2021-04-15 16:00:14 -07:00
|
|
|
RpcRequest::GetTransaction => "getTransaction",
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequest::GetTransactionCount => "getTransactionCount",
|
2019-08-08 10:13:06 -07:00
|
|
|
RpcRequest::GetVersion => "getVersion",
|
2019-08-16 16:02:19 -07:00
|
|
|
RpcRequest::GetVoteAccounts => "getVoteAccounts",
|
2021-08-13 09:08:20 -07:00
|
|
|
RpcRequest::IsBlockhashValid => "isBlockhashValid",
|
2020-05-26 12:06:21 -07:00
|
|
|
RpcRequest::MinimumLedgerSlot => "minimumLedgerSlot",
|
2019-04-25 07:52:53 -07:00
|
|
|
RpcRequest::RegisterNode => "registerNode",
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequest::RequestAirdrop => "requestAirdrop",
|
|
|
|
RpcRequest::SendTransaction => "sendTransaction",
|
2020-05-19 12:08:19 -07:00
|
|
|
RpcRequest::SimulateTransaction => "simulateTransaction",
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequest::SignVote => "signVote",
|
|
|
|
};
|
2020-05-10 08:51:53 -07:00
|
|
|
|
2022-12-06 06:30:06 -08:00
|
|
|
write!(f, "{method}")
|
2020-05-10 08:51:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-25 14:19:58 -07:00
|
|
|
// Changing any of these? Update the JSON RPC docs!
|
2020-05-10 08:51:53 -07:00
|
|
|
pub const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS: usize = 256;
|
|
|
|
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE: u64 = 10_000;
|
2020-07-06 08:37:04 -07:00
|
|
|
pub const MAX_GET_CONFIRMED_BLOCKS_RANGE: u64 = 500_000;
|
2020-07-27 11:42:49 -07:00
|
|
|
pub const MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS2_LIMIT: usize = 1_000;
|
2020-09-04 10:51:28 -07:00
|
|
|
pub const MAX_MULTIPLE_ACCOUNTS: usize = 100;
|
2020-09-03 10:35:06 -07:00
|
|
|
pub const NUM_LARGEST_ACCOUNTS: usize = 20;
|
2021-02-22 22:54:35 -08:00
|
|
|
pub const MAX_GET_PROGRAM_ACCOUNT_FILTERS: usize = 4;
|
2021-03-23 10:48:54 -07:00
|
|
|
pub const MAX_GET_SLOT_LEADERS: usize = 5000;
|
2020-05-10 08:51:53 -07:00
|
|
|
|
2022-09-26 16:28:29 -07:00
|
|
|
// Limit the length of the `epoch_credits` array for each validator in a `get_vote_accounts`
|
|
|
|
// response
|
|
|
|
pub const MAX_RPC_VOTE_ACCOUNT_INFO_EPOCH_CREDITS_HISTORY: usize = 5;
|
|
|
|
|
2020-06-09 08:43:16 -07:00
|
|
|
// Validators that are this number of slots behind are considered delinquent
|
|
|
|
pub const DELINQUENT_VALIDATOR_SLOT_DISTANCE: u64 = 128;
|
|
|
|
|
2020-05-10 08:51:53 -07:00
|
|
|
impl RpcRequest {
|
2022-08-23 22:34:35 -07:00
|
|
|
pub fn build_request_json(self, id: u64, params: Value) -> Value {
|
2020-05-10 08:51:53 -07:00
|
|
|
let jsonrpc = "2.0";
|
2019-12-18 21:26:11 -08:00
|
|
|
json!({
|
2019-03-12 17:26:07 -07:00
|
|
|
"jsonrpc": jsonrpc,
|
|
|
|
"id": id,
|
2022-12-06 06:30:06 -08:00
|
|
|
"method": format!("{self}"),
|
2019-12-18 21:26:11 -08:00
|
|
|
"params": params,
|
|
|
|
})
|
2019-03-12 17:26:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 14:37:41 -08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum RpcResponseErrorData {
|
|
|
|
Empty,
|
|
|
|
SendTransactionPreflightFailure(RpcSimulateTransactionResult),
|
2021-01-17 20:23:14 -08:00
|
|
|
NodeUnhealthy { num_slots_behind: Option<Slot> },
|
2020-11-03 14:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for RpcResponseErrorData {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
RpcResponseErrorData::SendTransactionPreflightFailure(
|
|
|
|
RpcSimulateTransactionResult {
|
|
|
|
logs: Some(logs), ..
|
|
|
|
},
|
|
|
|
) => {
|
2020-11-03 20:23:41 -08:00
|
|
|
if logs.is_empty() {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
// Give the user a hint that there is more useful logging information available...
|
|
|
|
write!(f, "[{} log messages]", logs.len())
|
|
|
|
}
|
2020-11-03 14:37:41 -08:00
|
|
|
}
|
|
|
|
_ => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-12 23:20:49 -07:00
|
|
|
#[derive(Debug, Error)]
|
2019-03-12 17:26:07 -07:00
|
|
|
pub enum RpcError {
|
2020-10-12 17:47:06 -07:00
|
|
|
#[error("RPC request error: {0}")]
|
2019-03-12 17:26:07 -07:00
|
|
|
RpcRequestError(String),
|
2020-11-03 20:23:41 -08:00
|
|
|
#[error("RPC response error {code}: {message} {data}")]
|
2020-11-03 14:37:41 -08:00
|
|
|
RpcResponseError {
|
|
|
|
code: i64,
|
|
|
|
message: String,
|
|
|
|
data: RpcResponseErrorData,
|
|
|
|
},
|
2020-03-12 23:20:49 -07:00
|
|
|
#[error("parse error: expected {0}")]
|
|
|
|
ParseError(String), /* "expected" */
|
|
|
|
// Anything in a `ForUser` needs to die. The caller should be
|
|
|
|
// deciding what to tell their user
|
|
|
|
#[error("{0}")]
|
|
|
|
ForUser(String), /* "direct-to-user message" */
|
2019-03-12 17:26:07 -07:00
|
|
|
}
|
|
|
|
|
2020-07-31 13:53:49 -07:00
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub enum TokenAccountsFilter {
|
|
|
|
Mint(Pubkey),
|
|
|
|
ProgramId(Pubkey),
|
|
|
|
}
|
|
|
|
|
2019-03-12 17:26:07 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
super::*,
|
2022-08-23 22:34:35 -07:00
|
|
|
crate::config::RpcTokenAccountsFilter,
|
2021-12-03 09:00:31 -08:00
|
|
|
solana_sdk::commitment_config::{CommitmentConfig, CommitmentLevel},
|
|
|
|
};
|
2019-03-12 17:26:07 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_build_request_json() {
|
|
|
|
let test_request = RpcRequest::GetAccountInfo;
|
2019-11-06 13:15:00 -08:00
|
|
|
let addr = json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx");
|
2020-06-08 17:38:14 -07:00
|
|
|
let request = test_request.build_request_json(1, json!([addr]));
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "getAccountInfo");
|
2019-11-06 13:15:00 -08:00
|
|
|
assert_eq!(request["params"], json!([addr]));
|
2019-03-12 17:26:07 -07:00
|
|
|
|
|
|
|
let test_request = RpcRequest::GetBalance;
|
2020-06-08 17:38:14 -07:00
|
|
|
let request = test_request.build_request_json(1, json!([addr]));
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "getBalance");
|
|
|
|
|
2019-09-27 22:00:30 -07:00
|
|
|
let test_request = RpcRequest::GetEpochInfo;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-09-27 22:00:30 -07:00
|
|
|
assert_eq!(request["method"], "getEpochInfo");
|
|
|
|
|
2021-08-13 09:08:20 -07:00
|
|
|
#[allow(deprecated)]
|
2019-03-12 17:26:07 -07:00
|
|
|
let test_request = RpcRequest::GetRecentBlockhash;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "getRecentBlockhash");
|
|
|
|
|
2021-08-13 09:08:20 -07:00
|
|
|
#[allow(deprecated)]
|
2020-03-06 16:01:31 -08:00
|
|
|
let test_request = RpcRequest::GetFeeCalculatorForBlockhash;
|
2020-05-15 09:35:43 -07:00
|
|
|
let request = test_request.build_request_json(1, json!([addr]));
|
2020-03-06 16:01:31 -08:00
|
|
|
assert_eq!(request["method"], "getFeeCalculatorForBlockhash");
|
|
|
|
|
2021-08-13 09:08:20 -07:00
|
|
|
#[allow(deprecated)]
|
2020-02-28 12:27:01 -08:00
|
|
|
let test_request = RpcRequest::GetFeeRateGovernor;
|
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
|
|
|
assert_eq!(request["method"], "getFeeRateGovernor");
|
|
|
|
|
2019-06-12 16:43:05 -07:00
|
|
|
let test_request = RpcRequest::GetSlot;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-06-12 16:43:05 -07:00
|
|
|
assert_eq!(request["method"], "getSlot");
|
|
|
|
|
2019-03-12 17:26:07 -07:00
|
|
|
let test_request = RpcRequest::GetTransactionCount;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "getTransactionCount");
|
|
|
|
|
|
|
|
let test_request = RpcRequest::RequestAirdrop;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "requestAirdrop");
|
|
|
|
|
|
|
|
let test_request = RpcRequest::SendTransaction;
|
2019-12-18 21:26:11 -08:00
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
2019-03-12 17:26:07 -07:00
|
|
|
assert_eq!(request["method"], "sendTransaction");
|
2022-08-16 13:32:38 -07:00
|
|
|
|
|
|
|
let test_request = RpcRequest::GetTokenLargestAccounts;
|
|
|
|
let request = test_request.build_request_json(1, Value::Null);
|
|
|
|
assert_eq!(request["method"], "getTokenLargestAccounts");
|
2019-03-12 17:26:07 -07:00
|
|
|
}
|
2019-11-06 13:15:00 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_build_request_json_config_options() {
|
|
|
|
let commitment_config = CommitmentConfig {
|
2021-01-26 11:23:07 -08:00
|
|
|
commitment: CommitmentLevel::Finalized,
|
2019-11-06 13:15:00 -08:00
|
|
|
};
|
|
|
|
let addr = json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx");
|
|
|
|
|
|
|
|
// Test request with CommitmentConfig and no params
|
2021-08-13 09:08:20 -07:00
|
|
|
#[allow(deprecated)]
|
2019-11-06 13:15:00 -08:00
|
|
|
let test_request = RpcRequest::GetRecentBlockhash;
|
2020-06-08 17:38:14 -07:00
|
|
|
let request = test_request.build_request_json(1, json!([commitment_config]));
|
2019-11-06 13:15:00 -08:00
|
|
|
assert_eq!(request["params"], json!([commitment_config.clone()]));
|
|
|
|
|
|
|
|
// Test request with CommitmentConfig and params
|
|
|
|
let test_request = RpcRequest::GetBalance;
|
2020-06-08 17:38:14 -07:00
|
|
|
let request = test_request.build_request_json(1, json!([addr, commitment_config]));
|
2019-11-06 13:15:00 -08:00
|
|
|
assert_eq!(request["params"], json!([addr, commitment_config]));
|
2020-07-31 13:53:49 -07:00
|
|
|
|
|
|
|
// Test request with CommitmentConfig and params
|
|
|
|
let test_request = RpcRequest::GetTokenAccountsByOwner;
|
2020-10-19 12:12:08 -07:00
|
|
|
let mint = solana_sdk::pubkey::new_rand();
|
2020-07-31 13:53:49 -07:00
|
|
|
let token_account_filter = RpcTokenAccountsFilter::Mint(mint.to_string());
|
|
|
|
let request = test_request
|
|
|
|
.build_request_json(1, json!([addr, token_account_filter, commitment_config]));
|
|
|
|
assert_eq!(
|
|
|
|
request["params"],
|
|
|
|
json!([addr, token_account_filter, commitment_config])
|
|
|
|
);
|
2019-11-06 13:15:00 -08:00
|
|
|
}
|
2019-03-12 17:26:07 -07:00
|
|
|
}
|