ac_node_api/metadata/
print_metadata.rs

1/*
2	Copyright 2021 Integritee AG and Supercomputing Systems AG
3	Licensed under the Apache License, Version 2.0 (the "License");
4	you may not use this file except in compliance with the License.
5	You may obtain a copy of the License at
6		http://www.apache.org/licenses/LICENSE-2.0
7	Unless required by applicable law or agreed to in writing, software
8	distributed under the License is distributed on an "AS IS" BASIS,
9	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10	See the License for the specific language governing permissions and
11	limitations under the License.
12*/
13
14use crate::metadata::{Metadata, PalletMetadata};
15
16impl Metadata {
17	pub fn print_overview(&self) {
18		let mut string = String::new();
19		for pallet in self.pallets() {
20			string.push_str(pallet.name());
21			string.push('\n');
22			for storage in pallet.storage() {
23				string.push_str(" s  ");
24				string.push_str(&storage.name);
25				string.push('\n');
26			}
27
28			if let Some(call_variants) = pallet.call_variants() {
29				for call in call_variants {
30					string.push_str(" c  ");
31					string.push_str(&call.name);
32					string.push('\n');
33				}
34			}
35
36			for constant in pallet.constants() {
37				string.push_str(" cst  ");
38				string.push_str(&constant.name);
39				string.push('\n');
40			}
41
42			if let Some(events) = pallet.event_variants() {
43				for event in events {
44					string.push_str(" e  ");
45					string.push_str(&event.name);
46					string.push('\n');
47				}
48			}
49
50			if let Some(errors) = pallet.error_variants() {
51				for error in errors {
52					string.push_str(" err  ");
53					string.push_str(&error.name);
54					string.push('\n');
55				}
56			}
57		}
58
59		println!("{string}");
60	}
61
62	pub fn print_pallets(&self) {
63		for pallet in self.pallets() {
64			pallet.print()
65		}
66	}
67
68	pub fn print_pallets_with_calls(&self) {
69		for pallet in self.pallets() {
70			pallet.print_calls();
71		}
72	}
73	pub fn print_pallets_with_constants(&self) {
74		for pallet in self.pallets() {
75			pallet.print_constants();
76		}
77	}
78	pub fn print_pallet_with_storages(&self) {
79		for pallet in self.pallets() {
80			pallet.print_storages();
81		}
82	}
83
84	pub fn print_pallets_with_events(&self) {
85		for pallet in self.pallets() {
86			pallet.print_events();
87		}
88	}
89
90	pub fn print_pallets_with_errors(&self) {
91		for pallet in self.pallets() {
92			pallet.print_errors();
93		}
94	}
95}
96
97impl PalletMetadata<'_> {
98	pub fn print(&self) {
99		println!("----------------- Pallet: '{}' -----------------\n", self.name());
100		println!("Pallet id: {}", self.index());
101	}
102
103	pub fn print_calls(&self) {
104		println!("----------------- Calls for Pallet: {} -----------------\n", self.name());
105		if let Some(variants) = self.call_variants() {
106			for variant in variants {
107				println!("Name: {}, index {}", variant.name, variant.index);
108			}
109		};
110		println!();
111	}
112
113	pub fn print_constants(&self) {
114		println!("----------------- Constants for Pallet: {} -----------------\n", self.name());
115		for constant in self.constants() {
116			println!("Name: {}, Type {:?}, Value {:?}", constant.name, constant.ty, constant.value);
117		}
118		println!();
119	}
120	pub fn print_storages(&self) {
121		println!("----------------- Storages for Pallet: {} -----------------\n", self.name());
122		for storage in self.storage() {
123			println!(
124				"Name: {}, Modifier: {:?}, Type {:?}, Default {:?}",
125				storage.name, storage.modifier, storage.ty, storage.default
126			);
127		}
128		println!();
129	}
130
131	pub fn print_events(&self) {
132		println!("----------------- Events for Pallet: {} -----------------\n", self.name());
133		if let Some(variants) = self.event_variants() {
134			for variant in variants {
135				println!("Name: {}", variant.name);
136				println!("Field: {:?}", variant.fields);
137				println!("Docs: {:?}", variant.docs);
138				println!();
139			}
140		};
141		println!();
142	}
143
144	pub fn print_errors(&self) {
145		println!("----------------- Errors for Pallet: {} -----------------\n", self.name());
146		if let Some(variants) = self.error_variants() {
147			for variant in variants {
148				println!("Name: {}", variant.name);
149				println!("Docs: {:?}", variant.docs);
150				println!();
151			}
152		};
153		println!();
154	}
155}