mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-18 06:24:21 +01:00
Fix list payments filter (#529)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(", ")
|
||||
));
|
||||
|
||||
2
packages/react-native/example/App.js
vendored
2
packages/react-native/example/App.js
vendored
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user