1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4pub type AccessControlConditionItem = ControlConditionItem<JsonAccessControlCondition>;
5pub type SolRpcConditionItem = ControlConditionItem<SolRpcConditionV2Options>;
6pub type UnifiedAccessControlConditionItem = ControlConditionItem<UnifiedAccessControlCondition>;
7pub type EVMContractConditionItem = ControlConditionItem<EVMContractCondition>;
8pub type CosmosConditionItem = ControlConditionItem<CosmosCondition>;
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase", untagged)]
12pub enum ControlConditionItem<T> {
13 Condition(T),
14 Operator(JsonAccessControlConditionOperator),
15 Group(Vec<ControlConditionItem<T>>),
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19#[serde(rename_all = "camelCase", untagged)]
20#[allow(clippy::enum_variant_names)]
21pub enum UnifiedAccessControlCondition {
22 JsonAccessControlCondition(JsonAccessControlCondition),
23 SolRpcCondition(SolRpcConditionV2Options),
24 EVMContractCondition(EVMContractCondition),
25 CosmosCondition(CosmosCondition),
26}
27
28#[derive(Clone, Debug, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct SolRpcConditionV2Options {
31 pub method: String,
32 pub params: Vec<serde_json::Value>,
33 pub pda_params: Option<Vec<String>>,
34 pub pda_interface: Option<SolPdaInterface>,
35 pub pda_key: Option<String>,
36 pub chain: String,
37 pub return_value_test: JsonReturnValueTestV2,
38}
39
40#[derive(Clone, Debug, Serialize, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub struct SolRpcConditionV2 {
43 pub method: String,
44 pub params: Vec<serde_json::Value>,
45 pub pda_params: Vec<String>,
46 pub pda_interface: SolPdaInterface,
47 pub pda_key: String,
48 pub chain: String,
49 pub return_value_test: JsonReturnValueTestV2,
50}
51
52#[derive(Clone, Debug, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54pub struct SolRpcCondition {
55 pub method: String,
56 pub params: Vec<serde_json::Value>,
57 pub chain: String,
58 pub return_value_test: JsonReturnValueTestV2,
59}
60
61#[derive(Clone, Debug, Serialize, Deserialize)]
62#[serde(rename_all = "camelCase")]
63pub struct SolPdaInterface {
64 pub offset: usize,
65 pub fields: HashMap<String, usize>,
66}
67
68#[derive(Clone, Debug, Serialize, Deserialize)]
69#[serde(rename_all = "camelCase", untagged)]
70pub enum SolRpcConditionItemV0 {
71 Condition(SolRpcCondition),
72 Operator(JsonAccessControlConditionOperator),
73 Group(Vec<SolRpcConditionItem>),
74}
75
76#[derive(Clone, Debug, Serialize, Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct EVMContractCondition {
79 pub contract_address: String,
80 pub function_name: String,
81 pub function_params: Vec<String>,
82 pub function_abi: ethabi::Function,
83 pub chain: String,
84 pub return_value_test: JsonReturnValueTestV2,
85}
86
87#[derive(Clone, Debug, Serialize, Deserialize)]
88#[serde(rename_all = "camelCase")]
89pub struct JsonAccessControlCondition {
90 pub contract_address: String,
91 pub chain: String,
92 pub standard_contract_type: String,
93 pub method: String,
94 pub parameters: Vec<String>,
95 pub return_value_test: JsonReturnValueTest,
96}
97
98#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct JsonAccessControlConditionOperator {
101 pub operator: AccessControlBooleanOperator,
102}
103
104#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
105#[serde(rename_all = "camelCase")]
106pub enum AccessControlBooleanOperator {
107 And,
108 Or,
109}
110
111impl std::fmt::Display for AccessControlBooleanOperator {
112 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
113 match self {
114 AccessControlBooleanOperator::And => write!(f, "AND"),
115 AccessControlBooleanOperator::Or => write!(f, "OR"),
116 }
117 }
118}
119
120#[derive(Clone, Debug, Serialize, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct CosmosCondition {
123 pub path: String,
124 pub chain: String,
125 pub method: Option<String>,
126 pub parameters: Option<Vec<String>>,
127 pub return_value_test: JsonReturnValueTestV2,
128}
129
130#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
131#[serde(rename_all = "camelCase")]
132pub struct CosmosBlock {
133 #[serde(rename = "block_id")]
134 pub block_id: CosmosBlockId,
135 pub block: CosmosBlockBlock,
136 #[serde(rename = "sdk_block")]
137 pub sdk_block: CosmosBlockSdkBlock,
138}
139
140#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
141#[serde(rename_all = "camelCase")]
142pub struct CosmosBlockId {
143 pub hash: String,
144 #[serde(rename = "part_set_header")]
145 pub part_set_header: CosmosPartSetHeader,
146}
147
148#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct CosmosPartSetHeader {
151 pub total: i64,
152 pub hash: String,
153}
154
155#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
156#[serde(rename_all = "camelCase")]
157pub struct CosmosBlockData {
158 pub txs: Vec<serde_json::Value>,
159}
160
161#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
162#[serde(rename_all = "camelCase")]
163pub struct CosmosBlockEvidence {
164 pub evidence: Vec<serde_json::Value>,
165}
166
167#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
168#[serde(rename_all = "camelCase")]
169pub struct CosmosBlockLastCommit {
170 pub height: String,
171 pub round: i64,
172 #[serde(rename = "block_id")]
173 pub block_id: CosmosBlockId,
174 pub signatures: Vec<CosmosBlockSignature>,
175}
176
177#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
178#[serde(rename_all = "camelCase")]
179pub struct CosmosBlockSignature {
180 #[serde(rename = "block_id_flag")]
181 pub block_id_flag: String,
182 #[serde(rename = "validator_address")]
183 pub validator_address: Option<String>,
184 pub timestamp: String,
185 pub signature: Option<String>,
186}
187
188#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
189#[serde(rename_all = "camelCase")]
190pub struct CosmosBlockSdkBlock {
191 pub header: CosmosBlockHeader,
192 pub data: CosmosBlockData,
193 pub evidence: CosmosBlockEvidence,
194 #[serde(rename = "last_commit")]
195 pub last_commit: CosmosBlockLastCommit,
196}
197
198#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
199#[serde(rename_all = "camelCase")]
200pub struct CosmosBlockBlock {
201 pub header: CosmosBlockHeader,
202 pub data: CosmosBlockData,
203 pub evidence: CosmosBlockEvidence,
204 #[serde(rename = "last_commit")]
205 pub last_commit: CosmosBlockLastCommit,
206}
207
208#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
209#[serde(rename_all = "camelCase")]
210pub struct CosmosBlockHeader {
211 pub version: Version,
212 #[serde(rename = "chain_id")]
213 pub chain_id: String,
214 pub height: String,
215 pub time: String,
216 #[serde(rename = "last_block_id")]
217 pub last_block_id: CosmosBlockId,
218 #[serde(rename = "last_commit_hash")]
219 pub last_commit_hash: String,
220 #[serde(rename = "data_hash")]
221 pub data_hash: String,
222 #[serde(rename = "validators_hash")]
223 pub validators_hash: String,
224 #[serde(rename = "next_validators_hash")]
225 pub next_validators_hash: String,
226 #[serde(rename = "consensus_hash")]
227 pub consensus_hash: String,
228 #[serde(rename = "app_hash")]
229 pub app_hash: String,
230 #[serde(rename = "last_results_hash")]
231 pub last_results_hash: String,
232 #[serde(rename = "evidence_hash")]
233 pub evidence_hash: String,
234 #[serde(rename = "proposer_address")]
235 pub proposer_address: String,
236}
237
238#[derive(Clone, Debug, Serialize, Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub struct JsonReturnValueTest {
241 pub comparator: String,
242 pub value: String,
243}
244
245#[derive(Clone, Debug, Serialize, Deserialize)]
246#[serde(rename_all = "camelCase")]
247pub struct JsonReturnValueTestV2 {
248 pub key: String,
249 pub comparator: String,
250 pub value: String,
251}
252#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
253#[serde(rename_all = "camelCase")]
254pub struct Version {
255 pub block: String,
256 pub app: String,
257}