Skip to content

Commit 882d791

Browse files
committed
Depend on bitcoin 0.29.0
Depend on the newly released bitcoin 0.29.0
1 parent 3bfb938 commit 882d791

29 files changed

+426
-306
lines changed

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ std = ["bitcoin/std", "bitcoin/secp-recovery"]
1616
no-std = ["hashbrown", "bitcoin/no-std"]
1717
compiler = []
1818
trace = []
19+
1920
unstable = []
20-
serde = ["actual-serde", "bitcoin/use-serde"]
21+
serde = ["actual-serde", "bitcoin/serde"]
2122
rand = ["bitcoin/rand"]
2223

2324
[dependencies]
24-
bitcoin = { version = "0.28.1", default-features = false }
25+
bitcoin = { version = "0.29.1", default-features = false }
2526
hashbrown = { version = "0.11", optional = true }
2627

2728
# Do NOT use this as a feature! Use the `serde` feature instead.
2829
actual-serde = { package = "serde", version = "1.0", optional = true }
2930

30-
3131
[dev-dependencies]
32-
bitcoind = {version = "0.26.1", features=["22_0"]}
32+
bitcoind = { version = "0.27.0", features=["23_0"] }
3333
actual-rand = { package = "rand", version = "0.8.4"}
34-
secp256k1 = {version = "0.22.1", features = ["rand-std"]}
34+
secp256k1 = {version = "0.24.0", features = ["rand-std"]}
3535

3636
[[example]]
3737
name = "htlc"

examples/sign_multisig.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::collections::HashMap;
1818
use std::str::FromStr;
1919

2020
use bitcoin::blockdata::witness::Witness;
21-
use bitcoin::secp256k1;
21+
use bitcoin::{secp256k1, PackedLockTime, Sequence};
2222

