@@ -33,23 +33,32 @@ pub enum EthClientError {
3333 /// The Ethereum Address was invalid.
3434 #[ error( "Invalid address: {0}" ) ]
3535 InvalidAddress ( #[ from] alloy:: primitives:: AddressError ) ,
36+
37+ /// No execution engine endpoint was configured.
38+ #[ error( "execution engine endpoint is not set" ) ]
39+ NoExecutionEngineAddr ,
3640}
3741
3842/// Defines the interface for the Ethereum EL RPC client.
39- pub struct EthClient ( DynProvider ) ;
40-
41- impl std:: ops:: Deref for EthClient {
42- type Target = DynProvider ;
43-
44- fn deref ( & self ) -> & DynProvider {
45- & self . 0
46- }
43+ pub enum EthClient {
44+ /// Connected client backed by a live provider.
45+ Connected ( DynProvider ) ,
46+ /// Noop client returned when no address is provided. Mirrors Go's
47+ /// noopClient.
48+ Noop ,
4749}
4850
4951impl EthClient {
50- /// Create a new `EthClient` connected to the given address using defaults
51- /// for retry.
52+ /// Create a new `EthClient`. When `address` is empty a noop client is
53+ /// returned that errors with [`EthClientError::NoExecutionEngineAddr`]
54+ /// if `verify_smart_contract_based_signature` is ever called, matching
55+ /// Go's `NewDefaultEthClientRunner("")` behaviour.
5256 pub async fn new ( address : impl AsRef < str > ) -> Result < EthClient > {
57+ let address = address. as_ref ( ) ;
58+ if address. is_empty ( ) {
59+ return Ok ( EthClient :: Noop ) ;
60+ }
61+
5362 // The maximum number of retries for rate limit errors.
5463 const MAX_RETRY : u32 = 10 ;
5564 // The initial backoff in milliseconds.
@@ -61,12 +70,12 @@ impl EthClient {
6170
6271 let client = ClientBuilder :: default ( )
6372 . layer ( retry_layer)
64- . connect ( address. as_ref ( ) )
73+ . connect ( address)
6574 . await ?;
6675
6776 let provider = ProviderBuilder :: new ( ) . connect_client ( client) ;
6877
69- Ok ( EthClient ( provider. erased ( ) ) )
78+ Ok ( EthClient :: Connected ( provider. erased ( ) ) )
7079 }
7180
7281 /// Check if `sig` is a valid signature of `hash` according to ERC-1271.
@@ -76,12 +85,16 @@ impl EthClient {
7685 hash : [ u8 ; 32 ] ,
7786 sig : & [ u8 ] ,
7887 ) -> Result < bool > {
88+ let EthClient :: Connected ( provider) = self else {
89+ return Err ( EthClientError :: NoExecutionEngineAddr ) ;
90+ } ;
91+
7992 // Magic value defined in [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271).
8093 const MAGIC_VALUE : [ u8 ; 4 ] = [ 0x16 , 0x26 , 0xba , 0x7e ] ;
8194
8295 let address = alloy:: primitives:: Address :: parse_checksummed ( contract_address, None ) ?;
8396
84- let instance = IERC1271 :: new ( address, & self . 0 ) ;
97+ let instance = IERC1271 :: new ( address, provider ) ;
8598
8699 let call = instance
87100 . isValidSignature ( hash. into ( ) , sig. to_vec ( ) . into ( ) )
0 commit comments