Exth.Rpc.Call (Exth v0.4.2)
View SourceRepresents a chain of RPC calls that can be executed in sequence or as a batch.
This module provides a fluent API for making RPC calls, allowing you to chain multiple requests together before executing them. The calls can be executed either as individual requests or as a batch request.
Fields
client
- The RPC client used to make the requestsrequests
- List of requests to be executed
Examples
# Create a new call chain
call = Call.new(client)
# Add requests to the chain
call
|> Call.add_request("eth_blockNumber", [])
|> Call.add_request("eth_getBalance", ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"])
# Get the list of requests
requests = Call.get_requests(call)
# => [
# %Request{method: "eth_blockNumber", params: [], id: 1},
# %Request{method: "eth_getBalance", params: ["0x742d...", "latest"], id: 2}
# ]
# Get the associated client
client = Call.get_client(call)
# => %Client{...}
Summary
Functions
Adds a new request to the call chain.
Returns the client associated with this call chain.
Returns the list of requests in the call chain.
Creates a new RpcCall with the given client.
Types
@type t() :: %Exth.Rpc.Call{ client: Exth.Rpc.Client.t(), requests: [Exth.Rpc.Request.t()] }
Functions
@spec add_request(t(), Exth.Rpc.Types.method(), Exth.Rpc.Types.params()) :: t()
Adds a new request to the call chain.
Parameters
call
- The call chain to add the request tomethod
- The RPC method name (string or atom)params
- List of parameters for the method
Returns
- A new
Call
struct with the request added to the chain
Examples
call
|> Call.add_request("eth_blockNumber", [])
|> Call.add_request("eth_getBalance", ["0x742d...", "latest"])
@spec get_client(t()) :: Exth.Rpc.Client.t()
Returns the client associated with this call chain.
Parameters
call
- The call chain to get the client from
Returns
- The
Client
struct associated with the call chain
Examples
client = Call.get_client(call)
# => %Client{...}
@spec get_requests(t()) :: [Exth.Rpc.Request.t()]
Returns the list of requests in the call chain.
Parameters
call
- The call chain to get requests from
Returns
- A list of
Request
structs
Examples
requests = Call.get_requests(call)
# => [
# %Request{method: "eth_blockNumber", params: [], id: 1},
# %Request{method: "eth_getBalance", params: ["0x742d...", "latest"], id: 2}
# ]
@spec new(Exth.Rpc.Client.t()) :: t()
Creates a new RpcCall with the given client.
Parameters
client
- The RPC client to use for making requests
Returns
- A new
Call
struct with the given client and an empty list of requests
Examples
client = %Client{...}
call = Call.new(client)
# => %Call{client: client, requests: []}