2323
fn main() {
2424
let mut tx = spending_transaction();
@@ -91,11 +91,11 @@ fn main() {
9191
fn spending_transaction() -> bitcoin::Transaction {
9292
bitcoin::Transaction {
9393
version: 2,
94-
lock_time: 0,
94+
lock_time: PackedLockTime::ZERO,
9595
input: vec![bitcoin::TxIn {
9696
previous_output: Default::default(),
9797
script_sig: bitcoin::Script::new(),
98-
sequence: 0xffffffff,
98+
sequence: Sequence::MAX,
9999
witness: Witness::default(),
100100
}],
101101
output: vec![bitcoin::TxOut {

examples/taproot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn main() {
102102
let secp = secp256k1::Secp256k1::new();
103103
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
104104
// Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor
105-
let unspendable_pubkey = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);
105+
let (unspendable_pubkey, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);
106106

107107
pk_map.insert("UNSPENDABLE_KEY".to_string(), unspendable_pubkey);
108108
let pubkeys = hardcoded_xonlypubkeys();

examples/verify_tx.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::str::FromStr;
1919
use bitcoin::consensus::Decodable;
2020
use bitcoin::secp256k1::{self, Secp256k1};
2121
use bitcoin::util::sighash;
22+
use bitcoin::{LockTime, Sequence};
2223
use miniscript::interpreter::KeySigPair;
2324

2425
fn main() {
@@ -33,8 +34,8 @@ fn main() {
3334
&spk_input_1,
3435
&tx.input[0].script_sig,
3536
&tx.input[0].witness,
36-
0,
37-
0,
37+
Sequence::ZERO,
38+
LockTime::ZERO,
3839
)
3940
.unwrap();
4041

src/descriptor/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ mod tests {
860860
use bitcoin::hashes::hex::{FromHex, ToHex};
861861
use bitcoin::hashes::{hash160, sha256};
862862
use bitcoin::util::bip32;
863-
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey};
863+
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey, Sequence};
864864

865865
use super::checksum::desc_checksum;
866866
use super::tr::Tr;
@@ -1155,7 +1155,7 @@ mod tests {
11551155
let mut txin = bitcoin::TxIn {
11561156
previous_output: bitcoin::OutPoint::default(),
11571157
script_sig: bitcoin::Script::new(),
1158-
sequence: 100,
1158+
sequence: Sequence::from_height(100),
11591159
witness: Witness::default(),
11601160
};
11611161
let bare = Descriptor::new_bare(ms.clone()).unwrap();
@@ -1166,7 +1166,7 @@ mod tests {
11661166
bitcoin::TxIn {
11671167
previous_output: bitcoin::OutPoint::default(),
11681168
script_sig: script::Builder::new().push_slice(&sigser[..]).into_script(),
1169-
sequence: 100,
1169+
sequence: Sequence::from_height(100),
11701170
witness: Witness::default(),
11711171
}
11721172
);
@@ -1182,7 +1182,7 @@ mod tests {
11821182
.push_slice(&sigser[..])
11831183
.push_key(&pk)
11841184
.into_script(),
1185-
sequence: 100,
1185+
sequence: Sequence::from_height(100),
11861186
witness: Witness::default(),
11871187
}
11881188
);
@@ -1195,7 +1195,7 @@ mod tests {
11951195
bitcoin::TxIn {
11961196
previous_output: bitcoin::OutPoint::default(),
11971197
script_sig: bitcoin::Script::new(),
1198-
sequence: 100,
1198+
sequence: Sequence::from_height(100),
11991199
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
12001200
}
12011201
);
@@ -1216,7 +1216,7 @@ mod tests {
12161216
script_sig: script::Builder::new()
12171217
.push_slice(&redeem_script[..])
12181218
.into_script(),
1219-
sequence: 100,
1219+
sequence: Sequence::from_height(100),
12201220
witness: Witness::from_vec(vec![sigser.clone(), pk.to_bytes(),]),
12211221
}
12221222
);
@@ -1238,7 +1238,7 @@ mod tests {
12381238
.push_slice(&sigser[..])
12391239
.push_slice(&ms.encode()[..])
12401240
.into_script(),
1241-
sequence: 100,
1241+
sequence: Sequence::from_height(100),
12421242
witness: Witness::default(),
12431243
}
12441244
);
@@ -1253,7 +1253,7 @@ mod tests {
12531253
bitcoin::TxIn {
12541254
previous_output: bitcoin::OutPoint::default(),
12551255
script_sig: bitcoin::Script::new(),
1256-
sequence: 100,
1256+
sequence: Sequence::from_height(100),
12571257
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
12581258
}
12591259
);
@@ -1268,7 +1268,7 @@ mod tests {
12681268
script_sig: script::Builder::new()
12691269
.push_slice(&ms.encode().to_v0_p2wsh()[..])
12701270
.into_script(),
1271-
sequence: 100,
1271+
sequence: Sequence::from_height(100),
12721272
witness: Witness::from_vec(vec![sigser.clone(), ms.encode().into_bytes(),]),
12731273
}
12741274
);
@@ -1401,7 +1401,7 @@ mod tests {
14011401
let mut txin = bitcoin::TxIn {
14021402
previous_output: bitcoin::OutPoint::default(),
14031403
script_sig: bitcoin::Script::new(),
1404-
sequence: 0,
1404+
sequence: Sequence::ZERO,
14051405
witness: Witness::default(),
14061406
};
14071407
let satisfier = {

src/descriptor/tr.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::{fmt, hash};
55

66
use bitcoin::blockdata::opcodes;
77
use bitcoin::util::taproot::{
8-
LeafVersion, TaprootBuilder, TaprootBuilderError, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
8+
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
99
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
1010
};
1111
use bitcoin::{secp256k1, Address, Network, Script};
@@ -238,26 +238,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
238238
// Assert builder cannot error here because we have a well formed descriptor
239239
match builder.finalize(&secp, self.internal_key.to_x_only_pubkey()) {
240240
Ok(data) => data,
241-
Err(e) => match e {
242-
TaprootBuilderError::InvalidMerkleTreeDepth(_) => {
243-
unreachable!("Depth checked in struct construction")
244-
}
245-
TaprootBuilderError::NodeNotInDfsOrder => {
246-
unreachable!("Insertion is called in DFS order")
247-
}
248-
TaprootBuilderError::OverCompleteTree => {
249-
unreachable!("Taptree is a well formed tree")
250-
}
251-
TaprootBuilderError::InvalidInternalKey(_) => {
252-
unreachable!("Internal key checked for validity")
253-
}
254-
TaprootBuilderError::IncompleteTree => {
255-
unreachable!("Taptree is a well formed tree")
256-
}
257-
TaprootBuilderError::EmptyTree => {
258-
unreachable!("Taptree is a well formed tree with atleast 1 element")
259-
}
260-
},
241+
Err(_) => unreachable!("We know the builder can be finalized"),
261242
}
262243
};
263244
let spend_info = Arc::new(data);

src/interpreter/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use crate::prelude::*;
2929
pub enum Error {
3030
/// Could not satisfy, absolute locktime not met
3131
AbsoluteLocktimeNotMet(u32),
32+
/// Could not satisfy, lock time values are different units
33+
AbsoluteLocktimeComparisonInvalid(u32, u32),
3234
/// Cannot Infer a taproot descriptor
3335
/// Key spends cannot infer the internal key of the descriptor
3436
/// Inferring script spends is possible, but is hidden nodes are currently
@@ -129,6 +131,11 @@ impl fmt::Display for Error {
129131
"required absolute locktime CLTV of {} blocks, not met",
130132
n
131133
),
134+
Error::AbsoluteLocktimeComparisonInvalid(n, lock_time) => write!(
135+
f,
136+
"could not satisfy, lock time values are different units n: {} lock_time: {}",
137+
n, lock_time
138+
),
132139
Error::CannotInferTrDescriptors => write!(f, "Cannot infer taproot descriptors"),
133140
Error::ControlBlockParse(ref e) => write!(f, "Control block parse error {}", e),
134141
Error::ControlBlockVerificationError => {
@@ -198,6 +205,7 @@ impl error::Error for Error {
198205

199206
match self {
200207
AbsoluteLocktimeNotMet(_)
208+
| AbsoluteLocktimeComparisonInvalid(_, _)
201209
| CannotInferTrDescriptors
202210
| ControlBlockVerificationError
203211
| CouldNotEvaluate

src/interpreter/mod.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::str::FromStr;
2525
use bitcoin::blockdata::witness::Witness;
2626
use bitcoin::hashes::{hash160, ripemd160, sha256};
2727
use bitcoin::util::{sighash, taproot};
28-
use bitcoin::{self, secp256k1, TxOut};
28+
use bitcoin::{self, secp256k1, LockTime, Sequence, TxOut};
2929

3030
use crate::miniscript::context::NoChecks;
3131
use crate::miniscript::ScriptContext;
@@ -48,8 +48,8 @@ pub struct Interpreter<'txin> {
4848
/// For non-Taproot spends, the scriptCode; for Taproot script-spends, this
4949
/// is the leaf script; for key-spends it is `None`.
5050
script_code: Option<bitcoin::Script>,
51-
age: u32,
52-
lock_time: u32,
51+
age: Sequence,
52+
lock_time: LockTime,
5353
}
5454

5555
// A type representing functions for checking signatures that accept both
@@ -173,8 +173,8 @@ impl<'txin> Interpreter<'txin> {
173173
spk: &bitcoin::Script,
174174
script_sig: &'txin bitcoin::Script,
175175
witness: &'txin Witness,
176-
age: u32, // CSV, relative lock time.
177-
lock_time: u32, // CLTV, absolute lock time.
176+
age: Sequence, // CSV, relative lock time.
177+
lock_time: LockTime, // CLTV, absolute lock time.
178178
) -> Result<Self, Error> {
179179
let (inner, stack, script_code) = inner::from_txdata(spk, script_sig, witness)?;
180180
Ok(Interpreter {
@@ -491,12 +491,12 @@ pub enum SatisfiedConstraint {
491491
///Relative Timelock for CSV.
492492
RelativeTimelock {
493493
/// The value of RelativeTimelock
494-
time: u32,
494+
n: Sequence,
495495
},
496496
///Absolute Timelock for CLTV.
497497
AbsoluteTimelock {
498498
/// The value of Absolute timelock
499-
time: u32,
499+
n: LockTime,
500500
},
501501
}
502502

@@ -531,8 +531,8 @@ pub struct Iter<'intp, 'txin: 'intp> {
531531
public_key: Option<&'intp BitcoinKey>,
532532
state: Vec<NodeEvaluationState<'intp>>,
533533
stack: Stack<'txin>,
534-
age: u32,
535-
lock_time: u32,
534+
age: Sequence,
535+
lock_time: LockTime,
536536
has_errored: bool,
537537
}
538538

@@ -619,7 +619,7 @@ where
619619
Terminal::After(ref n) => {
620620
debug_assert_eq!(node_state.n_evaluated, 0);
621621
debug_assert_eq!(node_state.n_satisfied, 0);
622-
let res = self.stack.evaluate_after(n, self.lock_time);
622+
let res = self.stack.evaluate_after(&n.into(), self.lock_time);
623623
if res.is_some() {
624624
return res;
625625
}
@@ -1094,8 +1094,9 @@ mod tests {
10941094
pks.push(pk);
10951095
der_sigs.push(sigser);
10961096

1097-
let keypair = bitcoin::KeyPair::from_secret_key(&secp, sk);
1098-
x_only_pks.push(bitcoin::XOnlyPublicKey::from_keypair(&keypair));
1097+
let keypair = bitcoin::KeyPair::from_secret_key(&secp, &sk);
1098+
let (x_only_pk, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&keypair);
1099+
x_only_pks.push(x_only_pk);
10991100
let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]);
11001101
let schnorr_sig = bitcoin::SchnorrSig {
11011102
sig: schnorr_sig,
@@ -1144,8 +1145,8 @@ mod tests {
11441145
n_evaluated: 0,
11451146
n_satisfied: 0,
11461147
}],
1147-
age: 1002,
1148-
lock_time: 1002,
1148+
age: Sequence::from_height(1002),
1149+
lock_time: LockTime::from_height(1002).unwrap(),
11491150
has_errored: false,
11501151
}
11511152
}
@@ -1208,7 +1209,9 @@ mod tests {
12081209
let after_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
12091210
assert_eq!(
12101211
after_satisfied.unwrap(),
1211-
vec![SatisfiedConstraint::AbsoluteTimelock { time: 1000 }]
1212+
vec![SatisfiedConstraint::AbsoluteTimelock {
1213+
n: LockTime::from_height(1000).unwrap()
1214+
}]
12121215
);
12131216

12141217
//Check Older
@@ -1218,7 +1221,9 @@ mod tests {
12181221
let older_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
12191222
assert_eq!(
12201223
older_satisfied.unwrap(),
1221-
vec![SatisfiedConstraint::RelativeTimelock { time: 1000 }]
1224+
vec![SatisfiedConstraint::RelativeTimelock {
1225+
n: Sequence::from_height(1000)
1226+
}]
12221227
);
12231228

12241229
//Check Sha256

0 commit comments

Comments
 (0)