registry_distro/
lib.rs

1use maplit::hashmap;
2use std::collections::HashMap;
3use serde_json::{json, Value as JValue};
4
5pub const REGISTRY_WASM: &'static [u8] = include_bytes!("../registry-service/registry.wasm");
6pub const SQLITE_WASM: &'static [u8] = include_bytes!("../registry-service/sqlite3.wasm");
7pub const CONFIG: &'static [u8] = include_bytes!("../registry-service/Config.toml");
8
9pub const REGISTRY_SPELL: &'static str =
10    include_str!("../registry-service/air/spell.spell.air");
11
12pub mod build_info {
13    include!(concat!(env!("OUT_DIR"), "/built.rs"));
14}
15
16pub use build_info::PKG_VERSION as VERSION;
17
18pub fn modules() -> std::collections::HashMap<&'static str, &'static [u8]> {
19    maplit::hashmap! {
20        "sqlite3" => SQLITE_WASM,
21        "registry" => REGISTRY_WASM,
22    }
23}
24
25pub struct DistrSpell {
26    /// AIR script of the spell
27    pub air: &'static str,
28    /// Initial key-value records for spells KV storage
29    pub init_data: HashMap<&'static str, JValue>,
30}
31
32
33#[derive(Debug)]
34pub struct RegistryConfig {
35    pub expired_interval: u32,
36    pub renew_interval: u32,
37    pub replicate_interval: u32
38}
39
40pub fn registry_spell(config: RegistryConfig) -> DistrSpell {
41    DistrSpell {
42        air: REGISTRY_SPELL,
43        init_data: hashmap!{
44            "config" => json!( {
45                "expired_interval": config.expired_interval,
46                "renew_interval": config.renew_interval,
47                "replicate_interval": config.replicate_interval,
48            }),
49        },
50    }
51}