skoupidi 8 месяцев назад
Родитель
Сommit
8b44418fa7
2 измененных файлов с 16 добавлено и 10 удалено
  1. 4 4
      client/main.rs
  2. 12 6
      src/entrypoint.rs

+ 4 - 4
client/main.rs

@@ -71,7 +71,9 @@ fn register(argv0: &str, cid: ContractId, secret_key: Option<String>) {
     let prover_witnesses = vec![Witness::Base(Value::known(keypair.secret.inner()))];
 
     // Now we create the circuit and its ProvingKey so we are able to create
-    // the ZK proof.
+    // the ZK proof. We are using `eprintln` for execution logs so they are
+    // printed in `stderr` as we want to print just the encoded transaction
+    // in `stdout` for further processing.
     eprintln!("Generating {} circuit ProvingKey...", zkbin.namespace);
     let circuit = ZkCircuit::new(circuit_witnesses, &zkbin);
     let proving_key = ProvingKey::build(zkbin.k, &circuit);
@@ -175,8 +177,6 @@ fn main() {
     match command.as_str() {
         "register" => register(&argv0, cid, args.next()),
         "deregister" => deregister(&argv0, cid, args.next()),
-        _ => return usage(&argv0),
+        _ => usage(&argv0),
     }
-
-    process::exit(1);
 }

+ 12 - 6
src/entrypoint.rs

@@ -147,26 +147,32 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
     let (x, y) = params.member.xy();
     let commitment = poseidon_hash([x, y]);
 
+    // Database operates over byte vectors, therefore we need to serialize
+    // the commitment for further handling
+    let commitment = serialize(&commitment);
+
     // And then match based on our function call
     match func_id {
         ContractFunction::Register => {
-            // To register a member, they should not exist in the database.
-            if db_contains_key(db_members, &serialize(&commitment))? {
+            // To register a member, their commitment should not exist in
+            // the database.
+            if db_contains_key(db_members, &commitment)? {
                 msg!("Error: Member already registered");
                 return Err(ContractError::Custom(1));
             }
         }
         ContractFunction::Deregister => {
-            // To deregister a member, they should be in the database.
-            if !db_contains_key(db_members, &serialize(&commitment))? {
+            // To deregister a member, their commitment should be in the
+            // database.
+            if !db_contains_key(db_members, &commitment)? {
                 msg!("Error: Member not registered");
                 return Err(ContractError::Custom(2));
             }
         }
     }
 
-    // At this point our logic has passed, so we'll serialize the commitment
-    // and return it. It will be used in `process_update()`.
+    // At this point our logic has passed, so we'll return the serialized
+    // commitment. It will be used in `process_update()`.
     // `process_update()` will be prefixed with the first byte from the payload
     // fed to this function so there is no need to add it ourself. We just
     // return the payload we want to work with.