From 532299d46eaa2802356049b209a40e6289ad2621 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 12 Jun 2019 23:11:51 +0100 Subject: [PATCH] Allow transaction::Builder RNG to be configured --- zcash_primitives/src/transaction/builder.rs | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 2ea4d0d..4edcd20 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -178,8 +178,8 @@ impl TransactionMetadata { } /// Generates a [`Transaction`] from its inputs and outputs. -pub struct Builder { - rng: OsRng, +pub struct Builder { + rng: R, mtx: TransactionData, fee: Amount, anchor: Option, @@ -188,9 +188,9 @@ pub struct Builder { change_address: Option<(OutgoingViewingKey, PaymentAddress)>, } -impl Builder { +impl Builder { /// Creates a new `Builder` targeted for inclusion in the block with the given height, - /// using default values for general transaction fields. + /// using default values for general transaction fields and the default OS random. /// /// # Default values /// @@ -198,12 +198,27 @@ impl Builder { /// expiry delta (20 blocks). /// /// The fee will be set to the default fee (0.0001 ZEC). - pub fn new(height: u32) -> Builder { + pub fn new(height: u32) -> Self { + Builder::new_with_rng(height, OsRng) + } +} + +impl Builder { + /// Creates a new `Builder` targeted for inclusion in the block with the given height + /// and randomness source, using default values for general transaction fields. + /// + /// # Default values + /// + /// The expiry height will be set to the given height plus the default transaction + /// expiry delta (20 blocks). + /// + /// The fee will be set to the default fee (0.0001 ZEC). + pub fn new_with_rng(height: u32, rng: R) -> Builder { let mut mtx = TransactionData::new(); mtx.expiry_height = height + DEFAULT_TX_EXPIRY_DELTA; Builder { - rng: OsRng, + rng, mtx, fee: DEFAULT_FEE, anchor: None,