aztec_core/abi/
checkers.rs1use super::types::{AbiType, FunctionArtifact};
2
3pub fn is_address_struct(typ: &AbiType) -> bool {
5 is_aztec_address_struct(typ) || is_eth_address_struct(typ)
6}
7
8pub fn is_aztec_address_struct(typ: &AbiType) -> bool {
10 matches!(typ, AbiType::Struct { name, .. } if name.ends_with("address::AztecAddress"))
11}
12
13pub fn is_eth_address_struct(typ: &AbiType) -> bool {
15 matches!(typ, AbiType::Struct { name, .. } if name.ends_with("address::EthAddress"))
16}
17
18pub fn is_function_selector_struct(typ: &AbiType) -> bool {
20 matches!(typ, AbiType::Struct { name, .. }
21 if name.ends_with("function_selector::FunctionSelector"))
22}
23
24pub fn is_wrapped_field_struct(typ: &AbiType) -> bool {
26 matches!(typ, AbiType::Struct { fields, .. }
27 if fields.len() == 1
28 && fields[0].name == "inner"
29 && fields[0].typ == AbiType::Field)
30}
31
32pub fn is_public_keys_struct(typ: &AbiType) -> bool {
34 matches!(typ, AbiType::Struct { name, fields, .. }
35 if name.ends_with("public_keys::PublicKeys")
36 && fields.len() == 4
37 && fields[0].name == "npk_m"
38 && fields[1].name == "ivpk_m"
39 && fields[2].name == "ovpk_m"
40 && fields[3].name == "tpk_m")
41}
42
43pub fn is_bounded_vec_struct(typ: &AbiType) -> bool {
45 matches!(typ, AbiType::Struct { name, fields, .. }
46 if name.ends_with("bounded_vec::BoundedVec")
47 && fields.len() == 2
48 && fields[0].name == "storage"
49 && fields[1].name == "len")
50}
51
52pub fn is_option_struct(typ: &AbiType) -> bool {
54 matches!(typ, AbiType::Struct { name, fields, .. }
55 if name.ends_with("option::Option")
56 && fields.len() == 2
57 && fields[0].name == "_is_some"
58 && fields[1].name == "_value")
59}
60
61pub fn abi_type_size(typ: &AbiType) -> usize {
63 match typ {
64 AbiType::Field | AbiType::Boolean | AbiType::Integer { .. } => 1,
65 AbiType::String { length } => *length,
66 AbiType::Array { element, length } => length * abi_type_size(element),
67 AbiType::Struct { fields, .. } => fields.iter().map(|f| abi_type_size(&f.typ)).sum(),
68 AbiType::Tuple { elements } => elements.iter().map(abi_type_size).sum(),
69 }
70}
71
72pub fn count_arguments_size(function: &FunctionArtifact) -> usize {
74 function
75 .parameters
76 .iter()
77 .map(|p| abi_type_size(&p.typ))
78 .sum()
79}