1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use async_trait::async_trait;
use ethers_core::{abi::Token, types::Bytes};
use serde::Serialize;
use serde_json::Value;
use std::sync::Arc;

/// RPC Call data.
#[derive(Debug, Clone)]
pub struct RPCCall {
    pub to: String,
    pub data: Bytes,
}

/// RPC Call response with status.
#[derive(Serialize)]
pub struct RPCResponse {
    pub status: u32,
    pub body: Value,
}

#[async_trait]
pub trait CCIPReadHandler {
    /// Closure called by the server.
    ///
    /// # Arguments
    /// * `args` the parsed ABI input parameters
    /// * `req` the RPC call data
    async fn call(
        &self,
        args: Vec<Token>,
        req: RPCCall,
    ) -> Result<Vec<Token>, Box<dyn std::error::Error>>;
}

/// Callback from CCIP-Read server.
#[derive(Debug)]
pub struct HandlerCallback<'a, T: CCIPReadHandler> {
    /// Name of the smart-contract function
    pub name: &'a str,
    /// Closure called by the server
    pub function: Arc<T>,
}

#[derive(Clone, Debug)]
pub struct HandlerDescription<T: CCIPReadHandler> {
    pub name: &'static str,
    pub function: ethers_core::abi::Function,
    pub callback: Arc<T>,
}