axon_abi/
lib.rs

1pub mod builder;
2mod image_cell_abi;
3mod light_client_abi;
4mod metadata_abi;
5
6pub mod address;
7
8pub use image_cell_abi::{
9    BlockRollback as CellBlockRollback, BlockUpdate as CellBlockUpdate, CellInfo, OutPoint,
10    RollbackCall as CellRollbackCall, UpdateCall as CellUpdateCall,
11};
12pub use light_client_abi::{
13    Header, RollbackCall as HeaderRollbackCall, SetStateCall, UpdateCall as HeaderUpdateCall,
14};
15
16use ethers::abi::AbiEncode;
17
18use crate::image_cell_abi::ImageCellContractCalls;
19use crate::light_client_abi::CkbLightClientContractCalls;
20
21impl CellUpdateCall {
22    pub fn new(cells: Vec<CellBlockUpdate>) -> Self {
23        Self { blocks: cells }
24    }
25
26    pub fn abi_encode(self) -> Vec<u8> {
27        ImageCellContractCalls::Update(self).encode()
28    }
29}
30
31impl CellRollbackCall {
32    pub fn new(cells: Vec<CellBlockRollback>) -> Self {
33        Self { blocks: cells }
34    }
35
36    pub fn abi_encode(self) -> Vec<u8> {
37        ImageCellContractCalls::Rollback(self).encode()
38    }
39}
40
41impl CellBlockUpdate {
42    pub fn new(block_number: u64, inputs: Vec<OutPoint>, outputs: Vec<CellInfo>) -> Self {
43        Self {
44            block_number,
45            tx_inputs: inputs,
46            tx_outputs: outputs,
47        }
48    }
49}
50
51impl CellBlockRollback {
52    pub fn new(inputs: Vec<OutPoint>, outputs: Vec<OutPoint>) -> Self {
53        Self {
54            tx_inputs:  inputs,
55            tx_outputs: outputs,
56        }
57    }
58}
59
60impl HeaderUpdateCall {
61    pub fn new(headers: Vec<Header>) -> Self {
62        Self { headers }
63    }
64
65    pub fn abi_encode(self) -> Vec<u8> {
66        CkbLightClientContractCalls::Update(self).encode()
67    }
68}
69
70impl HeaderRollbackCall {
71    pub fn new(hashes: Vec<[u8; 32]>) -> Self {
72        Self {
73            block_hashes: hashes,
74        }
75    }
76
77    pub fn abi_encode(self) -> Vec<u8> {
78        CkbLightClientContractCalls::Rollback(self).encode()
79    }
80}
81
82impl SetStateCall {
83    pub fn new(allow_read: bool) -> Self {
84        Self { allow_read }
85    }
86
87    pub fn abi_encode(self) -> Vec<u8> {
88        CkbLightClientContractCalls::SetState(self).encode()
89    }
90}
91
92impl From<ckb_jsonrpc_types::Script> for image_cell_abi::Script {
93    fn from(value: ckb_jsonrpc_types::Script) -> Self {
94        image_cell_abi::Script {
95            code_hash: value.code_hash.0,
96            hash_type: value.hash_type as u8,
97            args:      value.args.into_bytes().into(),
98        }
99    }
100}