forked from alloy-rs/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: ProviderCall (alloy-rs#788)
* feature: ProviderCall fix: rename to prov_call for disambiguation * refactor: replace output types * doc: add note about fn pointers * feat: convert `EthCall` to `ProviderCall` * use `ClientRef` in EthCall instead of `WeakClient` * change lifetimes * add *_internal methods that return `EthCall` * doc nits * use `ClientRef` instead of `WeakClient` in `RpcWithBlock` * Revert "use `ClientRef` instead of `WeakClient` in `RpcWithBlock`" This reverts commit 569d168. * feat: RpcCallWithBlock enum val in provider call * nits * feat: integrate `RpcWithBlock` into `ProviderCall` * rm `RpcWithBlock` val from ProviderCall * feat(provider): caller trait for with_block calls * rm `WeakClient` from `RpcWithBlock` * introduce `Caller` into `RpcWithBlock` * use `WithBlockCall` in `RpcWithBlock`. polling doesn't work. * nit * feat(provider): add `WithBlockFut` - polls `ProviderCall` and maps response. * nit * revert 2ff402 * Revert "feat: convert `EthCall` to `ProviderCall`" This reverts commit 1cb1579. * doc nits * feat(provider): introduce `Caller` to `EthCall`. Arc it so that its cloneable * feat(provider): add `EthCaller` - converts EthCall into ProviderCall and strengthen test * update `EthCallFut` * holds `ProviderCall` * removes Clone * impl poll_preparing and poll_running on `EthCallFut` instead of `EthCallFutInner` * poll `ProviderCall` in `EthCall`using `EthCaller` * removes WeakClient from `EthCall` * updates `EthCallFutInner::Running` to store map * nit * wrap Caller in Arc to make `RpcWithBlock` cloneable * store in `ProvideCall` fut instance in `States` * store `ProviderCall` fut in `EthCallFutInner` * feat(provider): add `ParamsWithBlock` for `RpcWithBlock` * rm `block_id` from `Caller` trait * impl `Caller` for `WeakClient` * refactor(`ProviderCall`): don't rely on `Caller` in `RpcWithBlock` (alloy-rs#1159) * feat: RpcCall:map_params * WithBlockInner * Ready variant * fmt * use ProviderCall * clippy + fmt * add From<F> * make ProviderCall::Ready return a result * add docs * Update request.rs Co-authored-by: DaniPopes <[email protected]> * fmt --------- Co-authored-by: DaniPopes <[email protected]> * refac(provider): use `ProviderCall` as return in trait * nit * doc nits * fix --------- Co-authored-by: Yash Atreya <[email protected]> Co-authored-by: Arsenii Kulikov <[email protected]> Co-authored-by: DaniPopes <[email protected]>
- Loading branch information
Showing
13 changed files
with
770 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::ProviderCall; | ||
use alloy_json_rpc::{RpcParam, RpcReturn}; | ||
use alloy_rpc_client::WeakClient; | ||
use alloy_transport::{RpcError, Transport, TransportErrorKind, TransportResult}; | ||
use std::borrow::Cow; | ||
|
||
// TODO: Make `EthCall` specific. Ref: https://github.com/alloy-rs/alloy/pull/788#discussion_r1748862509. | ||
|
||
/// Trait that helpes convert `EthCall` into a `ProviderCall`. | ||
pub trait Caller<T, Params, Resp>: Send + Sync | ||
where | ||
T: Transport + Clone, | ||
Params: RpcParam, | ||
Resp: RpcReturn, | ||
{ | ||
/// Method that needs to be implemented to convert to a `ProviderCall`. | ||
/// | ||
/// This method handles serialization of the params and sends the request to relevant data | ||
/// source and returns a `ProviderCall`. | ||
fn call( | ||
&self, | ||
method: Cow<'static, str>, | ||
params: Params, | ||
) -> TransportResult<ProviderCall<T, serde_json::Value, Resp>>; | ||
} | ||
|
||
impl<T, Params, Resp> Caller<T, Params, Resp> for WeakClient<T> | ||
where | ||
T: Transport + Clone, | ||
Params: RpcParam, | ||
Resp: RpcReturn, | ||
{ | ||
fn call( | ||
&self, | ||
method: Cow<'static, str>, | ||
params: Params, | ||
) -> TransportResult<ProviderCall<T, serde_json::Value, Resp>> { | ||
let client = self.upgrade().ok_or_else(TransportErrorKind::backend_gone)?; | ||
|
||
// serialize the params | ||
let ser = serde_json::to_value(params).map_err(RpcError::ser_err)?; | ||
|
||
let rpc_call = client.request(method, ser); | ||
|
||
Ok(ProviderCall::RpcCall(rpc_call)) | ||
} | ||
} |
Oops, something went wrong.