Skip to content

Commit 0ed78e5

Browse files
committed
Add lock time types
Add a `LockTime` type to hold the nLockTime `u32` value. Use it in `Transaction` for `lock_time` instead of a `u32`. Make it public so this new type can be used by rust-miniscript and other downstream projects. Add a `PackedLockTime` type that wraps a raw `u32` and derives `Ord`, this type is for wrapping a consensus lock time value for nesting in types that would like to derive `Ord`.
1 parent 1390ee1 commit 0ed78e5

File tree

10 files changed

+842
-29
lines changed

10 files changed

+842
-29
lines changed

examples/ecdsa-psbt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ use bitcoin::util::bip32::{
4343
};
4444
use bitcoin::util::psbt::{self, Input, Psbt, PsbtSighashType};
4545
use bitcoin::{
46-
Address, Amount, Network, OutPoint, PrivateKey, PublicKey, Script, Sequence, Transaction, TxIn,
47-
TxOut, Txid, Witness,
46+
Address, Amount, Network, OutPoint, PackedLockTime, PrivateKey, PublicKey, Script, Sequence,
47+
Transaction, TxIn, TxOut, Txid, Witness,
4848
};
4949

5050
use self::psbt_sign::*;
@@ -207,7 +207,7 @@ impl WatchOnly {
207207

208208
let tx = Transaction {
209209
version: 2,
210-
lock_time: 0,
210+
lock_time: PackedLockTime::ZERO,
211211
input: vec![TxIn {
212212
previous_output: OutPoint {
213213
txid: Txid::from_hex(INPUT_UTXO_TXID)?,

src/blockdata/constants.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::hashes::hex::{self, HexIterator};
1616
use crate::hashes::{Hash, sha256d};
1717
use crate::blockdata::opcodes;
1818
use crate::blockdata::script;
19+
use crate::blockdata::locktime::PackedLockTime;
1920
use crate::blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn, Sequence};
2021
use crate::blockdata::block::{Block, BlockHeader};
2122
use crate::blockdata::witness::Witness;
@@ -73,7 +74,7 @@ fn bitcoin_genesis_tx() -> Transaction {
7374
// Base
7475
let mut ret = Transaction {
7576
version: 1,
76-
lock_time: 0,
77+
lock_time: PackedLockTime::ZERO,
7778
input: vec![],
7879
output: vec![],
7980
};
@@ -201,6 +202,7 @@ mod test {
201202
use crate::hashes::hex::{ToHex, FromHex};
202203
use crate::network::constants::Network;
203204
use crate::consensus::encode::serialize;
205+
use crate::blockdata::locktime::PackedLockTime;
204206

205207
#[test]
206208
fn bitcoin_genesis_first_transaction() {
@@ -218,7 +220,7 @@ mod test {
218220
assert_eq!(serialize(&gen.output[0].script_pubkey),
219221
Vec::from_hex("434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac").unwrap());
220222
assert_eq!(gen.output[0].value, 50 * COIN_VALUE);
221-
assert_eq!(gen.lock_time, 0);
223+
assert_eq!(gen.lock_time, PackedLockTime::ZERO);
222224

223225
assert_eq!(gen.wtxid().to_hex(), "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
224226
}

0 commit comments

Comments
 (0)