ccip_read_server/
types.rs

1use async_trait::async_trait;
2use ethers_core::{abi::Token, types::Bytes};
3use serde::Serialize;
4use serde_json::Value;
5use std::sync::Arc;
6
7/// RPC Call data.
8#[derive(Debug, Clone)]
9pub struct RPCCall {
10    pub to: String,
11    pub data: Bytes,
12}
13
14/// RPC Call response with status.
15#[derive(Serialize)]
16pub struct RPCResponse {
17    pub status: u32,
18    pub body: Value,
19}
20
21#[async_trait]
22pub trait CCIPReadHandler {
23    /// Closure called by the server.
24    ///
25    /// # Arguments
26    /// * `args` the parsed ABI input parameters
27    /// * `req` the RPC call data
28    async fn call(
29        &self,
30        args: Vec<Token>,
31        req: RPCCall,
32    ) -> Result<Vec<Token>, Box<dyn std::error::Error>>;
33}
34
35/// Callback from CCIP-Read server.
36#[derive(Debug)]
37pub struct HandlerCallback<'a, T: CCIPReadHandler> {
38    /// Name of the smart-contract function
39    pub name: &'a str,
40    /// Closure called by the server
41    pub function: Arc<T>,
42}
43
44#[derive(Clone, Debug)]
45pub struct HandlerDescription<T: CCIPReadHandler> {
46    pub name: &'static str,
47    pub function: ethers_core::abi::Function,
48    pub callback: Arc<T>,
49}