generate_checkpoint_snapshots/
generate_checkpoint_snapshots.rs1use std::{fs, path::PathBuf};
5
6use iota_light_client::{checkpoint::sync_checkpoint_list_to_latest, config::Config};
7use iota_rest_api::Client;
8use tracing::info;
9
10const FIXTURES_DIR: &str = "tests/fixtures";
11
12#[tokio::main]
13pub async fn main() {
14 env_logger::init();
15
16 let config = Config {
17 rpc_url: "http://localhost:9000".parse().unwrap(),
18 graphql_url: Some("http://localhost:9125".parse().unwrap()),
19 checkpoints_dir: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(FIXTURES_DIR),
20 genesis_blob_download_url: None,
21 sync_before_check: false,
22 checkpoint_store_config: None,
23 archive_store_config: None,
24 };
25 config.validate().expect("invalid config");
26
27 let checkpoint_list = sync_checkpoint_list_to_latest(&config)
28 .await
29 .expect("failed to sync checkpoint list");
30
31 if checkpoint_list.len() < 2 {
32 panic!("not enough checkpoints to sync")
33 }
34
35 let client = Client::new(format!("{}/rest", config.rpc_url));
36
37 for seq in checkpoint_list.checkpoints().iter().copied().take(2) {
39 info!("Downloading full and summary checkpoint: {seq}");
40
41 let summary = client
42 .get_checkpoint_summary(seq)
43 .await
44 .expect("error downloading checkpoint summary");
45
46 let full = client
47 .get_full_checkpoint(seq)
48 .await
49 .expect("error downloading full checkpoint");
50
51 bcs::serialize_into(
52 &mut fs::File::create(format!("{}/{seq}.sum", config.checkpoints_dir.display()))
53 .expect("error creating file"),
54 &summary,
55 )
56 .expect("error serializing summary checkpoint to bcs");
57
58 bcs::serialize_into(
59 &mut fs::File::create(format!("{}/{seq}.chk", config.checkpoints_dir.display()))
60 .expect("error creating file"),
61 &full,
62 )
63 .expect("error serializing full checkpoint to bcs");
64 }
65}