use sphinx-rs glyph types

This commit is contained in:
Evan Feenstra
2022-09-13 16:25:39 -07:00
parent 1577766394
commit 7aa4dd72da
3 changed files with 16 additions and 86 deletions

View File

@@ -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]

View File

@@ -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<String>),
Ota(OtaParams),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ControlResponse {
Nonce(u64),
ResetWifi,
ResetKeys,
ResetAll,
PolicyCurrent(Policy),
PolicyUpdated(Policy),
AllowlistCurrent(Vec<String>),
AllowlistUpdated(Vec<String>),
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<Mutex<dyn ControlPersist>>);

View File

@@ -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<String>) -> 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<Vec<String>>
}
}
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,
}
}