Skip to content

Commit

Permalink
Avoid sending unsolicited request-id (#386)
Browse files Browse the repository at this point in the history
* Avoid sending unsolicited request-id

* Removes request_id not being used anymore
  • Loading branch information
grunch authored Nov 7, 2024
1 parent 77faec4 commit 915f592
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
9 changes: 2 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ pub async fn run(
match message {
Ok(msg) => {
if msg.get_inner_message_kind().verify() {
// Get the optional request id
let request_id = msg.get_inner_message_kind().request_id;

if let Some(action) = msg.inner_action() {
match action {
Action::NewOrder => {
Expand All @@ -102,10 +99,8 @@ pub async fn run(
}
}
Action::TakeBuy => {
if let Err(e) = take_buy_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
take_buy_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub async fn add_invoice_action(

// We send a confirmation message to seller
send_new_order_msg(
request_id,
None,
Some(order.id),
Action::BuyerTookOrder,
Some(Content::Order(order_data.clone())),
Expand Down
13 changes: 3 additions & 10 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,7 @@ pub async fn release_action(
Some(buyer) => PublicKey::from_str(buyer.as_str())?,
_ => return Err(Error::msg("Missing buyer pubkeys")),
};
send_new_order_msg(
request_id,
Some(order_id),
Action::Released,
None,
&buyer_pubkey,
)
.await;
send_new_order_msg(None, Some(order_id), Action::Released, None, &buyer_pubkey).await;

let _ = do_payment(order_updated, request_id).await;

Expand Down Expand Up @@ -254,7 +247,7 @@ async fn payment_success(
) -> Result<()> {
// Purchase completed message to buyer
send_new_order_msg(
request_id,
None,
Some(order.id),
Action::PurchaseCompleted,
None,
Expand Down Expand Up @@ -353,7 +346,7 @@ async fn payment_success(
Ordering::Less => {}
}
} else {
send_cant_do_msg(request_id, Some(order.id), None, buyer_pubkey).await;
send_cant_do_msg(None, Some(order.id), None, buyer_pubkey).await;
send_cant_do_msg(request_id, Some(order.id), None, seller_pubkey).await;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/take_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub async fn take_buy_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: Option<u64>,
) -> Result<()> {
// Safe unwrap as we verified the message
let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
Expand All @@ -27,6 +26,8 @@ pub async fn take_buy_action(
return Err(Error::msg("No order id"));
};

let request_id = msg.get_inner_message_kind().request_id;

let mut order = match Order::by_id(pool, order_id).await? {
Some(order) => order,
None => {
Expand Down

0 comments on commit 915f592

Please sign in to comment.