Skip to main content

Rpc

Struct Rpc 

Source
pub struct Rpc { /* private fields */ }
Expand description

A connection to an Ethereum JSON-RPC endpoint over HTTP, with optional basic authentication and local method overrides.

Implementations§

Source§

impl Rpc

Source

pub fn new(host: impl Into<String>) -> Rpc

Returns a new RPC client targeting the given endpoint. Pass an empty host to build an override-only handler.

Source

pub fn set_override<F>(&mut self, method: impl Into<String>, f: F)
where F: Fn(&[Value]) -> Result<Value> + Send + Sync + 'static,

Redirects calls to method to a local function instead of the remote node. The function receives the call’s positional parameters.

Source

pub fn set_host(&mut self, host: impl Into<String>)

Sets the host for subsequent requests.

Source

pub fn host(&self) -> &str

Returns the configured host.

Source

pub fn set_basic_auth( &mut self, username: impl Into<String>, password: impl Into<String>, )

Sets HTTP basic auth credentials for subsequent requests.

Source

pub fn lag(&self) -> Duration

Returns how long this endpoint took to answer eth_blockNumber during evaluate, or zero if it was never probed.

Source

pub fn block(&self) -> u64

Returns the latest block number observed during evaluate, or zero if it was never probed.

Source

pub async fn call(&self, method: &str, params: Vec<Value>) -> Result<Value>

Performs a request using positional arguments.

Source

pub async fn call_named( &self, method: &str, params: Map<String, Value>, ) -> Result<Value>

Performs a request using named arguments.

Source

pub async fn call_as<T: DeserializeOwned>( &self, method: &str, params: Vec<Value>, ) -> Result<T>

Performs a request and deserializes the result into T via serde.

Source

pub async fn send(&self, req: &Request) -> Result<Value>

Sends a raw Request to the endpoint and returns the raw result value.

Source§

impl Rpc

Source

pub async fn forward( &self, req: &Request, opts: &ForwardOptions, ) -> ForwardResponse

Builds the response for a JSON-RPC request suitable for proxying back to an HTTP client. Overridden methods are executed locally; otherwise the request is forwarded to the node and its response relayed (with hop-by-hop headers stripped). The returned ForwardResponse is framework-agnostic — write its status, headers, and body to your response object.

Trait Implementations§

Source§

impl Clone for Rpc

Source§

fn clone(&self) -> Rpc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Rpc

Source§

fn default() -> Rpc

Returns the “default value” for a type. Read more
Source§

impl Handler for Rpc

Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, method: &'life1 str, params: Vec<Value>, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Performs a JSON-RPC call with positional parameters.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Rpc

§

impl !UnwindSafe for Rpc

§

impl Freeze for Rpc

§

impl Send for Rpc

§

impl Sync for Rpc

§

impl Unpin for Rpc

§

impl UnsafeUnpin for Rpc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.