From 6cced4d291790f70d7030341704afeca806e5035 Mon Sep 17 00:00:00 2001 From: Justin Litchfield Date: Thu, 12 Jan 2023 04:31:21 -0600 Subject: [PATCH] Send compatible but can't pass the path --- src/lib.rs | 9 +++++---- src/main.rs | 17 +++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c19bd3d..f5f1692 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,15 +12,16 @@ use cln_rpc::{model::{self}, ClnRpc, Request}; use std::sync::{Arc}; pub struct ClnClient { - config: Arc> + pub config: Arc> } impl ClnClient { async fn call(&self, request: Request) -> core::result::Result { - let config = self.config.read().unwrap(); + // let config = self.config.read().unwrap(); - let config_path = &config.rpc_path; - let path = Path::new(config_path); + // let config_path = &config.rpc_path; + // let path = Path::new(config_path); + let path = Path::new("/mnt/lightning/regtest/lightning-rpc"); let mut rpc = ClnRpc::new(path).await?; let response = rpc .call(request.clone()) diff --git a/src/main.rs b/src/main.rs index dcb515d..f714d7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use tokio::{task, time}; use spaz::{load_configuration, Config, Amount, ClnClient}; pub async fn start_handler( - config_holder: &Arc> + config_holder: Arc> ) -> Result { log::info!("Plugin start requested"); let mut guard = config_holder.write().unwrap(); @@ -24,7 +24,7 @@ pub async fn start_handler( } pub async fn stop_handler( - config_holder: &Arc> + config_holder: Arc> ) -> Result { log::info!("Plugin stop requested"); @@ -41,6 +41,7 @@ async fn main() -> Result<(), anyhow::Error> { let start_config_holder = config_holder.clone(); let stop_config_holder = config_holder.clone(); let loop_config_holder = config_holder.clone(); + if let Some(plugin) = Builder::new((), tokio::io::stdin(), tokio::io::stdout()) .option(options::ConfigOption::new( "spaz-on-load", @@ -52,8 +53,8 @@ async fn main() -> Result<(), anyhow::Error> { options::Value::String("lightning-rpc".to_string()), "RPC path for talking to your node", )) - .rpcmethod("start-spazzing", "enables this plugn", move |_p,_v| { start_handler(&start_config_holder.clone()) } ) - .rpcmethod("stop-spazzing", "disables this plugn", move |_p,_v| { stop_handler(&stop_config_holder.clone()) } ) + .rpcmethod("start-spazzing", "enables this plugn", move |_p,_v| { start_handler(start_config_holder.clone()) } ) + .rpcmethod("stop-spazzing", "disables this plugn", move |_p,_v| { stop_handler(stop_config_holder.clone()) } ) .start() .await? @@ -63,17 +64,17 @@ async fn main() -> Result<(), anyhow::Error> { task::spawn(async move { loop { time::sleep(Duration::from_secs( - 1 + 5 )) .await; - log::info!("Spazzzzzzing - config: {:?}", loop_config_holder.read().unwrap()); + log::info!("Spazzing - config: {:?}", loop_config_holder.read().unwrap()); match spaz_out(loop_config_holder.clone()).await { Ok(_) => { log::debug!("Success"); } Err(err) => { - log::warn!("Error spazzing. Proceeding: {:?}", err); + log::warn!("Error spazzing. Continuing: {:?}", err); } }; } @@ -198,7 +199,7 @@ pub async fn spaz_out(config_holder: Arc>) -> Result<(), Error> { if config_holder.read().unwrap().active == false { return Ok(()) } - let client = Arc::new(ClnClient { config: config_holder }); + let client = Arc::new(ClnClient { config: config_holder.clone() }); maybe_keysend_random_channel(client.clone()).await; maybe_disconnect_random_peer(client.clone()).await; maybe_keysend_random_node(client.clone()).await;