RPC: Add getFeeCalculatorForBlockhash method call (#8687)

Returns the `FeeCalculator` associated with the given blockhash, or
`null` if said blockhash has expired
This commit is contained in:
Trent Nelson
2020-03-06 17:01:31 -07:00
committed by GitHub
parent 3eb00ef60f
commit 4db074a5aa
9 changed files with 184 additions and 6 deletions

View File

@@ -6,8 +6,8 @@ use crate::{
rpc_request::RpcRequest,
rpc_response::{
Response, RpcAccount, RpcBlockhashFeeCalculator, RpcConfirmedBlock, RpcContactInfo,
RpcEpochInfo, RpcFeeRateGovernor, RpcIdentity, RpcKeyedAccount, RpcLeaderSchedule,
RpcResponse, RpcVersionInfo, RpcVoteAccountStatus,
RpcEpochInfo, RpcFeeCalculator, RpcFeeRateGovernor, RpcIdentity, RpcKeyedAccount,
RpcLeaderSchedule, RpcResponse, RpcVersionInfo, RpcVoteAccountStatus,
},
};
use bincode::serialize;
@@ -839,6 +839,35 @@ impl RpcClient {
})
}
pub fn get_fee_calculator_for_blockhash(
&self,
blockhash: &Hash,
) -> io::Result<Option<FeeCalculator>> {
let response = self
.client
.send(
&RpcRequest::GetFeeCalculatorForBlockhash,
json!([blockhash.to_string()]),
0,
)
.map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("GetFeeCalculatorForBlockhash request failure: {:?}", e),
)
})?;
let Response { value, .. } = serde_json::from_value::<Response<Option<RpcFeeCalculator>>>(
response,
)
.map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("GetFeeCalculatorForBlockhash parse failure: {:?}", e),
)
})?;
Ok(value.map(|rf| rf.fee_calculator))
}
pub fn get_fee_rate_governor(&self) -> RpcResponse<FeeRateGovernor> {
let response = self
.client