From 2c51288afdded4d05f3c53bde03f1f80cf4f3f69 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 28 Oct 2021 11:45:15 -0700 Subject: [PATCH] Add Copy to Role --- zk-token-sdk/src/instruction/mod.rs | 1 + zk-token-sdk/src/instruction/transfer.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zk-token-sdk/src/instruction/mod.rs b/zk-token-sdk/src/instruction/mod.rs index f1e7deb93..8c5b5a19f 100644 --- a/zk-token-sdk/src/instruction/mod.rs +++ b/zk-token-sdk/src/instruction/mod.rs @@ -16,6 +16,7 @@ pub trait Verifiable { } #[cfg(not(target_arch = "bpf"))] +#[derive(Debug,Copy,Clone)] pub enum Role { Source, Dest, diff --git a/zk-token-sdk/src/instruction/transfer.rs b/zk-token-sdk/src/instruction/transfer.rs index 81b14cedc..e11125f7e 100644 --- a/zk-token-sdk/src/instruction/transfer.rs +++ b/zk-token-sdk/src/instruction/transfer.rs @@ -142,7 +142,7 @@ impl TransferData { } /// Extracts the lo ciphertexts associated with a transfer data - fn ciphertext_lo(&self, role: &Role) -> Result { + fn ciphertext_lo(&self, role: Role) -> Result { let transfer_comm_lo: PedersenCommitment = self.amount_comms.lo.try_into()?; let decryption_handle_lo = match role { @@ -156,7 +156,7 @@ impl TransferData { } /// Extracts the lo ciphertexts associated with a transfer data - fn ciphertext_hi(&self, role: &Role) -> Result { + fn ciphertext_hi(&self, role: Role) -> Result { let transfer_comm_hi: PedersenCommitment = self.amount_comms.hi.try_into()?; let decryption_handle_hi = match role { @@ -175,7 +175,7 @@ impl TransferData { /// and make sure that the function does not terminate prematurely due to errors /// /// TODO: Define specific error type for decryption error - pub fn decrypt_amount(&self, role: &Role, sk: &ElGamalSecretKey) -> Result { + pub fn decrypt_amount(&self, role: Role, sk: &ElGamalSecretKey) -> Result { let ciphertext_lo = self.ciphertext_lo(role)?; let ciphertext_hi = self.ciphertext_hi(role)?; @@ -552,19 +552,19 @@ mod test { assert_eq!( transfer_data - .decrypt_amount(&Role::Source, &source_sk) + .decrypt_amount(Role::Source, &source_sk) .unwrap(), 55_u64, ); assert_eq!( - transfer_data.decrypt_amount(&Role::Dest, &dest_sk).unwrap(), + transfer_data.decrypt_amount(Role::Dest, &dest_sk).unwrap(), 55_u64, ); assert_eq!( transfer_data - .decrypt_amount(&Role::Auditor, &auditor_sk) + .decrypt_amount(Role::Auditor, &auditor_sk) .unwrap(), 55_u64, );