|
@@ -147,26 +147,32 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let (x, y) = params.member.xy();
|
|
let (x, y) = params.member.xy();
|
|
|
let commitment = poseidon_hash([x, y]);
|
|
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
|
|
// And then match based on our function call
|
|
|
match func_id {
|
|
match func_id {
|
|
|
ContractFunction::Register => {
|
|
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");
|
|
msg!("Error: Member already registered");
|
|
|
return Err(ContractError::Custom(1));
|
|
return Err(ContractError::Custom(1));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
ContractFunction::Deregister => {
|
|
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");
|
|
msg!("Error: Member not registered");
|
|
|
return Err(ContractError::Custom(2));
|
|
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
|
|
// `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
|
|
// fed to this function so there is no need to add it ourself. We just
|
|
|
// return the payload we want to work with.
|
|
// return the payload we want to work with.
|