Skip to content

Commit d2545ee

Browse files
committed
Rust: remove unnecessary uses of dynamic dispatch
1 parent 18dd964 commit d2545ee

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

ironfish-rust/src/merkle_note.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ impl MerkleNote {
285285
}
286286

287287
#[cfg(feature = "transaction-proofs")]
288-
pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec<Option<(Scalar, bool)>> {
288+
pub(crate) fn sapling_auth_path<W: WitnessTrait + ?Sized>(
289+
witness: &W,
290+
) -> Vec<Option<(Scalar, bool)>> {
289291
let mut auth_path = vec![];
290292
for element in &witness.get_auth_path() {
291293
let sapling_element = match element {
@@ -305,7 +307,7 @@ pub(crate) fn sapling_auth_path(witness: &dyn WitnessTrait) -> Vec<Option<(Scala
305307
/// like making Witness a trait since it's otherwise very simple.
306308
/// So this hacky function gets to live here.
307309
#[cfg(feature = "transaction-proofs")]
308-
pub(crate) fn position(witness: &dyn WitnessTrait) -> u64 {
310+
pub(crate) fn position<W: WitnessTrait + ?Sized>(witness: &W) -> u64 {
309311
let mut pos = 0;
310312
for (i, element) in witness.get_auth_path().iter().enumerate() {
311313
if let WitnessNode::Right(_) = element {

ironfish-rust/src/transaction/proposed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl ProposedTransaction {
102102
}
103103

104104
/// Spend the note owned by spender_key at the given witness location.
105-
pub fn add_spend(
105+
pub fn add_spend<W: WitnessTrait + ?Sized>(
106106
&mut self,
107107
note: Note,
108-
witness: &dyn WitnessTrait,
108+
witness: &W,
109109
) -> Result<(), IronfishError> {
110110
self.value_balances
111111
.add(note.asset_id(), note.value().try_into()?)?;

ironfish-rust/src/transaction/spends.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl SpendBuilder {
6868
/// This is the only time this API thinks about the merkle tree. The witness
6969
/// contains the root-hash at the time the witness was created and the path
7070
/// to verify the location of that note in the tree.
71-
pub(crate) fn new(note: Note, witness: &dyn WitnessTrait) -> Self {
71+
pub(crate) fn new<W: WitnessTrait + ?Sized>(note: Note, witness: &W) -> Self {
7272
let value_commitment = ValueCommitment::new(note.value, note.asset_generator());
7373

7474
SpendBuilder {

0 commit comments

Comments
 (0)