Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Middleware Architecture #68

Closed
gakonst opened this issue Sep 20, 2020 · 1 comment
Closed

Middleware Architecture #68

gakonst opened this issue Sep 20, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@gakonst
Copy link
Owner

gakonst commented Sep 20, 2020

Is your feature request related to a problem? Please describe.

So far, we're adding plugins to the Client / Provider by adding optional variables (e.g. Signer, ENS, Gas Oracle, Nonce Manager). Instead, we could have a trait Client which would require implementing all JSON-RPC methods. Then, each time you want to write a plug-in, you would implement the method you need (e.g. for ENS methods, you'd resolve to/from from names to addresses) and then you'd pass the data to the same function in the next level (e.g. self.inner.send_transaction). This seems straightforward to do with 2 exceptions

  1. It is cumbersome to have to re-implement every trait method when creating wrapper structs. It'd be nice if we can have some smart way (e.g. a macro) which does trait delegation. Unfortuntely, due to using
  2. Error handling: We cannot have a variant in a thiserror like InnerError(#[from] I::Error) because it potentially allows for a recursive type.

Describe the solution you'd like

A middleware-based architecture for sending RPC requests which allows creating new middleware wrappers "easily", ideally w/o having to write a lot of boilerplate which does delegation to each inner layer manually.

Then, we'd be able to do:

let provider = Provider::new("http://localhost:8545");
let provider = SignerMiddleware::new("privateKey", provider);
let provider = NonceManagerMiddleware::new(provider);
let provider = GasEscalatorMiddleware::new(provider);
let provider = EnsMiddleware::new(provider);

...and so on

Describe alternatives you've considered

So far, I've tried implementing this here: #65.

@gakonst gakonst added the enhancement New feature or request label Sep 20, 2020
@gakonst
Copy link
Owner Author

gakonst commented Sep 24, 2020

Fixed in #65

@gakonst gakonst closed this as completed Sep 24, 2020
meetmangukiya pushed a commit to meetmangukiya/ethers-rs that referenced this issue Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant