diff --git a/sqlx-data.json b/sqlx-data.json index 0062803c..6b3daae7 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -10,7 +10,7 @@ }, "query": "\n UPDATE orders\n SET\n master_seller_pubkey = ?1\n WHERE id = ?2\n " }, - "1a4f24e4d6c6447e7f6b9c7207bd12bc23e87f37d2c8676bffd8f4eb86c31405": { + "301fbda63c61bf75d60bc330d5b1aacae80248c253a2fe9e97f5a74a7acafe75": { "describe": { "columns": [], "nullable": [], @@ -18,27 +18,27 @@ "Right": 2 } }, - "query": "\n UPDATE orders\n SET\n seller_dispute = ?1\n WHERE id = ?2\n " + "query": "\n UPDATE orders\n SET\n buyer_sent_rate = ?1\n WHERE id = ?2\n " }, - "301fbda63c61bf75d60bc330d5b1aacae80248c253a2fe9e97f5a74a7acafe75": { + "4465f33fba7d31a7154b9710438d9319d02018e873a54d720cda2f7eb07aece6": { "describe": { "columns": [], "nullable": [], "parameters": { - "Right": 2 + "Right": 6 } }, - "query": "\n UPDATE orders\n SET\n buyer_sent_rate = ?1\n WHERE id = ?2\n " + "query": "\n UPDATE orders\n SET\n buyer_pubkey = ?1,\n seller_pubkey = ?2,\n status = ?3,\n preimage = ?4,\n hash = ?5\n WHERE id = ?6\n " }, - "4465f33fba7d31a7154b9710438d9319d02018e873a54d720cda2f7eb07aece6": { + "45bc1577516315db37be5481594323e87e6bd406f2248b5b44015eaf3ff34a14": { "describe": { "columns": [], "nullable": [], "parameters": { - "Right": 6 + "Right": 2 } }, - "query": "\n UPDATE orders\n SET\n buyer_pubkey = ?1,\n seller_pubkey = ?2,\n status = ?3,\n preimage = ?4,\n hash = ?5\n WHERE id = ?6\n " + "query": "\n UPDATE orders\n SET\n buyer_dispute = ?1,\n status = 'Dispute'\n WHERE id = ?2\n " }, "567a4d6906624fb39ff9719c0f15626b42d215d6648b6274bda052cfc9f48102": { "describe": { @@ -50,7 +50,7 @@ }, "query": "\n UPDATE orders\n SET\n seller_sent_rate = ?1\n WHERE id = ?2\n " }, - "77ea98f6af16fa6e5a7d604965593700c563f88d88cb10b348bdc4200c87ad1d": { + "6850cc0e71b2fc6d8632e96513f661de41349ee483172db98ddea8e5999d5329": { "describe": { "columns": [], "nullable": [], @@ -58,29 +58,29 @@ "Right": 2 } }, - "query": "\n UPDATE orders\n SET\n buyer_pubkey = ?1\n WHERE id = ?2\n " + "query": "\n UPDATE orders\n SET\n seller_dispute = ?1,\n status = 'Dispute'\n WHERE id = ?2\n " }, - "878c89a9ccf7cf33910f32a9dd2c09f45364dd744dc9e5749a318825343be542": { + "77ea98f6af16fa6e5a7d604965593700c563f88d88cb10b348bdc4200c87ad1d": { "describe": { "columns": [], "nullable": [], "parameters": { - "Right": 4 + "Right": 2 } }, - "query": "\n UPDATE orders\n SET\n cancel_initiator_pubkey = ?1,\n buyer_cooperativecancel = ?2,\n seller_cooperativecancel = ?3\n WHERE id = ?4\n " + "query": "\n UPDATE orders\n SET\n buyer_pubkey = ?1\n WHERE id = ?2\n " }, - "89253158dce7eb8ed1c4fce2120418909fde010398815c5e673fb7d406dc5b4f": { + "878c89a9ccf7cf33910f32a9dd2c09f45364dd744dc9e5749a318825343be542": { "describe": { "columns": [], "nullable": [], "parameters": { - "Right": 2 + "Right": 4 } }, - "query": "\n UPDATE orders\n SET\n buyer_invoice = ?1\n WHERE id = ?2\n " + "query": "\n UPDATE orders\n SET\n cancel_initiator_pubkey = ?1,\n buyer_cooperativecancel = ?2,\n seller_cooperativecancel = ?3\n WHERE id = ?4\n " }, - "900597cf1e8ed114cb383856d398ffb23b1d15e48c1708fc2b40cfcc649df9fc": { + "89253158dce7eb8ed1c4fce2120418909fde010398815c5e673fb7d406dc5b4f": { "describe": { "columns": [], "nullable": [], @@ -88,7 +88,7 @@ "Right": 2 } }, - "query": "\n UPDATE orders\n SET\n buyer_dispute = ?1\n WHERE id = ?2\n " + "query": "\n UPDATE orders\n SET\n buyer_invoice = ?1\n WHERE id = ?2\n " }, "97414183485e04346f420960beed77912ebe76089f58d30f0f526e232ce4be25": { "describe": { diff --git a/src/db.rs b/src/db.rs index 6145033a..304eb82d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -212,7 +212,7 @@ pub async fn update_order_event_id_status( let mostro_settings = Settings::get_mostro(); let status = status.to_string(); // We calculate the bot fee - let fee = mostro_settings.fee / 2.0; + let fee = mostro_settings.fee; let fee = fee * amount as f64; let fee = fee.round() as i64; @@ -484,7 +484,8 @@ pub async fn update_order_buyer_dispute( r#" UPDATE orders SET - buyer_dispute = ?1 + buyer_dispute = ?1, + status = 'Dispute' WHERE id = ?2 "#, buyer_dispute, @@ -507,7 +508,8 @@ pub async fn update_order_seller_dispute( r#" UPDATE orders SET - seller_dispute = ?1 + seller_dispute = ?1, + status = 'Dispute' WHERE id = ?2 "#, seller_dispute, diff --git a/src/lightning/invoice.rs b/src/lightning/invoice.rs index 9c4cd223..0166d49d 100644 --- a/src/lightning/invoice.rs +++ b/src/lightning/invoice.rs @@ -13,7 +13,8 @@ pub fn decode_invoice(payment_request: &str) -> Result { Ok(invoice) } -/// Verify if a buyer invoice is valid +/// Verify if a buyer invoice is valid, +/// if the invoice have amount we check if the amount minus fee is the same pub fn is_valid_invoice( payment_request: &str, amount: Option, @@ -23,20 +24,26 @@ pub fn is_valid_invoice( let mostro_settings = Settings::get_mostro(); let ln_settings = Settings::get_ln(); - let amount_msat = invoice.amount_milli_satoshis().unwrap_or(0) / 1000; + let amount_sat = invoice.amount_milli_satoshis().unwrap_or(0) / 1000; let fee = fee.unwrap_or(0); + // We receive the total order fee, we divide by 2 because we split the fee + let fee = fee as f64 / 2.0; + let fee = fee.round() as u64; if let Some(amt) = amount { - if amount_msat > 0 && amount_msat != (amt - fee) { + if amount_sat > 0 && amount_sat != (amt - fee) { return Err(MostroError::WrongAmountError); } } - if amount_msat > 0 && amount_msat < mostro_settings.min_payment_amount as u64 { + + if amount_sat > 0 && amount_sat < mostro_settings.min_payment_amount as u64 { return Err(MostroError::MinAmountError); } + if invoice.is_expired() { return Err(MostroError::InvoiceExpiredError); } + let parsed = payment_request.parse::()?; let (parsed_invoice, _, _) = parsed.into_parts(); diff --git a/src/lightning/mod.rs b/src/lightning/mod.rs index ee976867..b0a2d370 100644 --- a/src/lightning/mod.rs +++ b/src/lightning/mod.rs @@ -158,7 +158,11 @@ impl LndConnector { let invoice = decode_invoice(payment_request).unwrap(); let payment_hash = invoice.payment_hash(); let payment_hash = payment_hash.to_vec(); - let hash = String::from_utf8(payment_hash.clone()).unwrap(); + let hash: String = payment_hash + .clone() + .iter() + .map(|b| format!("{:02x}", b)) + .collect(); let mostro_settings = Settings::get_mostro(); // We need to set a max fee amount