@ -207,6 +207,22 @@ impl JsonRpcRequestProcessor {
|
||||
)
|
||||
}
|
||||
|
||||
fn get_fees(&self, commitment: Option<CommitmentConfig>) -> RpcResponse<RpcFees> {
|
||||
let bank = &*self.bank(commitment)?;
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash();
|
||||
let last_valid_slot = bank
|
||||
.get_blockhash_last_valid_slot(&blockhash)
|
||||
.expect("bank blockhash queue should contain blockhash");
|
||||
new_response(
|
||||
bank,
|
||||
RpcFees {
|
||||
blockhash: blockhash.to_string(),
|
||||
fee_calculator,
|
||||
last_valid_slot,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
@ -793,6 +809,13 @@ pub trait RpcSol {
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcBlockhashFeeCalculator>;
|
||||
|
||||
#[rpc(meta, name = "getFees")]
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcFees>;
|
||||
|
||||
#[rpc(meta, name = "getFeeCalculatorForBlockhash")]
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
@ -1126,6 +1149,15 @@ impl RpcSol for RpcSolImpl {
|
||||
.get_recent_blockhash(commitment)
|
||||
}
|
||||
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcFees> {
|
||||
debug!("get_fees rpc request received");
|
||||
meta.request_processor.read().unwrap().get_fees(commitment)
|
||||
}
|
||||
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
@ -1571,6 +1603,7 @@ pub mod tests {
|
||||
get_tmp_ledger_path,
|
||||
};
|
||||
use solana_sdk::{
|
||||
clock::MAX_RECENT_BLOCKHASHES,
|
||||
fee_calculator::DEFAULT_BURN_PERCENT,
|
||||
hash::{hash, Hash},
|
||||
instruction::InstructionError,
|
||||
@ -2517,6 +2550,38 @@ pub mod tests {
|
||||
assert_eq!(expected, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_get_fees() {
|
||||
let bob_pubkey = Pubkey::new_rand();
|
||||
let RpcHandler {
|
||||
io,
|
||||
meta,
|
||||
blockhash,
|
||||
..
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getFees"}"#;
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
"context":{"slot":0},
|
||||
"value":{
|
||||
"blockhash": blockhash.to_string(),
|
||||
"feeCalculator": {
|
||||
"lamportsPerSignature": 0,
|
||||
},
|
||||
"lastValidSlot": MAX_RECENT_BLOCKHASHES,
|
||||
}},
|
||||
"id": 1
|
||||
});
|
||||
let expected: Response =
|
||||
serde_json::from_value(expected).expect("expected response deserialization");
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
assert_eq!(expected, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_get_fee_calculator_for_blockhash() {
|
||||
let bob_pubkey = Pubkey::new_rand();
|
||||
|
Reference in New Issue
Block a user