Browse Source

Client: check if there is enough value for the desired token_id before
transfer

ghassmo 4 years ago
parent
commit
1d51af5489
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/client.rs

+ 10 - 4
src/client.rs

@@ -111,17 +111,23 @@ impl Client {
 
     pub async fn transfer(
         &mut self,
-        asset_id: jubjub::Fr,
+        token_id: jubjub::Fr,
         pub_key: jubjub::SubgroupPoint,
         amount: u64,
-    ) -> Result<()> {
+    ) -> ClientResult<()> {
         debug!(target: "CLIENT", "Start transfer {}", amount);
 
         if amount == 0 {
             return Err(ClientFailed::InvalidAmount(amount as u64).into());
         }
 
-        self.send(pub_key, amount, asset_id, false).await?;
+        let token_id_exists = self.state.lock().await.wallet.token_id_exists(&token_id)?;
+
+        if token_id_exists {
+            self.send(pub_key, amount, token_id, false).await?;
+        } else {
+            return Err(ClientFailed::NotEnoughValue(amount));
+        }
 
         debug!(target: "CLIENT", "End transfer {}", amount);
 
@@ -134,7 +140,7 @@ impl Client {
         amount: u64,
         asset_id: jubjub::Fr,
         clear_input: bool,
-    ) -> Result<()> {
+    ) -> ClientResult<()> {
         debug!(target: "CLIENT", "Start send {}", amount);
 
         let slab = self