Skip to content

Commit

Permalink
Allow buyer add new invoice with addinvoice action (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Feb 27, 2024
1 parent 993ed44 commit 50de71d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ uuid = { version = "1.3.0", features = [
"serde",
] }
reqwest = { version = "0.11", features = ["json"] }
mostro-core = "0.4.5"
mostro-core = "0.4.6"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
config = "0.13.3"
Expand Down
22 changes: 16 additions & 6 deletions src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub async fn add_invoice_action(
};
// Only the buyer can add an invoice
if buyer_pubkey != event.pubkey {
// We create a Message
let message = Message::cant_do(Some(order.id), None, None);
let message = message.as_json().unwrap();
send_dm(client, my_keys, &event.pubkey, message).await?;
Expand Down Expand Up @@ -85,7 +84,6 @@ pub async fn add_invoice_action(
| MostroError::MinExpirationTimeError
| MostroError::WrongAmountError
| MostroError::MinAmountError => {
// We create a Message
let message = Message::cant_do(
Some(order.id),
None,
Expand All @@ -108,12 +106,26 @@ pub async fn add_invoice_action(
error!("Order Id {order_id} wrong get_payment_request");
return Ok(());
}

// We save the invoice on db
order.buyer_invoice = Some(pr.clone());
// Buyer can add invoice orders with WaitingBuyerInvoice status
match order_status {
Status::WaitingBuyerInvoice => {}
Status::SettledHoldInvoice => {
order.update(pool).await?;
let message = Message::new_order(
Some(order_id),
None,
Action::AddInvoice,
Some(Content::TextMessage(format!(
"Order Id {order_id}: Invoice updated!"
))),
);
let message = message.as_json()?;
send_dm(client, my_keys, &buyer_pubkey, message).await?;
return Ok(());
}
_ => {
// We create a Message
let message = Message::cant_do(
Some(order.id),
None,
Expand All @@ -128,8 +140,6 @@ pub async fn add_invoice_action(
}
let seller_pubkey = order.seller_pubkey.as_ref().cloned().unwrap();
let seller_pubkey = XOnlyPublicKey::from_str(&seller_pubkey)?;
// We save the invoice on db
order.buyer_invoice = Some(pr.clone());

if order.preimage.is_some() {
// We send this data related to the order to the parties
Expand Down

0 comments on commit 50de71d

Please sign in to comment.