Skip to content

Commit

Permalink
Rust: remove unnecessary uses of dynamic dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
andiflabs committed Nov 26, 2024
1 parent 18dd964 commit d2545ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ironfish-rust/src/merkle_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ impl MerkleNote {
}

#[cfg(feature = "transaction-proofs")]
pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec<Option<(Scalar, bool)>> {
pub(crate) fn sapling_auth_path<W: WitnessTrait + ?Sized>(
witness: &W,
) -> Vec<Option<(Scalar, bool)>> {
let mut auth_path = vec![];
for element in &witness.get_auth_path() {
let sapling_element = match element {
Expand All @@ -305,7 +307,7 @@ pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec<Option<(Scala
/// like making Witness a trait since it's otherwise very simple.
/// So this hacky function gets to live here.
#[cfg(feature = "transaction-proofs")]
pub(crate) fn position(witness: &dyn WitnessTrait) -> u64 {
pub(crate) fn position<W: WitnessTrait + ?Sized>(witness: &W) -> u64 {
let mut pos = 0;
for (i, element) in witness.get_auth_path().iter().enumerate() {
if let WitnessNode::Right(_) = element {
Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust/src/transaction/proposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: WitnessTrait + ?Sized>(
&mut self,
note: Note,
witness: &dyn WitnessTrait,
witness: &W,
) -> Result<(), IronfishError> {
self.value_balances
.add(note.asset_id(), note.value().try_into()?)?;
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/transaction/spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: WitnessTrait + ?Sized>(note: Note, witness: &W) -> Self {
let value_commitment = ValueCommitment::new(note.value, note.asset_generator());

SpendBuilder {
Expand Down

0 comments on commit d2545ee

Please sign in to comment.