From 9768e4af78ee12cef1e0e52f0fbc502a50251ced Mon Sep 17 00:00:00 2001 From: CalDescent <> Date: Wed, 18 May 2022 19:14:01 +0100 Subject: [PATCH] Allow lock time to be optionally set when adding a transparent input. --- zcash_primitives/src/transaction/builder.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 55fef60..8e73839 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -175,6 +175,7 @@ impl TransparentInputs { coin: TxOut, secret: Vec, redeem_script: Vec, + lock_time: u32, ) -> Result<(), Error> { if coin.value.is_negative() { return Err(Error::InvalidAmount); @@ -197,6 +198,12 @@ impl TransparentInputs { mtx.vin.push(TxIn::new(utxo)); self.inputs.push(TransparentInputInfo { sk, pubkey, coin, secret, redeem_script }); + // Set lock time if present + if (lock_time > 0) { + mtx.sequence = 4294967294; // max value (0xFFFFFFFF - 1), so lockTime can be used but not RBF + mtx.lock_time = lock_time; + } + Ok(()) } @@ -409,7 +416,8 @@ impl Builder { utxo: OutPoint, coin: TxOut, ) -> Result<(), Error> { - self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, Vec::new(), Vec::new()) + let lock_time: u32 = 0; + self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, Vec::new(), Vec::new(), lock_time) } /// Adds a transparent coin to be spent in this transaction, with HTLC secret. @@ -421,8 +429,9 @@ impl Builder { coin: TxOut, secret: Vec, redeem_script: Vec, + lock_time: u32, ) -> Result<(), Error> { - self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, secret, redeem_script) + self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, secret, redeem_script, lock_time) } /// Adds a transparent address to send funds to.