-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleaning of cancelled invoices
- Loading branch information
1 parent
81a3189
commit eef0fbd
Showing
8 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::commands::structs::{parse_args, FromArr, ParamsError}; | ||
use crate::database::helpers::invoice_helper::InvoiceHelper; | ||
use crate::encoder::InvoiceEncoder; | ||
use crate::State; | ||
use cln_plugin::Plugin; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct CleanRequest { | ||
age: Option<u64>, | ||
} | ||
|
||
impl FromArr for CleanRequest { | ||
fn from_arr(arr: Vec<Value>) -> anyhow::Result<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
if arr.is_empty() { | ||
return Ok(Self { age: None }); | ||
} | ||
|
||
Ok(Self { | ||
age: Some(arr[0].as_u64().ok_or(ParamsError::ParseError)?), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct CleanResponse { | ||
pub cleaned: usize, | ||
} | ||
|
||
pub async fn clean<T, E>(plugin: Plugin<State<T, E>>, args: Value) -> anyhow::Result<Value> | ||
where | ||
T: InvoiceHelper + Sync + Send + Clone, | ||
E: InvoiceEncoder + Sync + Send + Clone, | ||
{ | ||
let params = parse_args::<CleanRequest>(args)?; | ||
|
||
let cleaned = plugin.state().invoice_helper.clean_cancelled(params.age)?; | ||
|
||
Ok(serde_json::to_value(&CleanResponse { cleaned })?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
mod cancel; | ||
mod clean; | ||
mod invoice; | ||
mod list; | ||
mod settle; | ||
mod structs; | ||
|
||
pub use cancel::cancel; | ||
pub use clean::clean; | ||
pub use invoice::invoice; | ||
pub use list::list_invoices; | ||
pub use settle::settle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters