Skip to content

Commit

Permalink
Send compatible but can't pass the path
Browse files Browse the repository at this point in the history
  • Loading branch information
litch committed Jan 12, 2023
1 parent ae6f502 commit 6cced4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use cln_rpc::{model::{self}, ClnRpc, Request};
use std::sync::{Arc};

pub struct ClnClient {
config: Arc<RwLock<Config>>
pub config: Arc<RwLock<Config>>
}

impl ClnClient {
async fn call(&self, request: Request) -> core::result::Result<String, Error> {
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())
Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio::{task, time};
use spaz::{load_configuration, Config, Amount, ClnClient};

pub async fn start_handler(
config_holder: &Arc<RwLock<Config>>
config_holder: Arc<RwLock<Config>>
) -> Result<serde_json::Value, Error> {
log::info!("Plugin start requested");
let mut guard = config_holder.write().unwrap();
Expand All @@ -24,7 +24,7 @@ pub async fn start_handler(
}

pub async fn stop_handler(
config_holder: &Arc<RwLock<Config>>
config_holder: Arc<RwLock<Config>>
) -> Result<serde_json::Value, Error> {
log::info!("Plugin stop requested");

Expand All @@ -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",
Expand All @@ -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?
Expand All @@ -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);
}
};
}
Expand Down Expand Up @@ -198,7 +199,7 @@ pub async fn spaz_out(config_holder: Arc<RwLock<Config>>) -> 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;
Expand Down

0 comments on commit 6cced4d

Please sign in to comment.