@@ -2393,33 +2393,78 @@ impl RpcMethod<2> for EthGetTransactionCount {
23932393 ( sender, block_param) : Self :: Params ,
23942394 ) -> Result < Self :: Ok , ServerError > {
23952395 let addr = sender. to_filecoin_address ( ) ?;
2396- if let BlockNumberOrHash :: PredefinedBlock ( ref predefined) = block_param
2397- && * predefined == Predefined :: Pending
2398- {
2399- return Ok ( EthUint64 ( ctx. mpool . get_sequence ( & addr) ?) ) ;
2396+ match block_param {
2397+ BlockNumberOrHash :: PredefinedBlock ( Predefined :: Pending ) => {
2398+ Ok ( EthUint64 ( ctx. mpool . get_sequence ( & addr) ?) )
2399+ }
2400+ _ => {
2401+ let ts = tipset_by_block_number_or_hash (
2402+ ctx. chain_store ( ) ,
2403+ block_param,
2404+ ResolveNullTipset :: TakeOlder ,
2405+ ) ?;
2406+ eth_get_transaction_count ( & ctx, & ts, addr) . await
2407+ }
24002408 }
2401- let ts = tipset_by_block_number_or_hash (
2402- ctx. chain_store ( ) ,
2403- block_param. clone ( ) ,
2404- ResolveNullTipset :: TakeOlder ,
2405- ) ?;
2409+ }
2410+ }
24062411
2407- let ( state_cid, _) = ctx. state_manager . tipset_state ( & ts) . await ?;
2412+ pub enum EthGetTransactionCountV2 { }
2413+ impl RpcMethod < 2 > for EthGetTransactionCountV2 {
2414+ const NAME : & ' static str = "Filecoin.EthGetTransactionCount" ;
2415+ const NAME_ALIAS : Option < & ' static str > = Some ( "eth_getTransactionCount" ) ;
2416+ const PARAM_NAMES : [ & ' static str ; 2 ] = [ "sender" , "blockParam" ] ;
2417+ const API_PATHS : BitFlags < ApiPaths > = make_bitflags ! ( ApiPaths :: V2 ) ;
2418+ const PERMISSION : Permission = Permission :: Read ;
2419+
2420+ type Params = ( EthAddress , ExtBlockNumberOrHash ) ;
2421+ type Ok = EthUint64 ;
24082422
2409- let state = StateTree :: new_from_root ( ctx. store_owned ( ) , & state_cid) ?;
2410- let actor = state. get_required_actor ( & addr) ?;
2411- if is_evm_actor ( & actor. code ) {
2412- let evm_state = evm:: State :: load ( ctx. store ( ) , actor. code , actor. state ) ?;
2413- if !evm_state. is_alive ( ) {
2414- return Ok ( EthUint64 ( 0 ) ) ;
2423+ async fn handle (
2424+ ctx : Ctx < impl Blockstore + Send + Sync + ' static > ,
2425+ ( sender, block_param) : Self :: Params ,
2426+ ) -> Result < Self :: Ok , ServerError > {
2427+ let addr = sender. to_filecoin_address ( ) ?;
2428+ match block_param {
2429+ ExtBlockNumberOrHash :: PredefinedBlock ( ExtPredefined :: Pending ) => {
2430+ Ok ( EthUint64 ( ctx. mpool . get_sequence ( & addr) ?) )
2431+ }
2432+ _ => {
2433+ let ts = tipset_by_block_number_or_hash_v2 (
2434+ & ctx,
2435+ block_param,
2436+ ResolveNullTipset :: TakeOlder ,
2437+ )
2438+ . await ?;
2439+ eth_get_transaction_count ( & ctx, & ts, addr) . await
24152440 }
2416- Ok ( EthUint64 ( evm_state. nonce ( ) ) )
2417- } else {
2418- Ok ( EthUint64 ( actor. sequence ) )
24192441 }
24202442 }
24212443}
24222444
2445+ async fn eth_get_transaction_count < B > (
2446+ ctx : & Ctx < B > ,
2447+ ts : & Tipset ,
2448+ addr : FilecoinAddress ,
2449+ ) -> Result < EthUint64 , ServerError >
2450+ where
2451+ B : Blockstore + Send + Sync + ' static ,
2452+ {
2453+ let ( state_cid, _) = ctx. state_manager . tipset_state ( ts) . await ?;
2454+
2455+ let state = StateTree :: new_from_root ( ctx. store_owned ( ) , & state_cid) ?;
2456+ let actor = state. get_required_actor ( & addr) ?;
2457+ if is_evm_actor ( & actor. code ) {
2458+ let evm_state = evm:: State :: load ( ctx. store ( ) , actor. code , actor. state ) ?;
2459+ if !evm_state. is_alive ( ) {
2460+ return Ok ( EthUint64 ( 0 ) ) ;
2461+ }
2462+ Ok ( EthUint64 ( evm_state. nonce ( ) ) )
2463+ } else {
2464+ Ok ( EthUint64 ( actor. sequence ) )
2465+ }
2466+ }
2467+
24232468pub enum EthMaxPriorityFeePerGas { }
24242469impl RpcMethod < 0 > for EthMaxPriorityFeePerGas {
24252470 const NAME : & ' static str = "Filecoin.EthMaxPriorityFeePerGas" ;
0 commit comments