Просмотр исходного кода

contract: minor fixes

dao contract needs to be updated with the new money API
aggstam 3 лет назад
Родитель
Сommit
2ac20a6f39
4 измененных файлов с 11 добавлено и 5 удалено
  1. 2 0
      Cargo.lock
  2. 5 4
      src/contract/dao/src/entrypoint.rs
  3. 1 1
      src/contract/money/src/client/swap_v1.rs
  4. 3 0
      src/error.rs

+ 2 - 0
Cargo.lock

@@ -1225,6 +1225,7 @@ dependencies = [
  "simplelog",
  "sled",
  "sqlx",
+ "thiserror",
 ]
 
 [[package]]
@@ -1234,6 +1235,7 @@ dependencies = [
  "blake2b_simd",
  "blake3",
  "bs58",
+ "chacha20poly1305",
  "darkfi-serial",
  "halo2_gadgets",
  "halo2_proofs",

+ 5 - 4
src/contract/dao/src/entrypoint.rs

@@ -33,7 +33,8 @@ use darkfi_sdk::{
 use darkfi_serial::{deserialize, serialize, Decodable, Encodable, WriteExt};
 
 use darkfi_money_contract::{
-    model::MoneyTransferParams, MoneyFunction, MONEY_CONTRACT_COIN_ROOTS_TREE,
+    model::MoneyTransferParamsV1 as MoneyTransferParams,
+    MoneyFunction::TransferV1 as MoneyTransfer, MONEY_CONTRACT_COIN_ROOTS_TREE,
     MONEY_CONTRACT_NULLIFIERS_TREE,
 };
 
@@ -301,7 +302,7 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
 
             // 3. First item should be a MoneyTransfer call
             assert!(call[0].contract_id == *MONEY_CONTRACT_ID);
-            assert!(call[0].data[0] == MoneyFunction::Transfer as u8);
+            assert!(call[0].data[0] == MoneyTransfer as u8);
 
             // 4. MoneyTransfer has exactly 2 outputs
             let mt_params: MoneyTransferParams = deserialize(&call[0].data[1..])?;
@@ -311,8 +312,8 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
             // Checks
             // ======
             // 1. Check both coins in MoneyTransfer are equal to our coin_0, coin_1
-            assert!(mt_params.outputs[0].coin == params.coin_0);
-            assert!(mt_params.outputs[1].coin == params.coin_1);
+            assert!(mt_params.outputs[0].coin.inner() == params.coin_0);
+            assert!(mt_params.outputs[1].coin.inner() == params.coin_1);
 
             // 2. Sum of MoneyTransfer input value commits == our input value commit
             let mut input_valcoms = pallas::Point::identity();

+ 1 - 1
src/contract/money/src/client/swap_v1.rs

@@ -104,7 +104,7 @@ impl SwapCallBuilder {
         }
 
         if self.coin.note.token_id != self.token_id_send {
-            return Err(ClientFailed::InvalidTokenId.into())
+            return Err(ClientFailed::InvalidTokenId(self.coin.note.token_id.to_string()).into())
         }
 
         let leaf_position = self.coin.leaf_position;

+ 3 - 0
src/error.rs

@@ -493,6 +493,9 @@ pub enum ClientFailed {
     #[error("Invalid amount: {0}")]
     InvalidAmount(u64),
 
+    #[error("Invalid token ID: {0}")]
+    InvalidTokenId(String),
+
     #[error("Internal error: {0}")]
     InternalError(String),