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
impl Rpc
Sourcepub fn new(host: impl Into<String>) -> Rpc
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.
Sourcepub fn set_override<F>(&mut self, method: impl Into<String>, f: F)
pub fn set_override<F>(&mut self, method: impl Into<String>, f: F)
Redirects calls to method to a local function instead of the remote
node. The function receives the call’s positional parameters.
Sourcepub fn set_basic_auth(
&mut self,
username: impl Into<String>,
password: impl Into<String>,
)
pub fn set_basic_auth( &mut self, username: impl Into<String>, password: impl Into<String>, )
Sets HTTP basic auth credentials for subsequent requests.
Sourcepub fn lag(&self) -> Duration
pub fn lag(&self) -> Duration
Returns how long this endpoint took to answer eth_blockNumber during
evaluate, or zero if it was never probed.
Sourcepub fn block(&self) -> u64
pub fn block(&self) -> u64
Returns the latest block number observed during
evaluate, or zero if it was never probed.
Sourcepub async fn call(&self, method: &str, params: Vec<Value>) -> Result<Value>
pub async fn call(&self, method: &str, params: Vec<Value>) -> Result<Value>
Performs a request using positional arguments.
Sourcepub async fn call_named(
&self,
method: &str,
params: Map<String, Value>,
) -> Result<Value>
pub async fn call_named( &self, method: &str, params: Map<String, Value>, ) -> Result<Value>
Performs a request using named arguments.
Source§impl Rpc
impl Rpc
Sourcepub async fn forward(
&self,
req: &Request,
opts: &ForwardOptions,
) -> ForwardResponse
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.