Deprecate "confirmed" RpcClient methods (#16520)

* Remove obsolete client methods

* Deprecate GetConfirmed client methods

* Rename Confirmed config structs, with appropriate deprecation

* Fixup client apps

* Map RpcRequest to deprecated when targeting older nodes
This commit is contained in:
Tyera Eulberg 2021-04-15 17:00:14 -06:00 committed by GitHub
parent ba77e48c12
commit 974e6dd2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 398 additions and 104 deletions

View File

@ -28,7 +28,7 @@ use solana_client::{
nonce_utils, nonce_utils,
rpc_client::RpcClient, rpc_client::RpcClient,
rpc_config::{ rpc_config::{
RpcConfirmedTransactionConfig, RpcLargestAccountsFilter, RpcSendTransactionConfig, RpcLargestAccountsFilter, RpcSendTransactionConfig, RpcTransactionConfig,
RpcTransactionLogsFilter, RpcTransactionLogsFilter,
}, },
rpc_response::RpcKeyedAccount, rpc_response::RpcKeyedAccount,
@ -1033,9 +1033,9 @@ fn process_confirm(
let mut transaction = None; let mut transaction = None;
let mut get_transaction_error = None; let mut get_transaction_error = None;
if config.verbose { if config.verbose {
match rpc_client.get_confirmed_transaction_with_config( match rpc_client.get_transaction_with_config(
signature, signature,
RpcConfirmedTransactionConfig { RpcTransactionConfig {
encoding: Some(UiTransactionEncoding::Base64), encoding: Some(UiTransactionEncoding::Base64),
commitment: Some(CommitmentConfig::confirmed()), commitment: Some(CommitmentConfig::confirmed()),
}, },

View File

@ -24,9 +24,9 @@ use solana_client::{
pubsub_client::PubsubClient, pubsub_client::PubsubClient,
rpc_client::{GetConfirmedSignaturesForAddress2Config, RpcClient}, rpc_client::{GetConfirmedSignaturesForAddress2Config, RpcClient},
rpc_config::{ rpc_config::{
RpcAccountInfoConfig, RpcConfirmedBlockConfig, RpcConfirmedTransactionConfig, RpcAccountInfoConfig, RpcBlockConfig, RpcLargestAccountsConfig, RpcLargestAccountsFilter,
RpcLargestAccountsConfig, RpcLargestAccountsFilter, RpcProgramAccountsConfig, RpcProgramAccountsConfig, RpcTransactionConfig, RpcTransactionLogsConfig,
RpcTransactionLogsConfig, RpcTransactionLogsFilter, RpcTransactionLogsFilter,
}, },
rpc_filter, rpc_filter,
rpc_response::SlotInfo, rpc_response::SlotInfo,
@ -975,12 +975,12 @@ pub fn process_get_block(
}; };
let encoded_confirmed_block = rpc_client let encoded_confirmed_block = rpc_client
.get_confirmed_block_with_config( .get_block_with_config(
slot, slot,
RpcConfirmedBlockConfig { RpcBlockConfig {
encoding: Some(UiTransactionEncoding::Base64), encoding: Some(UiTransactionEncoding::Base64),
commitment: Some(CommitmentConfig::confirmed()), commitment: Some(CommitmentConfig::confirmed()),
..RpcConfirmedBlockConfig::default() ..RpcBlockConfig::default()
}, },
)? )?
.into(); .into();
@ -1108,7 +1108,7 @@ pub fn process_show_block_production(
"Fetching confirmed blocks between slots {} and {}...", "Fetching confirmed blocks between slots {} and {}...",
start_slot, end_slot start_slot, end_slot
)); ));
let confirmed_blocks = rpc_client.get_confirmed_blocks(start_slot, Some(end_slot))?; let confirmed_blocks = rpc_client.get_blocks(start_slot, Some(end_slot))?;
let start_slot_index = (start_slot - first_slot_in_epoch) as usize; let start_slot_index = (start_slot - first_slot_in_epoch) as usize;
let end_slot_index = (end_slot - first_slot_in_epoch) as usize; let end_slot_index = (end_slot - first_slot_in_epoch) as usize;
@ -1829,7 +1829,7 @@ pub fn process_transaction_history(
limit: usize, limit: usize,
show_transactions: bool, show_transactions: bool,
) -> ProcessResult { ) -> ProcessResult {
let results = rpc_client.get_confirmed_signatures_for_address2_with_config( let results = rpc_client.get_signatures_for_address_with_config(
address, address,
GetConfirmedSignaturesForAddress2Config { GetConfirmedSignaturesForAddress2Config {
before, before,
@ -1868,9 +1868,9 @@ pub fn process_transaction_history(
if show_transactions { if show_transactions {
if let Ok(signature) = result.signature.parse::<Signature>() { if let Ok(signature) = result.signature.parse::<Signature>() {
match rpc_client.get_confirmed_transaction_with_config( match rpc_client.get_transaction_with_config(
&signature, &signature,
RpcConfirmedTransactionConfig { RpcTransactionConfig {
encoding: Some(UiTransactionEncoding::Base64), encoding: Some(UiTransactionEncoding::Base64),
commitment: Some(CommitmentConfig::confirmed()), commitment: Some(CommitmentConfig::confirmed()),
}, },

View File

@ -13,6 +13,7 @@ pub mod rpc_cache;
pub mod rpc_client; pub mod rpc_client;
pub mod rpc_config; pub mod rpc_config;
pub mod rpc_custom_error; pub mod rpc_custom_error;
pub mod rpc_deprecated_config;
pub mod rpc_filter; pub mod rpc_filter;
pub mod rpc_request; pub mod rpc_request;
pub mod rpc_response; pub mod rpc_response;

View File

@ -1,3 +1,8 @@
#[allow(deprecated)]
use crate::rpc_deprecated_config::{
RpcConfirmedBlockConfig, RpcConfirmedTransactionConfig,
RpcGetConfirmedSignaturesForAddress2Config,
};
use { use {
crate::{ crate::{
client_error::{ClientError, ClientErrorKind, Result as ClientResult}, client_error::{ClientError, ClientErrorKind, Result as ClientResult},
@ -5,10 +10,9 @@ use {
mock_sender::{MockSender, Mocks}, mock_sender::{MockSender, Mocks},
rpc_config::RpcAccountInfoConfig, rpc_config::RpcAccountInfoConfig,
rpc_config::{ rpc_config::{
RpcConfirmedBlockConfig, RpcConfirmedTransactionConfig, RpcEpochConfig, RpcBlockConfig, RpcEpochConfig, RpcLargestAccountsConfig, RpcProgramAccountsConfig,
RpcGetConfirmedSignaturesForAddress2Config, RpcLargestAccountsConfig, RpcRequestAirdropConfig, RpcSendTransactionConfig, RpcSignaturesForAddressConfig,
RpcProgramAccountsConfig, RpcRequestAirdropConfig, RpcSendTransactionConfig, RpcSimulateTransactionConfig, RpcTokenAccountsFilter, RpcTransactionConfig,
RpcSimulateTransactionConfig, RpcTokenAccountsFilter,
}, },
rpc_request::{RpcError, RpcRequest, RpcResponseErrorData, TokenAccountsFilter}, rpc_request::{RpcError, RpcRequest, RpcResponseErrorData, TokenAccountsFilter},
rpc_response::*, rpc_response::*,
@ -182,6 +186,23 @@ impl RpcClient {
Ok(requested_commitment) Ok(requested_commitment)
} }
#[allow(deprecated)]
fn maybe_map_request(&self, mut request: RpcRequest) -> Result<RpcRequest, RpcError> {
if self.get_node_version()? < semver::Version::new(1, 7, 0) {
request = match request {
RpcRequest::GetBlock => RpcRequest::GetConfirmedBlock,
RpcRequest::GetBlocks => RpcRequest::GetConfirmedBlocks,
RpcRequest::GetBlocksWithLimit => RpcRequest::GetConfirmedBlocksWithLimit,
RpcRequest::GetSignaturesForAddress => {
RpcRequest::GetConfirmedSignaturesForAddress2
}
RpcRequest::GetTransaction => RpcRequest::GetConfirmedTransaction,
_ => request,
};
}
Ok(request)
}
pub fn confirm_transaction(&self, signature: &Signature) -> ClientResult<bool> { pub fn confirm_transaction(&self, signature: &Signature) -> ClientResult<bool> {
Ok(self Ok(self
.confirm_transaction_with_commitment(signature, self.commitment_config)? .confirm_transaction_with_commitment(signature, self.commitment_config)?
@ -458,27 +479,6 @@ impl RpcClient {
) )
} }
#[deprecated(since = "1.5.19", note = "Please use RpcClient::supply() instead")]
#[allow(deprecated)]
pub fn total_supply(&self) -> ClientResult<u64> {
self.total_supply_with_commitment(self.commitment_config)
}
#[deprecated(
since = "1.5.19",
note = "Please use RpcClient::supply_with_commitment() instead"
)]
#[allow(deprecated)]
pub fn total_supply_with_commitment(
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<u64> {
self.send(
RpcRequest::GetTotalSupply,
json!([self.maybe_map_commitment(commitment_config)?]),
)
}
pub fn get_largest_accounts_with_config( pub fn get_largest_accounts_with_config(
&self, &self,
config: RpcLargestAccountsConfig, config: RpcLargestAccountsConfig,
@ -542,10 +542,43 @@ impl RpcClient {
self.send(RpcRequest::GetClusterNodes, Value::Null) self.send(RpcRequest::GetClusterNodes, Value::Null)
} }
pub fn get_block(&self, slot: Slot) -> ClientResult<EncodedConfirmedBlock> {
self.get_block_with_encoding(slot, UiTransactionEncoding::Json)
}
pub fn get_block_with_encoding(
&self,
slot: Slot,
encoding: UiTransactionEncoding,
) -> ClientResult<EncodedConfirmedBlock> {
self.send(
self.maybe_map_request(RpcRequest::GetBlock)?,
json!([slot, encoding]),
)
}
pub fn get_block_with_config(
&self,
slot: Slot,
config: RpcBlockConfig,
) -> ClientResult<UiConfirmedBlock> {
self.send(
self.maybe_map_request(RpcRequest::GetBlock)?,
json!([slot, config]),
)
}
#[deprecated(since = "1.7.0", note = "Please use RpcClient::get_block() instead")]
#[allow(deprecated)]
pub fn get_confirmed_block(&self, slot: Slot) -> ClientResult<EncodedConfirmedBlock> { pub fn get_confirmed_block(&self, slot: Slot) -> ClientResult<EncodedConfirmedBlock> {
self.get_confirmed_block_with_encoding(slot, UiTransactionEncoding::Json) self.get_confirmed_block_with_encoding(slot, UiTransactionEncoding::Json)
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_block_with_encoding() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_block_with_encoding( pub fn get_confirmed_block_with_encoding(
&self, &self,
slot: Slot, slot: Slot,
@ -554,6 +587,11 @@ impl RpcClient {
self.send(RpcRequest::GetConfirmedBlock, json!([slot, encoding])) self.send(RpcRequest::GetConfirmedBlock, json!([slot, encoding]))
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_block_with_config() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_block_with_config( pub fn get_confirmed_block_with_config(
&self, &self,
slot: Slot, slot: Slot,
@ -562,6 +600,56 @@ impl RpcClient {
self.send(RpcRequest::GetConfirmedBlock, json!([slot, config])) self.send(RpcRequest::GetConfirmedBlock, json!([slot, config]))
} }
pub fn get_blocks(&self, start_slot: Slot, end_slot: Option<Slot>) -> ClientResult<Vec<Slot>> {
self.send(
self.maybe_map_request(RpcRequest::GetBlocks)?,
json!([start_slot, end_slot]),
)
}
pub fn get_blocks_with_commitment(
&self,
start_slot: Slot,
end_slot: Option<Slot>,
commitment_config: CommitmentConfig,
) -> ClientResult<Vec<Slot>> {
let json = if end_slot.is_some() {
json!([
start_slot,
end_slot,
self.maybe_map_commitment(commitment_config)?
])
} else {
json!([start_slot, self.maybe_map_commitment(commitment_config)?])
};
self.send(self.maybe_map_request(RpcRequest::GetBlocks)?, json)
}
pub fn get_blocks_with_limit(&self, start_slot: Slot, limit: usize) -> ClientResult<Vec<Slot>> {
self.send(
self.maybe_map_request(RpcRequest::GetBlocksWithLimit)?,
json!([start_slot, limit]),
)
}
pub fn get_blocks_with_limit_and_commitment(
&self,
start_slot: Slot,
limit: usize,
commitment_config: CommitmentConfig,
) -> ClientResult<Vec<Slot>> {
self.send(
self.maybe_map_request(RpcRequest::GetBlocksWithLimit)?,
json!([
start_slot,
limit,
self.maybe_map_commitment(commitment_config)?
]),
)
}
#[deprecated(since = "1.7.0", note = "Please use RpcClient::get_blocks() instead")]
#[allow(deprecated)]
pub fn get_confirmed_blocks( pub fn get_confirmed_blocks(
&self, &self,
start_slot: Slot, start_slot: Slot,
@ -573,6 +661,11 @@ impl RpcClient {
) )
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_blocks_with_commitment() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_blocks_with_commitment( pub fn get_confirmed_blocks_with_commitment(
&self, &self,
start_slot: Slot, start_slot: Slot,
@ -591,6 +684,11 @@ impl RpcClient {
self.send(RpcRequest::GetConfirmedBlocks, json) self.send(RpcRequest::GetConfirmedBlocks, json)
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_blocks_with_limit() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_blocks_with_limit( pub fn get_confirmed_blocks_with_limit(
&self, &self,
start_slot: Slot, start_slot: Slot,
@ -602,6 +700,11 @@ impl RpcClient {
) )
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_blocks_with_limit_and_commitment() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_blocks_with_limit_and_commitment( pub fn get_confirmed_blocks_with_limit_and_commitment(
&self, &self,
start_slot: Slot, start_slot: Slot,
@ -618,33 +721,41 @@ impl RpcClient {
) )
} }
#[deprecated( pub fn get_signatures_for_address(
since = "1.5.19",
note = "Please use RpcClient::get_confirmed_signatures_for_address2() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_signatures_for_address(
&self, &self,
address: &Pubkey, address: &Pubkey,
start_slot: Slot, ) -> ClientResult<Vec<RpcConfirmedTransactionStatusWithSignature>> {
end_slot: Slot, self.get_signatures_for_address_with_config(
) -> ClientResult<Vec<Signature>> { address,
let signatures_base58_str: Vec<String> = self.send( GetConfirmedSignaturesForAddress2Config::default(),
RpcRequest::GetConfirmedSignaturesForAddress, )
json!([address.to_string(), start_slot, end_slot]),
)?;
let mut signatures = vec![];
for signature_base58_str in signatures_base58_str {
signatures.push(
signature_base58_str.parse::<Signature>().map_err(|err| {
Into::<ClientError>::into(RpcError::ParseError(err.to_string()))
})?,
);
}
Ok(signatures)
} }
pub fn get_signatures_for_address_with_config(
&self,
address: &Pubkey,
config: GetConfirmedSignaturesForAddress2Config,
) -> ClientResult<Vec<RpcConfirmedTransactionStatusWithSignature>> {
let config = RpcSignaturesForAddressConfig {
before: config.before.map(|signature| signature.to_string()),
until: config.until.map(|signature| signature.to_string()),
limit: config.limit,
commitment: config.commitment,
};
let result: Vec<RpcConfirmedTransactionStatusWithSignature> = self.send(
self.maybe_map_request(RpcRequest::GetSignaturesForAddress)?,
json!([address.to_string(), config]),
)?;
Ok(result)
}
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_signatures_for_address() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_signatures_for_address2( pub fn get_confirmed_signatures_for_address2(
&self, &self,
address: &Pubkey, address: &Pubkey,
@ -655,6 +766,11 @@ impl RpcClient {
) )
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_signatures_for_address_with_config() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_signatures_for_address2_with_config( pub fn get_confirmed_signatures_for_address2_with_config(
&self, &self,
address: &Pubkey, address: &Pubkey,
@ -675,6 +791,33 @@ impl RpcClient {
Ok(result) Ok(result)
} }
pub fn get_transaction(
&self,
signature: &Signature,
encoding: UiTransactionEncoding,
) -> ClientResult<EncodedConfirmedTransaction> {
self.send(
self.maybe_map_request(RpcRequest::GetTransaction)?,
json!([signature.to_string(), encoding]),
)
}
pub fn get_transaction_with_config(
&self,
signature: &Signature,
config: RpcTransactionConfig,
) -> ClientResult<EncodedConfirmedTransaction> {
self.send(
self.maybe_map_request(RpcRequest::GetTransaction)?,
json!([signature.to_string(), config]),
)
}
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_transaction() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_transaction( pub fn get_confirmed_transaction(
&self, &self,
signature: &Signature, signature: &Signature,
@ -686,6 +829,11 @@ impl RpcClient {
) )
} }
#[deprecated(
since = "1.7.0",
note = "Please use RpcClient::get_transaction_with_config() instead"
)]
#[allow(deprecated)]
pub fn get_confirmed_transaction_with_config( pub fn get_confirmed_transaction_with_config(
&self, &self,
signature: &Signature, signature: &Signature,

View File

@ -113,7 +113,7 @@ pub struct RpcSignatureSubscribeConfig {
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcGetConfirmedSignaturesForAddress2Config { pub struct RpcSignaturesForAddressConfig {
pub before: Option<String>, // Signature as base-58 string pub before: Option<String>, // Signature as base-58 string
pub until: Option<String>, // Signature as base-58 string pub until: Option<String>, // Signature as base-58 string
pub limit: Option<usize>, pub limit: Option<usize>,
@ -135,6 +135,17 @@ impl<T: EncodingConfig + Default + Copy> RpcEncodingConfigWrapper<T> {
RpcEncodingConfigWrapper::Current(config) => config.unwrap_or_default(), RpcEncodingConfigWrapper::Current(config) => config.unwrap_or_default(),
} }
} }
pub fn convert<U: EncodingConfig + From<T>>(&self) -> RpcEncodingConfigWrapper<U> {
match self {
RpcEncodingConfigWrapper::Deprecated(encoding) => {
RpcEncodingConfigWrapper::Deprecated(*encoding)
}
RpcEncodingConfigWrapper::Current(config) => {
RpcEncodingConfigWrapper::Current(config.map(|config| config.into()))
}
}
}
} }
pub trait EncodingConfig { pub trait EncodingConfig {
@ -143,7 +154,7 @@ pub trait EncodingConfig {
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcConfirmedBlockConfig { pub struct RpcBlockConfig {
pub encoding: Option<UiTransactionEncoding>, pub encoding: Option<UiTransactionEncoding>,
pub transaction_details: Option<TransactionDetails>, pub transaction_details: Option<TransactionDetails>,
pub rewards: Option<bool>, pub rewards: Option<bool>,
@ -151,7 +162,7 @@ pub struct RpcConfirmedBlockConfig {
pub commitment: Option<CommitmentConfig>, pub commitment: Option<CommitmentConfig>,
} }
impl EncodingConfig for RpcConfirmedBlockConfig { impl EncodingConfig for RpcBlockConfig {
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self { fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
Self { Self {
encoding: *encoding, encoding: *encoding,
@ -160,7 +171,7 @@ impl EncodingConfig for RpcConfirmedBlockConfig {
} }
} }
impl RpcConfirmedBlockConfig { impl RpcBlockConfig {
pub fn rewards_only() -> Self { pub fn rewards_only() -> Self {
Self { Self {
transaction_details: Some(TransactionDetails::None), transaction_details: Some(TransactionDetails::None),
@ -177,21 +188,21 @@ impl RpcConfirmedBlockConfig {
} }
} }
impl From<RpcConfirmedBlockConfig> for RpcEncodingConfigWrapper<RpcConfirmedBlockConfig> { impl From<RpcBlockConfig> for RpcEncodingConfigWrapper<RpcBlockConfig> {
fn from(config: RpcConfirmedBlockConfig) -> Self { fn from(config: RpcBlockConfig) -> Self {
RpcEncodingConfigWrapper::Current(Some(config)) RpcEncodingConfigWrapper::Current(Some(config))
} }
} }
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcConfirmedTransactionConfig { pub struct RpcTransactionConfig {
pub encoding: Option<UiTransactionEncoding>, pub encoding: Option<UiTransactionEncoding>,
#[serde(flatten)] #[serde(flatten)]
pub commitment: Option<CommitmentConfig>, pub commitment: Option<CommitmentConfig>,
} }
impl EncodingConfig for RpcConfirmedTransactionConfig { impl EncodingConfig for RpcTransactionConfig {
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self { fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
Self { Self {
encoding: *encoding, encoding: *encoding,
@ -202,16 +213,16 @@ impl EncodingConfig for RpcConfirmedTransactionConfig {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum RpcConfirmedBlocksConfigWrapper { pub enum RpcBlocksConfigWrapper {
EndSlotOnly(Option<Slot>), EndSlotOnly(Option<Slot>),
CommitmentOnly(Option<CommitmentConfig>), CommitmentOnly(Option<CommitmentConfig>),
} }
impl RpcConfirmedBlocksConfigWrapper { impl RpcBlocksConfigWrapper {
pub fn unzip(&self) -> (Option<Slot>, Option<CommitmentConfig>) { pub fn unzip(&self) -> (Option<Slot>, Option<CommitmentConfig>) {
match &self { match &self {
RpcConfirmedBlocksConfigWrapper::EndSlotOnly(end_slot) => (*end_slot, None), RpcBlocksConfigWrapper::EndSlotOnly(end_slot) => (*end_slot, None),
RpcConfirmedBlocksConfigWrapper::CommitmentOnly(commitment) => (None, *commitment), RpcBlocksConfigWrapper::CommitmentOnly(commitment) => (None, *commitment),
} }
} }
} }

View File

@ -0,0 +1,120 @@
#![allow(deprecated)]
use {
crate::rpc_config::{
EncodingConfig, RpcBlockConfig, RpcEncodingConfigWrapper, RpcTransactionConfig,
},
solana_sdk::{clock::Slot, commitment_config::CommitmentConfig},
solana_transaction_status::{TransactionDetails, UiTransactionEncoding},
};
#[deprecated(
since = "1.7.0",
note = "Please use RpcSignaturesForAddressConfig instead"
)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcGetConfirmedSignaturesForAddress2Config {
pub before: Option<String>, // Signature as base-58 string
pub until: Option<String>, // Signature as base-58 string
pub limit: Option<usize>,
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
}
#[deprecated(since = "1.7.0", note = "Please use RpcBlockConfig instead")]
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcConfirmedBlockConfig {
pub encoding: Option<UiTransactionEncoding>,
pub transaction_details: Option<TransactionDetails>,
pub rewards: Option<bool>,
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
}
impl EncodingConfig for RpcConfirmedBlockConfig {
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
Self {
encoding: *encoding,
..Self::default()
}
}
}
impl RpcConfirmedBlockConfig {
pub fn rewards_only() -> Self {
Self {
transaction_details: Some(TransactionDetails::None),
..Self::default()
}
}
pub fn rewards_with_commitment(commitment: Option<CommitmentConfig>) -> Self {
Self {
transaction_details: Some(TransactionDetails::None),
commitment,
..Self::default()
}
}
}
impl From<RpcConfirmedBlockConfig> for RpcEncodingConfigWrapper<RpcConfirmedBlockConfig> {
fn from(config: RpcConfirmedBlockConfig) -> Self {
RpcEncodingConfigWrapper::Current(Some(config))
}
}
impl From<RpcConfirmedBlockConfig> for RpcBlockConfig {
fn from(config: RpcConfirmedBlockConfig) -> Self {
Self {
encoding: config.encoding,
transaction_details: config.transaction_details,
rewards: config.rewards,
commitment: config.commitment,
}
}
}
#[deprecated(since = "1.7.0", note = "Please use RpcTransactionConfig instead")]
#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcConfirmedTransactionConfig {
pub encoding: Option<UiTransactionEncoding>,
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
}
impl EncodingConfig for RpcConfirmedTransactionConfig {
fn new_with_encoding(encoding: &Option<UiTransactionEncoding>) -> Self {
Self {
encoding: *encoding,
..Self::default()
}
}
}
impl From<RpcConfirmedTransactionConfig> for RpcTransactionConfig {
fn from(config: RpcConfirmedTransactionConfig) -> Self {
Self {
encoding: config.encoding,
commitment: config.commitment,
}
}
}
#[deprecated(since = "1.7.0", note = "Please use RpcBlocksConfigWrapper instead")]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RpcConfirmedBlocksConfigWrapper {
EndSlotOnly(Option<Slot>),
CommitmentOnly(Option<CommitmentConfig>),
}
impl RpcConfirmedBlocksConfigWrapper {
pub fn unzip(&self) -> (Option<Slot>, Option<CommitmentConfig>) {
match &self {
RpcConfirmedBlocksConfigWrapper::EndSlotOnly(end_slot) => (*end_slot, None),
RpcConfirmedBlocksConfigWrapper::CommitmentOnly(commitment) => (None, *commitment),
}
}
}

View File

@ -11,20 +11,32 @@ pub enum RpcRequest {
DeregisterNode, DeregisterNode,
GetAccountInfo, GetAccountInfo,
GetBalance, GetBalance,
GetBlock,
GetBlocks,
GetBlocksWithLimit,
GetBlockTime, GetBlockTime,
GetClusterNodes, GetClusterNodes,
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlock instead")]
GetConfirmedBlock, GetConfirmedBlock,
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlocks instead")]
GetConfirmedBlocks, GetConfirmedBlocks,
GetConfirmedBlocksWithLimit,
#[deprecated( #[deprecated(
since = "1.5.19", since = "1.7.0",
note = "Please use RpcRequest::GetConfirmedSignaturesForAddress2 instead" note = "Please use RpcRequest::GetBlocksWithLimit instead"
)]
GetConfirmedBlocksWithLimit,
#[deprecated(
since = "1.7.0",
note = "Please use RpcRequest::GetSignaturesForAddress instead"
)] )]
GetConfirmedSignaturesForAddress,
GetConfirmedSignaturesForAddress2, GetConfirmedSignaturesForAddress2,
#[deprecated(
since = "1.7.0",
note = "Please use RpcRequest::GetTransaction instead"
)]
GetConfirmedTransaction, GetConfirmedTransaction,
GetEpochInfo, GetEpochInfo,
GetEpochSchedule, GetEpochSchedule,
GetFeeCalculatorForBlockhash, GetFeeCalculatorForBlockhash,
@ -47,6 +59,7 @@ pub enum RpcRequest {
GetRecentBlockhash, GetRecentBlockhash,
GetRecentPerformanceSamples, GetRecentPerformanceSamples,
GetSnapshotSlot, GetSnapshotSlot,
GetSignaturesForAddress,
GetSignatureStatuses, GetSignatureStatuses,
GetSlot, GetSlot,
GetSlotLeader, GetSlotLeader,
@ -61,10 +74,7 @@ pub enum RpcRequest {
GetTokenAccountsByDelegate, GetTokenAccountsByDelegate,
GetTokenAccountsByOwner, GetTokenAccountsByOwner,
GetTokenSupply, GetTokenSupply,
GetTransaction,
#[deprecated(since = "1.5.19", note = "Please use RpcRequest::GetSupply instead")]
GetTotalSupply,
GetTransactionCount, GetTransactionCount,
GetVersion, GetVersion,
GetVoteAccounts, GetVoteAccounts,
@ -83,12 +93,14 @@ impl fmt::Display for RpcRequest {
RpcRequest::DeregisterNode => "deregisterNode", RpcRequest::DeregisterNode => "deregisterNode",
RpcRequest::GetAccountInfo => "getAccountInfo", RpcRequest::GetAccountInfo => "getAccountInfo",
RpcRequest::GetBalance => "getBalance", RpcRequest::GetBalance => "getBalance",
RpcRequest::GetBlock => "getBlock",
RpcRequest::GetBlocks => "getBlocks",
RpcRequest::GetBlocksWithLimit => "getBlocksWithLimit",
RpcRequest::GetBlockTime => "getBlockTime", RpcRequest::GetBlockTime => "getBlockTime",
RpcRequest::GetClusterNodes => "getClusterNodes", RpcRequest::GetClusterNodes => "getClusterNodes",
RpcRequest::GetConfirmedBlock => "getConfirmedBlock", RpcRequest::GetConfirmedBlock => "getConfirmedBlock",
RpcRequest::GetConfirmedBlocks => "getConfirmedBlocks", RpcRequest::GetConfirmedBlocks => "getConfirmedBlocks",
RpcRequest::GetConfirmedBlocksWithLimit => "getConfirmedBlocksWithLimit", RpcRequest::GetConfirmedBlocksWithLimit => "getConfirmedBlocksWithLimit",
RpcRequest::GetConfirmedSignaturesForAddress => "getConfirmedSignaturesForAddress",
RpcRequest::GetConfirmedSignaturesForAddress2 => "getConfirmedSignaturesForAddress2", RpcRequest::GetConfirmedSignaturesForAddress2 => "getConfirmedSignaturesForAddress2",
RpcRequest::GetConfirmedTransaction => "getConfirmedTransaction", RpcRequest::GetConfirmedTransaction => "getConfirmedTransaction",
RpcRequest::GetEpochInfo => "getEpochInfo", RpcRequest::GetEpochInfo => "getEpochInfo",
@ -113,6 +125,7 @@ impl fmt::Display for RpcRequest {
RpcRequest::GetRecentBlockhash => "getRecentBlockhash", RpcRequest::GetRecentBlockhash => "getRecentBlockhash",
RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples", RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples",
RpcRequest::GetSnapshotSlot => "getSnapshotSlot", RpcRequest::GetSnapshotSlot => "getSnapshotSlot",
RpcRequest::GetSignaturesForAddress => "getSignaturesForAddress",
RpcRequest::GetSignatureStatuses => "getSignatureStatuses", RpcRequest::GetSignatureStatuses => "getSignatureStatuses",
RpcRequest::GetSlot => "getSlot", RpcRequest::GetSlot => "getSlot",
RpcRequest::GetSlotLeader => "getSlotLeader", RpcRequest::GetSlotLeader => "getSlotLeader",
@ -127,7 +140,7 @@ impl fmt::Display for RpcRequest {
RpcRequest::GetTokenAccountsByDelegate => "getTokenAccountsByDelegate", RpcRequest::GetTokenAccountsByDelegate => "getTokenAccountsByDelegate",
RpcRequest::GetTokenAccountsByOwner => "getTokenAccountsByOwner", RpcRequest::GetTokenAccountsByOwner => "getTokenAccountsByOwner",
RpcRequest::GetTokenSupply => "getTokenSupply", RpcRequest::GetTokenSupply => "getTokenSupply",
RpcRequest::GetTotalSupply => "getTotalSupply", RpcRequest::GetTransaction => "getTransaction",
RpcRequest::GetTransactionCount => "getTransactionCount", RpcRequest::GetTransactionCount => "getTransactionCount",
RpcRequest::GetVersion => "getVersion", RpcRequest::GetVersion => "getVersion",
RpcRequest::GetVoteAccounts => "getVoteAccounts", RpcRequest::GetVoteAccounts => "getVoteAccounts",

View File

@ -25,6 +25,7 @@ use solana_client::{
rpc_cache::LargestAccountsCache, rpc_cache::LargestAccountsCache,
rpc_config::*, rpc_config::*,
rpc_custom_error::RpcCustomError, rpc_custom_error::RpcCustomError,
rpc_deprecated_config::*,
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType}, rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
rpc_request::{ rpc_request::{
TokenAccountsFilter, DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_BLOCKS_RANGE, TokenAccountsFilter, DELINQUENT_VALIDATOR_SLOT_DISTANCE, MAX_GET_CONFIRMED_BLOCKS_RANGE,
@ -423,7 +424,7 @@ impl JsonRpcRequestProcessor {
let first_confirmed_block = if let Ok(Some(first_confirmed_block)) = self.get_block( let first_confirmed_block = if let Ok(Some(first_confirmed_block)) = self.get_block(
first_confirmed_block_in_epoch, first_confirmed_block_in_epoch,
Some(RpcConfirmedBlockConfig::rewards_with_commitment(config.commitment).into()), Some(RpcBlockConfig::rewards_with_commitment(config.commitment).into()),
) { ) {
first_confirmed_block first_confirmed_block
} else { } else {
@ -817,7 +818,7 @@ impl JsonRpcRequestProcessor {
pub fn get_block( pub fn get_block(
&self, &self,
slot: Slot, slot: Slot,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>, config: Option<RpcEncodingConfigWrapper<RpcBlockConfig>>,
) -> Result<Option<UiConfirmedBlock>> { ) -> Result<Option<UiConfirmedBlock>> {
if self.config.enable_rpc_transaction_history { if self.config.enable_rpc_transaction_history {
let config = config let config = config
@ -1171,7 +1172,7 @@ impl JsonRpcRequestProcessor {
pub fn get_transaction( pub fn get_transaction(
&self, &self,
signature: Signature, signature: Signature,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>, config: Option<RpcEncodingConfigWrapper<RpcTransactionConfig>>,
) -> Result<Option<EncodedConfirmedTransaction>> { ) -> Result<Option<EncodedConfirmedTransaction>> {
let config = config let config = config
.map(|config| config.convert_to_current()) .map(|config| config.convert_to_current())
@ -2403,7 +2404,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Slot, slot: Slot,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>, config: Option<RpcEncodingConfigWrapper<RpcBlockConfig>>,
) -> Result<Option<UiConfirmedBlock>>; ) -> Result<Option<UiConfirmedBlock>>;
#[rpc(meta, name = "getBlockTime")] #[rpc(meta, name = "getBlockTime")]
@ -2415,7 +2416,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
start_slot: Slot, start_slot: Slot,
config: Option<RpcConfirmedBlocksConfigWrapper>, config: Option<RpcBlocksConfigWrapper>,
commitment: Option<CommitmentConfig>, commitment: Option<CommitmentConfig>,
) -> Result<Vec<Slot>>; ) -> Result<Vec<Slot>>;
@ -2433,7 +2434,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
signature_str: String, signature_str: String,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>, config: Option<RpcEncodingConfigWrapper<RpcTransactionConfig>>,
) -> Result<Option<EncodedConfirmedTransaction>>; ) -> Result<Option<EncodedConfirmedTransaction>>;
#[rpc(meta, name = "getSignaturesForAddress")] #[rpc(meta, name = "getSignaturesForAddress")]
@ -2441,7 +2442,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
address: String, address: String,
config: Option<RpcGetConfirmedSignaturesForAddress2Config>, config: Option<RpcSignaturesForAddressConfig>,
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>>; ) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>>;
#[rpc(meta, name = "getFirstAvailableBlock")] #[rpc(meta, name = "getFirstAvailableBlock")]
@ -3006,7 +3007,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Slot, slot: Slot,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>, config: Option<RpcEncodingConfigWrapper<RpcBlockConfig>>,
) -> Result<Option<UiConfirmedBlock>> { ) -> Result<Option<UiConfirmedBlock>> {
debug!("get_block rpc request received: {:?}", slot); debug!("get_block rpc request received: {:?}", slot);
meta.get_block(slot, config) meta.get_block(slot, config)
@ -3016,7 +3017,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
start_slot: Slot, start_slot: Slot,
config: Option<RpcConfirmedBlocksConfigWrapper>, config: Option<RpcBlocksConfigWrapper>,
commitment: Option<CommitmentConfig>, commitment: Option<CommitmentConfig>,
) -> Result<Vec<Slot>> { ) -> Result<Vec<Slot>> {
let (end_slot, maybe_commitment) = let (end_slot, maybe_commitment) =
@ -3054,7 +3055,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
signature_str: String, signature_str: String,
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>, config: Option<RpcEncodingConfigWrapper<RpcTransactionConfig>>,
) -> Result<Option<EncodedConfirmedTransaction>> { ) -> Result<Option<EncodedConfirmedTransaction>> {
debug!("get_transaction rpc request received: {:?}", signature_str); debug!("get_transaction rpc request received: {:?}", signature_str);
let signature = verify_signature(&signature_str)?; let signature = verify_signature(&signature_str)?;
@ -3065,7 +3066,7 @@ pub mod rpc_full {
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
address: String, address: String,
config: Option<RpcGetConfirmedSignaturesForAddress2Config>, config: Option<RpcSignaturesForAddressConfig>,
) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> { ) -> Result<Vec<RpcConfirmedTransactionStatusWithSignature>> {
let address = verify_pubkey(address)?; let address = verify_pubkey(address)?;
@ -3205,6 +3206,7 @@ pub mod rpc_full {
// Deprecated RPC methods, collected for easy deactivation and removal in v1.8 // Deprecated RPC methods, collected for easy deactivation and removal in v1.8
pub mod rpc_deprecated_v1_7 { pub mod rpc_deprecated_v1_7 {
#![allow(deprecated)]
use super::*; use super::*;
#[rpc] #[rpc]
pub trait DeprecatedV1_7 { pub trait DeprecatedV1_7 {
@ -3269,7 +3271,7 @@ pub mod rpc_deprecated_v1_7 {
config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>, config: Option<RpcEncodingConfigWrapper<RpcConfirmedBlockConfig>>,
) -> Result<Option<UiConfirmedBlock>> { ) -> Result<Option<UiConfirmedBlock>> {
debug!("get_confirmed_block rpc request received: {:?}", slot); debug!("get_confirmed_block rpc request received: {:?}", slot);
meta.get_block(slot, config) meta.get_block(slot, config.map(|config| config.convert()))
} }
fn get_confirmed_blocks( fn get_confirmed_blocks(
@ -3313,7 +3315,7 @@ pub mod rpc_deprecated_v1_7 {
signature_str signature_str
); );
let signature = verify_signature(&signature_str)?; let signature = verify_signature(&signature_str)?;
meta.get_transaction(signature, config) meta.get_transaction(signature, config.map(|config| config.convert()))
} }
fn get_confirmed_signatures_for_address2( fn get_confirmed_signatures_for_address2(
@ -5593,7 +5595,7 @@ pub mod tests {
let req = format!( let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0,{}]}}"#, r#"{{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0,{}]}}"#,
json!(RpcConfirmedBlockConfig { json!(RpcBlockConfig {
encoding: None, encoding: None,
transaction_details: Some(TransactionDetails::Signatures), transaction_details: Some(TransactionDetails::Signatures),
rewards: Some(false), rewards: Some(false),
@ -5614,7 +5616,7 @@ pub mod tests {
let req = format!( let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0,{}]}}"#, r#"{{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[0,{}]}}"#,
json!(RpcConfirmedBlockConfig { json!(RpcBlockConfig {
encoding: None, encoding: None,
transaction_details: Some(TransactionDetails::None), transaction_details: Some(TransactionDetails::None),
rewards: Some(true), rewards: Some(true),

View File

@ -59,7 +59,7 @@ pub fn calculate_leader_records(
let start_epoch = epoch_schedule.get_epoch(start_slot); let start_epoch = epoch_schedule.get_epoch(start_slot);
let end_epoch = epoch_schedule.get_epoch(end_slot); let end_epoch = epoch_schedule.get_epoch(end_slot);
let confirmed_blocks: HashSet<_> = rpc_client let confirmed_blocks: HashSet<_> = rpc_client
.get_confirmed_blocks(start_slot, Some(end_slot))? .get_blocks(start_slot, Some(end_slot))?
.into_iter() .into_iter()
.collect(); .collect();

View File

@ -290,12 +290,11 @@ fn load_blocks(
start_slot, end_slot start_slot, end_slot
); );
let slots = rpc_client.get_confirmed_blocks(start_slot, Some(end_slot))?; let slots = rpc_client.get_blocks(start_slot, Some(end_slot))?;
let mut blocks = vec![]; let mut blocks = vec![];
for slot in slots.into_iter() { for slot in slots.into_iter() {
let block = let block = rpc_client.get_block_with_encoding(slot, UiTransactionEncoding::Base64)?;
rpc_client.get_confirmed_block_with_encoding(slot, UiTransactionEncoding::Base64)?;
blocks.push((slot, block)); blocks.push((slot, block));
} }
Ok(blocks) Ok(blocks)