ic_agent::agent

Trait Transport

source
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§

source

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.

source

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.

source

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.

source

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.

source

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.

Implementations on Foreign Types§

source§

impl<I: Transport + ?Sized> Transport for Box<I>

source§

fn call( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<TransportCallResponse, AgentError>> + Send + '_>>

source§

fn read_state( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn query( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn status( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn read_subnet_state( &self, subnet_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

impl<I: Transport + ?Sized> Transport for Arc<I>

source§

fn call( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<TransportCallResponse, AgentError>> + Send + '_>>

source§

fn read_state( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn query( &self, effective_canister_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn status( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

source§

fn read_subnet_state( &self, subnet_id: Principal, envelope: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AgentError>> + Send + '_>>

Implementors§