-
Notifications
You must be signed in to change notification settings - Fork 329
[Feature] Allow custom implementation for Provider methods #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
enhancement
New feature or request
Comments
my current preferred implementation is to add an |
Sketch implementation #[pin_project::pin_project(project = ProviderCallProj)]
pub enum ProviderCall<Conn, Params, Resp, Output = Resp, Map = fn(Resp) -> Output>
where
Conn: Transport + Clone,
Params: RpcParam,
Map: Fn(Resp) -> Output,
{
TransportCall(TransportRpc<Conn, Params, Resp, Output, Map>),
Waiter {
waiter: Waiter<Resp>,
#[pin]
map: Map,
},
Other(Pin<Box<dyn Future<Output = TransportResult<Output>> + Send>>),
Ready(Option<Output>),
}
impl<Conn, Params, Resp, Output, Map> Future for ProviderCall<Conn, Params, Resp, Output, Map>
where
Conn: Transport + Clone,
Params: RpcParam,
Resp: RpcReturn,
Output: 'static,
Map: Fn(Resp) -> Output,
{
type Output = TransportResult<Output>;
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
match self.as_mut().project() {
ProviderCallProj::TransportCall(call) => call.poll_unpin(cx),
ProviderCallProj::Waiter { waiter, map } => match waiter.poll_unpin(cx) {
Ready(Ok(resp)) => Ready(Ok(map(resp))),
Ready(Err(e)) => Ready(Err(e)),
_ => task::Poll::Pending,
},
ProviderCallProj::Other(fut) => fut.poll_unpin(cx),
ProviderCallProj::Ready(output) => {
Ready(Ok(output.take().expect("output taken twice")))
}
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component
provider, pubsub, transports
Describe the feature you would like
Looking at the new
eth_call
implementation, it looks likeProvider
functions will now returnRpcCall
or a wrapper around it (likeEthCall
).The previous implementation returned raw values, making it possible to implement the
Provider
trait on your own provider and override methods to execute your own logic (reading from database instead of using JSON-RPC transport in my case) because the returned values had no ties toTransport
.What I ask is to maintain the possibility of executing arbitrary code in
Provider
methods. This can maybe be achieved by making theProvider
methods return an enum which can either hold an RpcCall or a CustomCall, the later containing a future not depending on theTransport
trait.Additional context
No response
The text was updated successfully, but these errors were encountered: