tangle_subxt/
field_ext.rs

1use crate::tangle_testnet_runtime::api::runtime_types::{
2	bounded_collections::bounded_vec::BoundedVec,
3	tangle_primitives::services::field::{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			Field::List(ty, _) => FieldType::List(Box::new(ty.clone())),
28			Field::Struct(_, fields) => {
29				let mut type_fields = Vec::with_capacity(fields.0.len());
30				for (_, field) in &fields.0 {
31					type_fields.push(field.field_type());
32				}
33
34				FieldType::Struct(Box::new(BoundedVec(type_fields)))
35			},
36			Field::AccountId(_) => FieldType::AccountId,
37		}
38	}
39}