|
| 1 | +use std::{collections::BTreeMap, fs}; |
| 2 | + |
| 3 | +use anyhow::Result; |
| 4 | +use rgbstd::{ |
| 5 | + interface::{LIB_ID_RGB20, LIB_ID_RGB21, LIB_ID_RGB25}, |
| 6 | + stl::{LIB_ID_RGB, LIB_ID_RGB_CONTRACT, LIB_ID_RGB_STD}, |
| 7 | +}; |
| 8 | +use serde::{Deserialize, Serialize}; |
| 9 | + |
| 10 | +type IdVersionMap = BTreeMap<String, String>; |
| 11 | + |
| 12 | +#[allow(non_snake_case)] |
| 13 | +#[derive(Deserialize, Serialize)] |
| 14 | +struct LibIds { |
| 15 | + LIB_ID_RGB: IdVersionMap, |
| 16 | + LIB_ID_RGB20: IdVersionMap, |
| 17 | + LIB_ID_RGB21: IdVersionMap, |
| 18 | + LIB_ID_RGB25: IdVersionMap, |
| 19 | + LIB_ID_RGB_CONTRACT: IdVersionMap, |
| 20 | + LIB_ID_RGB_STD: IdVersionMap, |
| 21 | +} |
| 22 | + |
| 23 | +const LIB_IDS_FILE: &str = "RGB_LIB_IDs.toml"; |
| 24 | +const NOTE_COMMENT: &str = |
| 25 | + "# Auto-generated semantic IDs for RGB consensus-critical libraries and their corresponding versions of bitmask-core.\n\n"; |
| 26 | + |
| 27 | +fn main() -> Result<()> { |
| 28 | + const BMC_VERSION: &str = env!("CARGO_PKG_VERSION"); |
| 29 | + |
| 30 | + let lib_ids_file = fs::read_to_string(LIB_IDS_FILE)?; |
| 31 | + let mut lib_ids: LibIds = toml::from_str(&lib_ids_file)?; |
| 32 | + |
| 33 | + lib_ids |
| 34 | + .LIB_ID_RGB |
| 35 | + .entry(LIB_ID_RGB.to_owned()) |
| 36 | + .or_insert(BMC_VERSION.to_owned()); |
| 37 | + |
| 38 | + lib_ids |
| 39 | + .LIB_ID_RGB20 |
| 40 | + .entry(LIB_ID_RGB20.to_owned()) |
| 41 | + .or_insert(BMC_VERSION.to_owned()); |
| 42 | + |
| 43 | + lib_ids |
| 44 | + .LIB_ID_RGB21 |
| 45 | + .entry(LIB_ID_RGB21.to_owned()) |
| 46 | + .or_insert(BMC_VERSION.to_owned()); |
| 47 | + |
| 48 | + lib_ids |
| 49 | + .LIB_ID_RGB25 |
| 50 | + .entry(LIB_ID_RGB25.to_owned()) |
| 51 | + .or_insert(BMC_VERSION.to_owned()); |
| 52 | + |
| 53 | + lib_ids |
| 54 | + .LIB_ID_RGB_CONTRACT |
| 55 | + .entry(LIB_ID_RGB_CONTRACT.to_owned()) |
| 56 | + .or_insert(BMC_VERSION.to_owned()); |
| 57 | + |
| 58 | + lib_ids |
| 59 | + .LIB_ID_RGB_STD |
| 60 | + .entry(LIB_ID_RGB_STD.to_owned()) |
| 61 | + .or_insert(BMC_VERSION.to_owned()); |
| 62 | + |
| 63 | + let toml = toml::to_string(&lib_ids)?; |
| 64 | + fs::write(LIB_IDS_FILE, format!("{NOTE_COMMENT}{toml}"))?; |
| 65 | + |
| 66 | + Ok(()) |
| 67 | +} |
0 commit comments