tangle_subxt/
field_ext.rs

1use crate::tangle_testnet_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec;
2use crate::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::field::{
3	Field, FieldType,
4};
5use subxt_core::utils::AccountId32;
6
7pub trait FieldExt {
8	fn field_type(&self) -> FieldType;
9}
10
11impl FieldExt for Field<AccountId32> {
12	fn field_type(&self) -> FieldType {
13		match self {
14			Field::Optional(ty, _) => FieldType::Optional(Box::new(ty.clone())),
15			Field::Bool(_) => FieldType::Bool,
16			Field::Uint8(_) => FieldType::Uint8,
17			Field::Int8(_) => FieldType::Int8,
18			Field::Uint16(_) => FieldType::Uint16,
19			Field::Int16(_) => FieldType::Int16,
20			Field::Uint32(_) => FieldType::Uint32,
21			Field::Int32(_) => FieldType::Int32,
22			Field::Uint64(_) => FieldType::Uint64,
23			Field::Int64(_) => FieldType::Int64,
24			Field::String(_) => FieldType::String,
25			Field::Array(ty, values) => {
26				FieldType::Array(values.0.len() as u64, Box::new(ty.clone()))
27			},
28			Field::List(ty, _) => FieldType::List(Box::new(ty.clone())),
29			Field::Struct(_, fields) => {
30				let mut type_fields = Vec::with_capacity(fields.0.len());
31				for (_, field) in &fields.0 {
32					type_fields.push(field.field_type());
33				}
34
35				FieldType::Struct(Box::new(BoundedVec(type_fields)))
36			},
37			Field::AccountId(_) => FieldType::AccountId,
38		}
39	}
40}