diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..9e2662a --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,4 @@ +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +imports_layout = "HorizontalVertical" +unstable_features = true diff --git a/src/main.rs b/src/main.rs index 121d71e..ebfa79a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,10 @@ use std::{path::Path, time::Duration}; use anyhow::anyhow; use cln_plugin::{ options::{ConfigOption, DefaultBooleanConfigOption, StringArrayConfigOption}, - Builder, Plugin, + Builder, + Plugin, }; use cln_rpc::{model::requests::ListdatastoreRequest, ClnRpc}; - use nostr_sdk::nips::nip47; use nwc::run_nwc; use nwc_notifications::{payment_received_handler, payment_sent_handler}; diff --git a/src/nwc.rs b/src/nwc.rs index 1ba7172..b06b02b 100644 --- a/src/nwc.rs +++ b/src/nwc.rs @@ -1,44 +1,45 @@ -use std::borrow::Cow; -use std::time::Duration; +use std::{borrow::Cow, time::Duration}; -use crate::nwc_balance::get_balance_response; -use crate::nwc_hold::{ - cancel_hold_invoice_response, make_hold_invoice_response, settle_hold_invoice_response, -}; -use crate::nwc_info::get_info_response; -use crate::nwc_invoice::make_invoice_response; -use crate::nwc_keysend::{multi_pay_keysend, pay_keysend_response}; -use crate::nwc_lookups::{list_transactions_response, lookup_invoice_response}; -use crate::nwc_pay::{multi_pay_invoice, pay_invoice_response}; -use crate::structs::{NwcStore, PluginState}; -use crate::tasks::budget_task; -use crate::util::{build_capabilities, build_notifications_vec, is_read_only_nwc}; -use crate::OPT_NOTIFICATIONS; use anyhow::anyhow; use cln_plugin::Plugin; -use nostr_sdk::client; -use nostr_sdk::nips::nip04; -use nostr_sdk::nips::nip44; -use nostr_sdk::nips::nip47; -use nostr_sdk::nostr::Filter; -use nostr_sdk::nostr::Kind; -use nostr_sdk::nostr::Tag; -use nostr_sdk::Alphabet; -use nostr_sdk::Client; -use nostr_sdk::Event; -use nostr_sdk::EventBuilder; -use nostr_sdk::EventId; -use nostr_sdk::Keys; -use nostr_sdk::PublicKey; -use nostr_sdk::RelayPoolNotification; -use nostr_sdk::RelayStatus; -use nostr_sdk::SecretKey; -use nostr_sdk::SignerError; -use nostr_sdk::SingleLetterTag; -use nostr_sdk::TagKind; -use nostr_sdk::Timestamp; -use tokio::sync::oneshot; -use tokio::time; +use nostr_sdk::{ + client, + nips::{nip04, nip44, nip47}, + nostr::{Filter, Kind, Tag}, + Alphabet, + Client, + Event, + EventBuilder, + EventId, + Keys, + PublicKey, + RelayPoolNotification, + RelayStatus, + SecretKey, + SignerError, + SingleLetterTag, + TagKind, + Timestamp, +}; +use tokio::{sync::oneshot, time}; + +use crate::{ + nwc_balance::get_balance_response, + nwc_hold::{ + cancel_hold_invoice_response, + make_hold_invoice_response, + settle_hold_invoice_response, + }, + nwc_info::get_info_response, + nwc_invoice::make_invoice_response, + nwc_keysend::{multi_pay_keysend, pay_keysend_response}, + nwc_lookups::{list_transactions_response, lookup_invoice_response}, + nwc_pay::{multi_pay_invoice, pay_invoice_response}, + structs::{NwcStore, PluginState}, + tasks::budget_task, + util::{build_capabilities, build_notifications_vec, is_read_only_nwc}, + OPT_NOTIFICATIONS, +}; pub async fn run_nwc( plugin: Plugin, diff --git a/src/nwc_hold.rs b/src/nwc_hold.rs index e0c34a8..e048d0c 100644 --- a/src/nwc_hold.rs +++ b/src/nwc_hold.rs @@ -1,7 +1,7 @@ use cln_plugin::Plugin; +use nostr_sdk::nips::nip47; use crate::structs::PluginState; -use nostr_sdk::nips::nip47; pub async fn make_hold_invoice_response( _plugin: Plugin, diff --git a/src/nwc_info.rs b/src/nwc_info.rs index 4b844b2..050edf3 100644 --- a/src/nwc_info.rs +++ b/src/nwc_info.rs @@ -1,10 +1,12 @@ use cln_plugin::Plugin; use cln_rpc::model::requests::GetinfoRequest; - -use crate::structs::PluginState; -use crate::util::{build_methods_vec, build_notifications_vec, is_read_only_nwc, load_nwc_store}; use nostr_sdk::nips::nip47; +use crate::{ + structs::PluginState, + util::{build_methods_vec, build_notifications_vec, is_read_only_nwc, load_nwc_store}, +}; + pub async fn get_info_response( plugin: Plugin, label: &str, diff --git a/src/nwc_lookups.rs b/src/nwc_lookups.rs index 8b3a491..33bea1f 100644 --- a/src/nwc_lookups.rs +++ b/src/nwc_lookups.rs @@ -5,14 +5,16 @@ use cln_rpc::{ model::{ requests::{DecodeRequest, ListinvoicesRequest, ListpaysRequest}, responses::{ - ListinvoicesInvoices, ListinvoicesInvoicesStatus, ListpaysPays, ListpaysPaysStatus, + ListinvoicesInvoices, + ListinvoicesInvoicesStatus, + ListpaysPays, + ListpaysPaysStatus, }, }, primitives::Sha256, ClnRpc, }; -use nostr_sdk::nips::nip47; -use nostr_sdk::Timestamp; +use nostr_sdk::{nips::nip47, Timestamp}; use crate::structs::{PluginState, NOT_INV_ERR}; diff --git a/src/nwc_notifications.rs b/src/nwc_notifications.rs index 82a3c0b..7fcea01 100644 --- a/src/nwc_notifications.rs +++ b/src/nwc_notifications.rs @@ -2,23 +2,31 @@ use std::str::FromStr; use anyhow::anyhow; use cln_plugin::Plugin; -use cln_rpc::model::requests::{DecodeRequest, ListinvoicesRequest, ListpaysRequest}; -use cln_rpc::model::responses::{ - DecodeResponse, ListinvoicesInvoices, ListinvoicesInvoicesStatus, ListpaysPays, - ListpaysPaysStatus, +use cln_rpc::{ + model::{ + requests::{DecodeRequest, ListinvoicesRequest, ListpaysRequest}, + responses::{ + DecodeResponse, + ListinvoicesInvoices, + ListinvoicesInvoicesStatus, + ListpaysPays, + ListpaysPaysStatus, + }, + }, + primitives::Sha256, + ClnRpc, +}; +use nostr_sdk::{ + nips::nip47, + nostr::{key::PublicKey, EventBuilder, Kind, Tag}, + Client, + Timestamp, }; -use cln_rpc::primitives::Sha256; -use cln_rpc::ClnRpc; -use crate::structs::{PluginState, NOT_INV_ERR}; -use crate::OPT_NOTIFICATIONS; - -use nostr_sdk::nips::nip47; -use nostr_sdk::nostr::key::PublicKey; -use nostr_sdk::nostr::EventBuilder; -use nostr_sdk::nostr::Kind; -use nostr_sdk::nostr::Tag; -use nostr_sdk::{Client, Timestamp}; +use crate::{ + structs::{PluginState, NOT_INV_ERR}, + OPT_NOTIFICATIONS, +}; pub async fn payment_received_handler( plugin: Plugin, diff --git a/src/nwc_pay.rs b/src/nwc_pay.rs index 309279b..608a63e 100644 --- a/src/nwc_pay.rs +++ b/src/nwc_pay.rs @@ -7,7 +7,8 @@ use cln_rpc::{ responses::DecodeResponse, }, primitives::{Amount, Secret}, - ClnRpc, RpcError, + ClnRpc, + RpcError, }; use nostr_sdk::nips::nip47; use tokio::time; diff --git a/src/rpc.rs b/src/rpc.rs index 4af72c2..bbc12db 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -1,22 +1,21 @@ use anyhow::anyhow; use cln_plugin::Plugin; use cln_rpc::model::requests::{ - DatastoreMode, DatastoreRequest, DeldatastoreRequest, ListdatastoreRequest, + DatastoreMode, + DatastoreRequest, + DeldatastoreRequest, + ListdatastoreRequest, }; -use nostr_sdk::nips::nip47::NostrWalletConnectURI; -use nostr_sdk::Keys; -use nostr_sdk::SecretKey; -use nostr_sdk::Timestamp; +use nostr_sdk::{nips::nip47::NostrWalletConnectURI, Keys, SecretKey, Timestamp}; use serde_json::json; -use crate::nwc::{ - run_nwc, send_nwc_info_event, start_nwc_budget_job, stop_nwc, stop_nwc_budget_job, +use crate::{ + nwc::{run_nwc, send_nwc_info_event, start_nwc_budget_job, stop_nwc, stop_nwc_budget_job}, + parse::parse_time_period, + structs::{BudgetIntervalConfig, NwcStore, PluginState}, + util::{build_capabilities, is_read_only_nwc, load_nwc_store, update_nwc_store}, + PLUGIN_NAME, }; -use crate::parse::parse_time_period; -use crate::structs::{BudgetIntervalConfig, NwcStore, PluginState}; -use crate::util::build_capabilities; -use crate::util::{is_read_only_nwc, load_nwc_store, update_nwc_store}; -use crate::PLUGIN_NAME; pub async fn nwc_create( plugin: Plugin, diff --git a/src/structs.rs b/src/structs.rs index 7e6ff4a..c96db5a 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,9 +1,7 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::Arc}; use cln_rpc::ClnRpc; -use nostr_sdk::client; -use nostr_sdk::nips::nip47; -use nostr_sdk::nostr; +use nostr_sdk::{client, nips::nip47, nostr}; use parking_lot::Mutex; use serde::{Deserialize, Serialize}; use tokio::sync::oneshot; diff --git a/src/util.rs b/src/util.rs index 89114cd..36cc484 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,12 +4,15 @@ use cln_rpc::{ model::requests::{DatastoreMode, DatastoreRequest, ListdatastoreRequest}, ClnRpc, }; - use nostr_sdk::nips::nip47; use crate::{ structs::{NwcStore, PluginState}, - OPT_NOTIFICATIONS, PLUGIN_NAME, WALLET_NOTIFICATIONS, WALLET_PAY_METHODS, WALLET_READ_METHODS, + OPT_NOTIFICATIONS, + PLUGIN_NAME, + WALLET_NOTIFICATIONS, + WALLET_PAY_METHODS, + WALLET_READ_METHODS, }; pub fn budget_amount_check(