Skip to content

Commit

Permalink
Refactoring using new actions (#241)
Browse files Browse the repository at this point in the history
* Refactoring with new message actions

* bumps to 0.11.0
  • Loading branch information
grunch authored Apr 1, 2024
1 parent babd7f2 commit 9925ed0
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 363 deletions.
660 changes: 322 additions & 338 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mostro"
version = "0.10.2"
version = "0.11.0"
edition = "2021"
license = "MIT"
authors = ["Francisco Calderón <[email protected]>"]
Expand Down Expand Up @@ -36,10 +36,9 @@ uuid = { version = "1.8.0", features = [
"serde",
] }
reqwest = { version = "0.12.1", features = ["json"] }
mostro-core = "0.5.5"
mostro-core = "0.5.6"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
config = "0.14.0"
clap = { version = "4.5.3", features = ["derive"] }
lnurl-rs = "0.4.0"

6 changes: 3 additions & 3 deletions src/app/admin_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub async fn admin_cancel_action(
// and update on local database the status and new event id
let order_updated = update_order_event(my_keys, Status::CanceledByAdmin, &order).await?;
order_updated.update(pool).await?;
// We create a Message
let message = Message::new_dispute(Some(order.id), None, Action::AdminCancel, None);
// We create a Message for cancel
let message = Message::new_dispute(Some(order.id), None, Action::AdminCanceled, None);
let message = message.as_json()?;
// Message to admin
send_dm(&event.pubkey, message.clone()).await?;
Expand All @@ -89,7 +89,7 @@ pub async fn admin_cancel_action(
return Ok(());
}
};
send_dm(&buyer_pubkey, message.clone()).await?;
send_dm(&buyer_pubkey, message).await?;

Ok(())
}
17 changes: 12 additions & 5 deletions src/app/admin_settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ pub async fn admin_settle_action(
}
};

settle_seller_hold_invoice(event, my_keys, ln_client, Action::AdminSettle, true, &order)
.await?;
settle_seller_hold_invoice(
event,
my_keys,
ln_client,
Action::AdminSettled,
true,
&order,
)
.await?;

let order_updated = update_order_event(my_keys, Status::SettledHoldInvoice, &order).await?;

Expand All @@ -56,8 +63,8 @@ pub async fn admin_settle_action(

NOSTR_CLIENT.get().unwrap().send_event(event).await?;
}
// We create a Message
let message = Message::new_dispute(Some(order_updated.id), None, Action::AdminSettle, None);
// We create a Message for settle
let message = Message::new_dispute(Some(order_updated.id), None, Action::AdminSettled, None);
let message = message.as_json()?;
// Message to admin
send_dm(&event.pubkey, message.clone()).await?;
Expand All @@ -66,7 +73,7 @@ pub async fn admin_settle_action(
send_dm(&seller_pubkey, message.clone()).await?;
let buyer_pubkey = order_updated.buyer_pubkey.as_ref().unwrap();
let buyer_pubkey = PublicKey::from_str(buyer_pubkey).unwrap();
send_dm(&buyer_pubkey, message.clone()).await?;
send_dm(&buyer_pubkey, message).await?;

let _ = do_payment(order_updated).await;

Expand Down
2 changes: 1 addition & 1 deletion src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub async fn admin_take_dispute_action(
let message = Message::new_dispute(
Some(dispute_id),
None,
Action::AdminAcceptDispute,
Action::AdminTookDispute,
Some(Content::Order(new_order)),
);
let message = message.as_json()?;
Expand Down
10 changes: 5 additions & 5 deletions src/app/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn cancel_action(
let _ = order_updated.update(pool).await;
}
// We create a Message for cancel
send_new_order_msg(Some(order.id), Action::Cancel, None, &event.pubkey).await;
send_new_order_msg(Some(order.id), Action::Canceled, None, &event.pubkey).await;
}

return Ok(());
Expand Down Expand Up @@ -176,8 +176,8 @@ pub async fn cancel_add_invoice(
// and update on local database the status and new event id
update_order_event(my_keys, Status::CooperativelyCanceled, order).await?;
// We create a Message for cancel
send_new_order_msg(Some(order.id), Action::Cancel, None, &event.pubkey).await;
send_new_order_msg(Some(order.id), Action::Cancel, None, &seller_pubkey).await;
send_new_order_msg(Some(order.id), Action::Canceled, None, &event.pubkey).await;
send_new_order_msg(Some(order.id), Action::Canceled, None, &seller_pubkey).await;
Ok(())
} else {
// We re-publish the event with Pending status
Expand Down Expand Up @@ -231,8 +231,8 @@ pub async fn cancel_pay_hold_invoice(
// and update on local database the status and new event id
update_order_event(my_keys, Status::Canceled, order).await?;
// We create a Message for cancel
send_new_order_msg(Some(order.id), Action::Cancel, None, &event.pubkey).await;
send_new_order_msg(Some(order.id), Action::Cancel, None, &seller_pubkey).await;
send_new_order_msg(Some(order.id), Action::Canceled, None, &event.pubkey).await;
send_new_order_msg(Some(order.id), Action::Canceled, None, &seller_pubkey).await;
Ok(())
} else {
// We re-publish the event with Pending status
Expand Down
7 changes: 3 additions & 4 deletions src/app/fiat_sent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,20 @@ pub async fn fiat_sent_action(
};
let peer = Peer::new(event.pubkey.to_string());

// We create a Message
// We a message to the seller
send_new_order_msg(
Some(order.id),
Action::FiatSent,
Action::FiatSentOk,
Some(Content::Peer(peer)),
&seller_pubkey,
)
.await;
// We send a message to buyer to wait
let peer = Peer::new(seller_pubkey.to_string());

// We create a Message
send_new_order_msg(
Some(order.id),
Action::FiatSent,
Action::FiatSentOk,
Some(Content::Peer(peer)),
&event.pubkey,
)
Expand Down
4 changes: 2 additions & 2 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn release_action(
return Ok(());
}

settle_seller_hold_invoice(event, my_keys, ln_client, Action::Release, false, &order).await?;
settle_seller_hold_invoice(event, my_keys, ln_client, Action::Released, false, &order).await?;

let buyer_pubkey = order.buyer_pubkey.clone().unwrap();

Expand All @@ -107,7 +107,7 @@ pub async fn release_action(
.await;
// We send a message to buyer indicating seller released funds
let buyer_pubkey = PublicKey::from_str(&buyer_pubkey)?;
send_new_order_msg(Some(order_id), Action::Release, None, &buyer_pubkey).await;
send_new_order_msg(Some(order_id), Action::Released, None, &buyer_pubkey).await;
let _ = do_payment(order_updated).await;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ pub async fn rate_counterpart(
) -> Result<()> {
// Send dm to counterparts
// to buyer
send_new_order_msg(Some(order.id), Action::RateUser, None, buyer_pubkey).await;
send_new_order_msg(Some(order.id), Action::Rate, None, buyer_pubkey).await;
// to seller
send_new_order_msg(Some(order.id), Action::RateUser, None, seller_pubkey).await;
send_new_order_msg(Some(order.id), Action::Rate, None, seller_pubkey).await;

Ok(())
}
Expand Down

0 comments on commit 9925ed0

Please sign in to comment.