Przeglądaj źródła

check if there are coins before transfer the coins

ghassmo 5 lat temu
rodzic
commit
dcd44c2a71
2 zmienionych plików z 11 dodań i 5 usunięć
  1. 11 4
      src/client/client.rs
  2. 0 1
      src/rpc/jsonserver.rs

+ 11 - 4
src/client/client.rs

@@ -212,13 +212,15 @@ impl Client {
                     let address: jubjub::SubgroupPoint = deserialize(&address)?;
 
 
-                    let slab = self.prepare_transaction(
+                    let slab_tx = self.prepare_transaction(
                         address,
                         transfer_params.amount,
                         wallet.clone()
                     )?;
 
-                    self.gateway.put_slab(slab).await?;
+                    if let Some(slab) = slab_tx {
+                        self.gateway.put_slab(slab).await?;
+                    }
                 }
 
             }
@@ -230,8 +232,13 @@ impl Client {
         address: jubjub::SubgroupPoint,
         amount: f64,
         wallet: WalletPtr,
-    ) -> Result<Slab> {
+    ) -> Result<Option<Slab>> {
+        // check if there are coins
         let own_coins = wallet.get_own_coins()?;
+        if own_coins.len() < 1 {
+            return Ok(None);
+        }
+
         let witness = &own_coins[0].3;
         let merkle_path = witness.path().unwrap();
 
@@ -260,7 +267,7 @@ impl Client {
 
         // build slab from the transaction
         let slab = Slab::new(tx_data);
-        return Ok(slab);
+        return Ok(Some(slab));
     }
 }
 

+ 0 - 1
src/rpc/jsonserver.rs

@@ -68,7 +68,6 @@ pub async fn listen(
             }
         };
 
-        // Detach the task to let it run in the background.
         task.await;
     }
 }