From d2545ee7f6d1e24a9ba694db26cec28cf7b1c37e Mon Sep 17 00:00:00 2001 From: andrea Date: Tue, 26 Nov 2024 12:23:43 -0800 Subject: [PATCH] Rust: remove unnecessary uses of dynamic dispatch --- ironfish-rust/src/merkle_note.rs | 6 ++++-- ironfish-rust/src/transaction/proposed.rs | 4 ++-- ironfish-rust/src/transaction/spends.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ironfish-rust/src/merkle_note.rs b/ironfish-rust/src/merkle_note.rs index b038508e84..562b55f184 100644 --- a/ironfish-rust/src/merkle_note.rs +++ b/ironfish-rust/src/merkle_note.rs @@ -285,7 +285,9 @@ impl MerkleNote { } #[cfg(feature = "transaction-proofs")] -pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec> { +pub(crate) fn sapling_auth_path( + witness: &W, +) -> Vec> { let mut auth_path = vec![]; for element in &witness.get_auth_path() { let sapling_element = match element { @@ -305,7 +307,7 @@ pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec u64 { +pub(crate) fn position(witness: &W) -> u64 { let mut pos = 0; for (i, element) in witness.get_auth_path().iter().enumerate() { if let WitnessNode::Right(_) = element { diff --git a/ironfish-rust/src/transaction/proposed.rs b/ironfish-rust/src/transaction/proposed.rs index 49a7b3cc48..5470c1ea98 100644 --- a/ironfish-rust/src/transaction/proposed.rs +++ b/ironfish-rust/src/transaction/proposed.rs @@ -102,10 +102,10 @@ impl ProposedTransaction { } /// Spend the note owned by spender_key at the given witness location. - pub fn add_spend( + pub fn add_spend( &mut self, note: Note, - witness: &dyn WitnessTrait, + witness: &W, ) -> Result<(), IronfishError> { self.value_balances .add(note.asset_id(), note.value().try_into()?)?; diff --git a/ironfish-rust/src/transaction/spends.rs b/ironfish-rust/src/transaction/spends.rs index e0741e1b19..5122429c3e 100644 --- a/ironfish-rust/src/transaction/spends.rs +++ b/ironfish-rust/src/transaction/spends.rs @@ -68,7 +68,7 @@ impl SpendBuilder { /// This is the only time this API thinks about the merkle tree. The witness /// contains the root-hash at the time the witness was created and the path /// to verify the location of that note in the tree. - pub(crate) fn new(note: Note, witness: &dyn WitnessTrait) -> Self { + pub(crate) fn new(note: Note, witness: &W) -> Self { let value_commitment = ValueCommitment::new(note.value, note.asset_generator()); SpendBuilder {