pub trait Transport: Send + Sync {
// Required methods
fn call(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<TransportCallResponse, AgentError>> + Send + '_>>;
fn read_state(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>;
fn read_subnet_state(
&self,
subnet_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>;
fn query(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>;
fn status(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>;
}
Expand description
A facade that connects to a Replica and does requests. These requests can be of any type (does not have to be HTTP). This trait is to inverse the control from the Agent over its connection code, and to resolve any direct dependencies to tokio or HTTP code from this crate.
An implementation of this trait for HTTP transport is implemented using Reqwest, with the
feature flag reqwest
. This might be deprecated in the future.
Any error returned by these methods will bubble up to the code that called the Agent.
Required Methods§
sourcefn call(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<TransportCallResponse, AgentError>> + Send + '_>>
fn call( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<TransportCallResponse, AgentError>> + Send + '_>>
Sends a synchronous call request to a replica.
This normally corresponds to the /api/v3/canister/<effective_canister_id>/call
endpoint.
sourcefn read_state(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
fn read_state( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
Sends a synchronous request to a replica. This call includes the body of the request message itself (envelope).
This normally corresponds to the /api/v2/canister/<effective_canister_id>/read_state
endpoint.
sourcefn read_subnet_state(
&self,
subnet_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
fn read_subnet_state( &self, subnet_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
Sends a synchronous request to a replica. This call includes the body of the request message itself (envelope).
This normally corresponds to the /api/v2/subnet/<subnet_id>/read_state
endpoint.
sourcefn query(
&self,
effective_canister_id: Principal,
envelope: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
fn query( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
Sends a synchronous request to a replica. This call includes the body of the request message itself (envelope).
This normally corresponds to the /api/v2/canister/<effective_canister_id>/query
endpoint.
sourcefn status(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
fn status( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>
Sends a status request to the replica, returning whatever the replica returns. In the current spec v2, this is a CBOR encoded status message, but we are not making this API attach semantics to the response.