Przeglądaj źródła

app/plugin/drk: mark transaction coins as spent before broadcast

epiphany 2 miesięcy temu
rodzic
commit
1e1810126e
1 zmienionych plików z 21 dodań i 16 usunięć
  1. 21 16
      bin/app/src/plugin/drk.rs

+ 21 - 16
bin/app/src/plugin/drk.rs

@@ -599,25 +599,30 @@ impl DrkPlugin {
             return true
         };
 
-        let result = self_.broadcast_tx(tx).await;
-
-        match result {
-            Ok(tx_id) => {
-                let state = TxState {
-                    id: Some(tx_id),
-                    status: TxStatus::Confirming,
-                    amount: None,
-                    token_symbol: None,
-                    recipient: None,
-                };
-                self_.emit_tx_updated(&state).await;
-            }
-            Err(_) => {
-                e!("Failed to broadcast transaction");
+        let drk = self_.drk.read().await;
+        if let Err(e) = drk.mark_tx_spend(&tx, &mut vec![]).await {
+            e!("Failed to mark transaction coins as spent: {e}");
+            self_.emit_tx_status_updated(&TxStatus::Error("failed to mark coins as spent".to_string())).await;
+            return true
+        };
+        let tx_id = match drk.broadcast_tx(&tx, &mut vec![]).await {
+            Ok(t) => t,
+            Err(e) => {
+                e!("Failed to broadcast transaction: {e}");
                 self_.emit_tx_status_updated(&TxStatus::Error("failed to broadcast".to_string())).await;
                 return true
             }
-        }
+        };
+        drop(drk);
+
+        let state = TxState {
+            id: Some(tx_id),
+            status: TxStatus::Confirming,
+            amount: None,
+            token_symbol: None,
+            recipient: None,
+        };
+        self_.emit_tx_updated(&state).await;
 
         true
     }