@@ -13,7 +13,9 @@ use candid::Nat;
1313use canhttp:: http:: json:: JsonRpcRequest ;
1414use canhttp:: multi:: { ReductionError , Timestamp } ;
1515use ethers_core:: { types:: Transaction , utils:: rlp} ;
16- use evm_rpc_types:: { Hex , Hex32 , MultiRpcResult , Nat256 , RpcError , RpcResult , ValidationError } ;
16+ use evm_rpc_types:: {
17+ BlockTag , GetLogsArgs , Hex , Hex32 , MultiRpcResult , Nat256 , RpcError , RpcResult , ValidationError ,
18+ } ;
1719
1820fn process_result < T > (
1921 method : impl Into < MetricRpcMethod > + Clone ,
@@ -71,23 +73,6 @@ impl CandidRpcClient {
7173 max_block_range : u32 ,
7274 ) -> MultiRpcResult < Vec < evm_rpc_types:: LogEntry > > {
7375 use crate :: candid_rpc:: cketh_conversion:: { from_log_entries, into_get_logs_param} ;
74-
75- if let (
76- Some ( evm_rpc_types:: BlockTag :: Number ( from) ) ,
77- Some ( evm_rpc_types:: BlockTag :: Number ( to) ) ,
78- ) = ( & args. from_block , & args. to_block )
79- {
80- let from = Nat :: from ( from. clone ( ) ) ;
81- let to = Nat :: from ( to. clone ( ) ) ;
82- let block_count = if to > from { to - from } else { from - to } ;
83- if block_count > max_block_range {
84- return MultiRpcResult :: Consistent ( Err ( ValidationError :: Custom ( format ! (
85- "Requested {} blocks; limited to {} when specifying a start and end block" ,
86- block_count, max_block_range
87- ) )
88- . into ( ) ) ) ;
89- }
90- }
9176 process_result (
9277 RpcMethod :: EthGetLogs ,
9378 self . client . eth_get_logs ( into_get_logs_param ( args) ) . await ,
@@ -97,7 +82,7 @@ impl CandidRpcClient {
9782
9883 pub async fn eth_get_block_by_number (
9984 & self ,
100- block : evm_rpc_types :: BlockTag ,
85+ block : BlockTag ,
10186 ) -> MultiRpcResult < evm_rpc_types:: Block > {
10287 use crate :: candid_rpc:: cketh_conversion:: { from_block, into_block_spec} ;
10388 process_result (
@@ -208,3 +193,21 @@ fn get_transaction_hash(raw_signed_transaction_hex: &Hex) -> Option<Hex32> {
208193 let transaction: Transaction = rlp:: decode ( raw_signed_transaction_hex. as_ref ( ) ) . ok ( ) ?;
209194 Some ( Hex32 :: from ( transaction. hash . 0 ) )
210195}
196+
197+ pub fn validate_get_logs_block_range ( args : & GetLogsArgs , max_block_range : u32 ) -> RpcResult < ( ) > {
198+ if let ( Some ( BlockTag :: Number ( from) ) , Some ( BlockTag :: Number ( to) ) ) =
199+ ( & args. from_block , & args. to_block )
200+ {
201+ let from = Nat :: from ( from. clone ( ) ) ;
202+ let to = Nat :: from ( to. clone ( ) ) ;
203+ let block_count = if to > from { to - from } else { from - to } ;
204+ if block_count > max_block_range {
205+ return Err ( ValidationError :: Custom ( format ! (
206+ "Requested {} blocks; limited to {} when specifying a start and end block" ,
207+ block_count, max_block_range
208+ ) )
209+ . into ( ) ) ;
210+ }
211+ }
212+ Ok ( ( ) )
213+ }
0 commit comments