From 40c761baaf8498349ab2d349064a67769a97c64f Mon Sep 17 00:00:00 2001 From: nicolasito1411 <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:32:17 +0200 Subject: [PATCH] fix: coupon can only be used once --- src/endpoints/campaigns/get_free_domain.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/endpoints/campaigns/get_free_domain.rs b/src/endpoints/campaigns/get_free_domain.rs index 110afe4..6ef5918 100644 --- a/src/endpoints/campaigns/get_free_domain.rs +++ b/src/endpoints/campaigns/get_free_domain.rs @@ -59,7 +59,18 @@ pub async fn handler( if let Ok(spent) = doc.get_bool("spent") { if spent { if let Ok(spent_by) = doc.get_str("spent_by") { - if (spent_by != to_hex(&query.addr)) { + if (spent_by == to_hex(&query.addr)) { + let r = doc.get_str("r").unwrap(); + let s = doc.get_str("s").unwrap(); + return ( + StatusCode::OK, + Json(json!({ + "r": r, + "s": s, + })), + ) + .into_response(); + } else { return get_error(format!("Coupon code already used by {}\nIf you own this account, this means you have already used this coupon code with the other account. Please switch to it.", spent_by)); } } else { @@ -111,6 +122,8 @@ pub async fn handler( "$set" : { "spent" : true, "spent_by" : to_hex(&query.addr), + "r" : signature.r.to_string(), + "s" : signature.s.to_string(), }, }, None,