diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 884bf7a..b32596f 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -9,6 +9,7 @@ serde = { version = "1.0", default-features = false } rmp-serde = "1.1.0" serde_bolt = { version = "0.2", default-features = false } sphinx-auther = "0.1.10" +sphinx-glyph = "0.1.0" anyhow = "1" [features] diff --git a/parser/src/control.rs b/parser/src/control.rs index e0a5204..1ef4e84 100644 --- a/parser/src/control.rs +++ b/parser/src/control.rs @@ -1,80 +1,9 @@ use anyhow::Result; -use serde::{Deserialize, Serialize}; use sphinx_auther::nonce; use sphinx_auther::secp256k1::{PublicKey, SecretKey}; +use sphinx_glyph::types::{Config, ControlMessage, ControlResponse, Policy}; use std::sync::{Arc, Mutex}; -#[derive(Serialize, Deserialize, Debug, Clone)] -pub enum ControlMessage { - Nonce, - ResetWifi, - ResetKeys, - ResetAll, - QueryPolicy, - UpdatePolicy(Policy), - QueryAllowlist, - UpdateAllowlist(Vec), - Ota(OtaParams), -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub enum ControlResponse { - Nonce(u64), - ResetWifi, - ResetKeys, - ResetAll, - PolicyCurrent(Policy), - PolicyUpdated(Policy), - AllowlistCurrent(Vec), - AllowlistUpdated(Vec), - OtaConfirm(OtaParams), - Error(String), -} - -#[derive(Clone, Debug, Deserialize, Serialize, Default)] -pub struct Config { - pub broker: String, - pub ssid: String, - pub pass: String, - pub network: String, - // pub seed: [u8; 32], -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct Policy { - pub sat_limit: u64, - pub interval: Interval, - pub htlc_limit: u64, -} - -impl Default for Policy { - fn default() -> Self { - Self { - sat_limit: 1_000_000, - interval: Interval::Daily, - htlc_limit: 1_000_000, - } - } -} - -#[derive(Serialize, Deserialize, Debug, Clone, Copy)] -pub enum Interval { - Hourly, - Daily, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct OtaParams { - pub version: u64, - pub url: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct WifiParams { - pub ssid: String, - pub password: String, -} - // u64 is the nonce. Each signature must have a higher nonce pub struct Controller(SecretKey, PublicKey, u64, Arc>); diff --git a/signer/src/policy.rs b/signer/src/policy.rs index 278161d..56ebe78 100644 --- a/signer/src/policy.rs +++ b/signer/src/policy.rs @@ -9,20 +9,6 @@ use vls_protocol_signer::handler::RootHandler; use vls_protocol_signer::lightning_signer; use vls_protocol_signer::lightning_signer::bitcoin::Network; -fn policy_interval(int: Interval) -> VelocityControlIntervalType { - match int { - Interval::Hourly => VelocityControlIntervalType::Hourly, - Interval::Daily => VelocityControlIntervalType::Daily, - } -} - -pub fn set_policy(root_handler: &RootHandler, network: Network, po: Policy) -> anyhow::Result<()> { - let policy = make_policy(network, &po); - let validator_factory = Arc::new(SimpleValidatorFactory::new_with_policy(policy)); - root_handler.node.set_validator_factory(validator_factory); - Ok(()) -} - pub fn set_allowlist(root_handler: &RootHandler, allowlist: &Vec) -> anyhow::Result<()> { if let Err(e) = root_handler.node.set_allowlist(allowlist) { return Err(anyhow::anyhow!("error setting allowlist {:?}", e)); @@ -37,6 +23,13 @@ pub fn get_allowlist(root_handler: &RootHandler) -> anyhow::Result> } } +pub fn set_policy(root_handler: &RootHandler, network: Network, po: Policy) -> anyhow::Result<()> { + let policy = make_policy(network, &po); + let validator_factory = Arc::new(SimpleValidatorFactory::new_with_policy(policy)); + root_handler.node.set_validator_factory(validator_factory); + Ok(()) +} + pub fn make_policy(network: Network, po: &Policy) -> SimplePolicy { let mut p = make_simple_policy(network); p.max_htlc_value_sat = po.htlc_limit; @@ -48,3 +41,10 @@ pub fn make_policy(network: Network, po: &Policy) -> SimplePolicy { p.global_velocity_control = velocity_spec; p } + +fn policy_interval(int: Interval) -> VelocityControlIntervalType { + match int { + Interval::Hourly => VelocityControlIntervalType::Hourly, + Interval::Daily => VelocityControlIntervalType::Daily, + } +}