generate_chk_snapshots/
generate_chk_snapshots.rs1use std::fs;
5
6use iota_light_client::utils::{
7 CheckpointsList, Config, read_checkpoint_list, sync_checkpoint_list_to_latest,
8};
9use iota_rest_api::Client;
10
11#[tokio::main]
12pub async fn main() {
13 let config: Config = serde_yaml::from_reader(
14 &fs::File::open(format!(
15 "{}/example_config/light_client.yaml",
16 env!("CARGO_MANIFEST_DIR")
17 ))
18 .unwrap(),
19 )
20 .unwrap();
21 sync_checkpoint_list_to_latest(&config).await.unwrap();
22 let checkpoints_list: CheckpointsList = read_checkpoint_list(&config).unwrap();
23
24 let client = Client::new(format!("{}/rest", config.full_node_url));
25 for ckp in checkpoints_list.checkpoints {
26 let summary = client.get_checkpoint_summary(ckp).await.unwrap();
27 serde_json::to_writer_pretty(
28 &mut fs::File::create(format!(
29 "{}/example_config/{ckp}.json",
30 env!("CARGO_MANIFEST_DIR")
31 ))
32 .unwrap(),
33 &summary,
34 )
35 .unwrap();
36 let full = client.get_full_checkpoint(ckp).await.unwrap();
37 serde_json::to_writer_pretty(
38 &mut fs::File::create(format!(
39 "{}/example_config/{ckp}_full.json",
40 env!("CARGO_MANIFEST_DIR")
41 ))
42 .unwrap(),
43 &full,
44 )
45 .unwrap();
46 bcs::serialize_into(
47 &mut fs::File::create(format!(
48 "{}/example_config/{ckp}.chk",
49 env!("CARGO_MANIFEST_DIR")
50 ))
51 .unwrap(),
52 &full,
53 )
54 .unwrap();
55 }
56}