Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid sending unsolicited request-id #386

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading