Skip to main content

blvm_sdk/composition/
schema.rs

1//! Composition Configuration Schema
2//!
3//! Schema validation for node composition configuration.
4
5use crate::composition::config::NodeConfig;
6use crate::composition::types::*;
7
8/// Validate node configuration schema
9pub fn validate_config_schema(config: &NodeConfig) -> Result<ValidationResult> {
10    let mut errors = Vec::new();
11    let mut warnings = Vec::new();
12
13    // Validate node metadata
14    if config.node.name.is_empty() {
15        errors.push("Node name cannot be empty".to_string());
16    }
17
18    if !["mainnet", "testnet", "regtest"].contains(&config.node.network.as_str()) {
19        errors.push(format!(
20            "Invalid network type: {}. Must be one of: mainnet, testnet, regtest",
21            config.node.network
22        ));
23    }
24
25    // Validate modules
26    for (name, module_cfg) in &config.modules {
27        if module_cfg.enabled {
28            if name.is_empty() {
29                errors.push("Module name cannot be empty".to_string());
30            }
31
32            // Warn if version not specified
33            if module_cfg.version.is_none() {
34                warnings.push(format!(
35                    "Module '{name}' does not specify version, will use latest available"
36                ));
37            }
38        }
39    }
40
41    let valid = errors.is_empty();
42    Ok(ValidationResult {
43        valid,
44        errors,
45        warnings,
46        dependencies: Vec::new(), // Will be populated during dependency resolution
47    })
48}