ctrl tester: read json file

This commit is contained in:
Evan Feenstra
2022-10-11 18:03:12 -07:00
parent 105b6c009f
commit e5412e23bd
2 changed files with 17 additions and 10 deletions

7
tester/cmd.json Normal file
View File

@@ -0,0 +1,7 @@
{
"type": "Ota",
"content": {
"url": "http://192.168.1.10/sphinx-update-",
"version": 0
}
}

View File

@@ -1,6 +1,6 @@
use dotenv::dotenv;
use serde::{Deserialize, Serialize};
use sphinx_key_parser::control::{ControlMessage, Controller, OtaParams};
use sphinx_key_parser::control::{ControlMessage, Controller};
use sphinx_key_signer::lightning_signer::bitcoin::Network;
use std::env;
use std::time::Duration;
@@ -25,16 +25,16 @@ async fn main() -> anyhow::Result<()> {
let seed = hex::decode(seed_string).expect("yo");
let mut ctrl = controller_from_seed(&Network::Regtest, &seed, nonce);
let version_string: String = env::var("VERSION").unwrap_or("0".to_string());
let version: u64 = version_string.parse::<u64>().expect("failed to parse version");
let ota_url: String = env::var("OTA_URL").unwrap_or("http://192.168.1.10/sphinx-update-".to_string());
let control_message = ControlMessage::Ota(OtaParams {
version: version,
url: ota_url
});
let mut command = ControlMessage::Nonce;
if let Ok(cmd_content) = std::fs::read_to_string("./tester/cmd.json") {
if let Ok(cmd) = serde_json::from_str::<ControlMessage>(&cmd_content) {
command = cmd;
}
}
//let msg = ctrl.build_msg(control_message)?;
let msg = ctrl.build_msg(ControlMessage::Nonce)?;
println!("COMMAND! {:?}", command);
let msg = ctrl.build_msg(command)?;
let msg_hex = hex::encode(&msg);
let client = reqwest::Client::builder()