Skip to content

Commit 0003e39

Browse files
committed
fix: completed merge of pr and fixed conflicts
1 parent c91ebfb commit 0003e39

3 files changed

Lines changed: 34 additions & 33 deletions

File tree

src/cli/last_trade_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub async fn execute_last_trade_index(
4444
if let Some((message, _, _)) = messages.first() {
4545
let message = message.get_inner_message_kind();
4646
if message.action == Action::LastTradeIndex {
47-
print_commands_results(message, None, ctx).await?
47+
print_commands_results(message, ctx).await?
4848
} else {
4949
return Err(anyhow::anyhow!(
5050
"Received response with mismatched action. Expected: {:?}, Got: {:?}",

src/parser/dms.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ use crate::{
1616
use sqlx::SqlitePool;
1717

1818
/// Execute logic of command answer
19-
pub async fn print_commands_results(
20-
message: &MessageKind,
21-
mut order: Option<Order>,
22-
ctx: &Context,
23-
) -> Result<()> {
19+
pub async fn print_commands_results(message: &MessageKind, ctx: &Context) -> Result<()> {
2420
// Do the logic for the message response
2521
match message.action {
2622
Action::NewOrder => {
@@ -48,7 +44,8 @@ pub async fn print_commands_results(
4844
// this is the case where the buyer adds an invoice to a takesell order
4945
Action::WaitingSellerToPay => {
5046
println!("Now we should wait for the seller to pay the invoice");
51-
if let Some(mut order) = order.take() {
47+
if let Some(order_id) = &message.id {
48+
let mut order = Order::get_by_id(&ctx.pool, &order_id.to_string()).await?;
5249
match order
5350
.set_status(Status::WaitingPayment.to_string())
5451
.save(&ctx.pool)
@@ -199,6 +196,27 @@ pub async fn print_commands_results(
199196
Err(anyhow::anyhow!("No trade index found in message"))
200197
}
201198
}
199+
Action::DisputeInitiatedByYou => {
200+
if let Some(Payload::Dispute(dispute_id, _)) = &message.payload {
201+
println!("Dispute initiated successfully with ID: {}", dispute_id);
202+
if let Some(order_id) = &message.id {
203+
let mut order = Order::get_by_id(&ctx.pool, &order_id.to_string()).await?;
204+
// Update order status to disputed if we have the order
205+
match order
206+
.set_status(Status::Dispute.to_string())
207+
.save(&ctx.pool)
208+
.await
209+
{
210+
Ok(_) => println!("Order status updated to Dispute"),
211+
Err(e) => println!("Failed to update order status: {}", e),
212+
}
213+
}
214+
Ok(())
215+
} else {
216+
println!("Warning: Dispute initiated but received unexpected payload structure");
217+
Ok(())
218+
}
219+
}
202220
Action::HoldInvoicePaymentSettled => {
203221
println!("Hold invoice payment settled");
204222
Ok(())
@@ -226,15 +244,21 @@ pub async fn parse_dm_events(
226244
let unwrapped_gift = match nip59::extract_rumor(pubkey, dm).await {
227245
Ok(u) => u,
228246
Err(e) => {
229-
eprintln!("Warning: Could not decrypt gift wrap (event {}): {}", dm.id, e);
247+
eprintln!(
248+
"Warning: Could not decrypt gift wrap (event {}): {}",
249+
dm.id, e
250+
);
230251
continue;
231252
}
232253
};
233254
let (message, _): (Message, Option<String>) =
234255
match serde_json::from_str(&unwrapped_gift.rumor.content) {
235256
Ok(msg) => msg,
236257
Err(e) => {
237-
eprintln!("Warning: Could not parse message content (event {}): {}", dm.id, e);
258+
eprintln!(
259+
"Warning: Could not parse message content (event {}): {}",
260+
dm.id, e
261+
);
238262
continue;
239263
}
240264
};

src/util.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,6 @@ where
164164
// Continue waiting for a valid event
165165
continue;
166166
}
167-
// this is the case where the user initiates a dispute
168-
Action::DisputeInitiatedByYou => {
169-
if let Some(Payload::Dispute(dispute_id, _)) = &message.payload {
170-
println!("Dispute initiated successfully with ID: {}", dispute_id);
171-
// Update order status to disputed if we have the order
172-
if let Some(mut order) = order.take() {
173-
match order
174-
.set_status(Status::Dispute.to_string())
175-
.save(pool)
176-
.await
177-
{
178-
Ok(_) => println!("Order status updated to Dispute"),
179-
Err(e) => println!("Failed to update order status: {}", e),
180-
}
181-
}
182-
return Ok(());
183-
} else {
184-
println!("Warning: Dispute initiated but received unexpected payload structure");
185-
return Ok(());
186-
}
187-
}
188-
_ => {}
189-
}
190167
}
191168
}
192169
Err(e) => {
@@ -621,7 +598,7 @@ pub async fn print_dm_events(
621598
if let Some((message, _, _)) = messages.first() {
622599
let message = message.get_inner_message_kind();
623600
if message.request_id == Some(request_id) {
624-
print_commands_results(message, None, ctx).await?;
601+
print_commands_results(message, ctx).await?;
625602
} else {
626603
return Err(anyhow::anyhow!(
627604
"Received response with mismatched request_id. Expected: {}, Got: {:?}",

0 commit comments

Comments
 (0)