Deprecate FeeCalculator returning APIs (#19120)
This commit is contained in:
@@ -19,6 +19,7 @@ pub enum Source {
|
||||
}
|
||||
|
||||
impl Source {
|
||||
#[deprecated(since = "1.8.0", note = "Please use `get_blockhash` instead")]
|
||||
pub fn get_blockhash_and_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@@ -26,6 +27,7 @@ impl Source {
|
||||
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
#[allow(deprecated)]
|
||||
let res = rpc_client
|
||||
.get_recent_blockhash_with_commitment(commitment)?
|
||||
.value;
|
||||
@@ -39,6 +41,10 @@ impl Source {
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please do not use, will no longer be available in the future"
|
||||
)]
|
||||
pub fn get_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@@ -47,6 +53,7 @@ impl Source {
|
||||
) -> Result<Option<FeeCalculator>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
#[allow(deprecated)]
|
||||
let res = rpc_client
|
||||
.get_fee_calculator_for_blockhash_with_commitment(blockhash, commitment)?
|
||||
.value;
|
||||
@@ -61,6 +68,40 @@ impl Source {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_blockhash(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<Hash, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
let (blockhash, _) = rpc_client.get_latest_blockhash_with_commitment(commitment)?;
|
||||
Ok(blockhash)
|
||||
}
|
||||
Self::NonceAccount(ref pubkey) => {
|
||||
let data = nonce_utils::get_account_with_commitment(rpc_client, pubkey, commitment)
|
||||
.and_then(|ref a| nonce_utils::data_from_account(a))?;
|
||||
Ok(data.blockhash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_blockhash_valid(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
blockhash: &Hash,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
Ok(match self {
|
||||
Self::Cluster => rpc_client.is_blockhash_valid(blockhash, commitment)?,
|
||||
Self::NonceAccount(ref pubkey) => {
|
||||
let _ = nonce_utils::get_account_with_commitment(rpc_client, pubkey, commitment)
|
||||
.and_then(|ref a| nonce_utils::data_from_account(a))?;
|
||||
true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -90,6 +131,7 @@ impl BlockhashQuery {
|
||||
BlockhashQuery::new(blockhash, sign_only, nonce_account)
|
||||
}
|
||||
|
||||
#[deprecated(since = "1.8.0", note = "Please use `get_blockhash` instead")]
|
||||
pub fn get_blockhash_and_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@@ -98,16 +140,36 @@ impl BlockhashQuery {
|
||||
match self {
|
||||
BlockhashQuery::None(hash) => Ok((*hash, FeeCalculator::default())),
|
||||
BlockhashQuery::FeeCalculator(source, hash) => {
|
||||
#[allow(deprecated)]
|
||||
let fee_calculator = source
|
||||
.get_fee_calculator(rpc_client, hash, commitment)?
|
||||
.ok_or(format!("Hash has expired {:?}", hash))?;
|
||||
Ok((*hash, fee_calculator))
|
||||
}
|
||||
BlockhashQuery::All(source) => {
|
||||
BlockhashQuery::All(source) =>
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
source.get_blockhash_and_fee_calculator(rpc_client, commitment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_blockhash(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<Hash, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
BlockhashQuery::None(hash) => Ok(*hash),
|
||||
BlockhashQuery::FeeCalculator(source, hash) => {
|
||||
if !source.is_blockhash_valid(rpc_client, hash, commitment)? {
|
||||
return Err(format!("Hash has expired {:?}", hash).into());
|
||||
}
|
||||
Ok(*hash)
|
||||
}
|
||||
BlockhashQuery::All(source) => source.get_blockhash(rpc_client, commitment),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BlockhashQuery {
|
||||
@@ -282,6 +344,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_blockhash_query_get_blockhash_fee_calc() {
|
||||
let test_blockhash = hash(&[0u8]);
|
||||
let rpc_blockhash = hash(&[1u8]);
|
||||
|
Reference in New Issue
Block a user