Fix list payments filter (#529)

This commit is contained in:
Ross Savage
2024-10-15 10:18:11 +02:00
committed by GitHub
parent 45281fb7e5
commit 5f638aec37
4 changed files with 12 additions and 12 deletions

View File

@@ -86,6 +86,10 @@ pub(crate) enum Command {
},
/// List incoming and outgoing payments
ListPayments {
/// The optional payment type filter. Either "send" or "receive"
#[clap(name = "filter", short = 'r', long = "filter")]
filters: Option<Vec<PaymentType>>,
/// The optional from unix timestamp
#[clap(name = "from_timestamp", short = 'f', long = "from")]
from_timestamp: Option<i64>,
@@ -445,6 +449,7 @@ pub(crate) async fn handle_command(
command_result!(format!("Message was signed by pubkey: {}", res.is_valid))
}
Command::ListPayments {
filters,
from_timestamp,
to_timestamp,
limit,
@@ -460,7 +465,7 @@ pub(crate) async fn handle_command(
let payments = sdk
.list_payments(&ListPaymentsRequest {
filters: None,
filters,
from_timestamp,
to_timestamp,
limit,

View File

@@ -943,6 +943,7 @@ impl FromSql for PaymentState {
}
#[derive(Debug, Copy, Clone, Eq, EnumString, Display, Hash, PartialEq, Serialize)]
#[strum(serialize_all = "lowercase")]
pub enum PaymentType {
Receive = 0,
Send = 1,

View File

@@ -478,23 +478,17 @@ fn filter_to_where_clause(req: &ListPaymentsRequest) -> (String, Vec<Box<dyn ToS
if let Some(filters) = &req.filters {
if !filters.is_empty() {
let mut type_filter_clause: HashSet<PaymentType> = HashSet::new();
let mut type_filter_clause: HashSet<i8> = HashSet::new();
for type_filter in filters {
match type_filter {
PaymentType::Send => {
type_filter_clause.insert(PaymentType::Send);
}
PaymentType::Receive => {
type_filter_clause.insert(PaymentType::Receive);
}
}
type_filter_clause.insert(*type_filter as i8);
}
where_clause.push(format!(
"ptx.payment_type in ({})",
type_filter_clause
.iter()
.map(|t| format!("'{}'", t))
.map(|t| format!("{}", t))
.collect::<Vec<_>>()
.join(", ")
));

View File

@@ -76,7 +76,7 @@ const App = () => {
addLine("getInfo", JSON.stringify(getInfoRes))
// Historical payments list
let payments = listPayments({})
let payments = await listPayments({})
// Register for events
listenerId = await addEventListener(eventHandler)