mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
tester ctrl configurable nonce and url
This commit is contained in:
@@ -5,7 +5,7 @@ use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
||||
use std::env;
|
||||
use std::time::Duration;
|
||||
|
||||
const URL: &str = "http://localhost:8000/api";
|
||||
const DEFAULT_URL: &str = "http://localhost:8000/api";
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct EcdhBody {
|
||||
@@ -16,9 +16,14 @@ pub struct EcdhBody {
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv().ok();
|
||||
|
||||
let nonce_string: String = env::var("NONCE").unwrap_or("0".to_string());
|
||||
let nonce: u64 = nonce_string.parse::<u64>().expect("failed to parse nonce");
|
||||
|
||||
let broker_url: String = env::var("BROKER_URL").unwrap_or(DEFAULT_URL.to_string());
|
||||
|
||||
let seed_string: String = env::var("SEED").expect("no seed");
|
||||
let seed = hex::decode(seed_string).expect("yo");
|
||||
let mut ctrl = controller_from_seed(&Network::Regtest, &seed);
|
||||
let mut ctrl = controller_from_seed(&Network::Regtest, &seed, nonce);
|
||||
|
||||
let msg = ctrl.build_msg(ControlMessage::Nonce)?;
|
||||
let msg_hex = hex::encode(&msg);
|
||||
@@ -29,7 +34,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
.expect("couldnt build reqwest client");
|
||||
|
||||
let res = client
|
||||
.post(format!("{}/control?msg={}", URL, msg_hex))
|
||||
.post(format!("{}/control?msg={}", broker_url, msg_hex))
|
||||
.header("Content-Type", "application/json")
|
||||
.send()
|
||||
.await?;
|
||||
@@ -43,7 +48,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn controller_from_seed(network: &Network, seed: &[u8]) -> Controller {
|
||||
pub fn controller_from_seed(network: &Network, seed: &[u8], nonce: u64) -> Controller {
|
||||
let (pk, sk) = sphinx_key_signer::derive_node_keys(network, seed);
|
||||
Controller::new(sk, pk, 0)
|
||||
Controller::new(sk, pk, nonce)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user