Skip to content

Commit 0bd872c

Browse files
committed
wip: Use review suggestions
1 parent 28eb5c7 commit 0bd872c

File tree

14 files changed

+28
-47
lines changed

14 files changed

+28
-47
lines changed

src/descriptor/bare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737

3838
/// Create a Bare Descriptor. That is descriptor that is
3939
/// not wrapped in sh or wsh. This covers the Pk descriptor
40-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
40+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
4141
pub struct Bare<Pk: MiniscriptKey> {
4242
/// underlying miniscript
4343
ms: Miniscript<Pk, BareCtx>,

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub use self::key::{
7070
pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
7171

7272
/// Script descriptor
73-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
73+
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash)]
7474
pub enum Descriptor<Pk: MiniscriptKey> {
7575
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
7676
Bare(Bare<Pk>),

src/descriptor/segwitv0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::{
3333
TranslatePk,
3434
};
3535
/// A Segwitv0 wsh descriptor
36-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
36+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
3737
pub struct Wsh<Pk: MiniscriptKey> {
3838
/// underlying miniscript
3939
inner: WshInner<Pk>,
@@ -177,7 +177,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
177177
}
178178

179179
/// Wsh Inner
180-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
180+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
181181
pub enum WshInner<Pk: MiniscriptKey> {
182182
/// Sorted Multi
183183
SortedMulti(SortedMultiVec<Pk, Segwitv0>),

src/descriptor/sh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ use crate::{
3737
};
3838

3939
/// A Legacy p2sh Descriptor
40-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
40+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
4141
pub struct Sh<Pk: MiniscriptKey> {
4242
/// underlying miniscript
4343
inner: ShInner<Pk>,
4444
}
4545

4646
/// Sh Inner
47-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
47+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
4848
pub enum ShInner<Pk: MiniscriptKey> {
4949
/// Nested Wsh
5050
Wsh(Wsh<Pk>),

src/descriptor/tr.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
/// A Taproot Tree representation.
2626
// Hidden leaves are not yet supported in descriptor spec. Conceptually, it should
2727
// be simple to integrate those here, but it is best to wait on core for the exact syntax.
28-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
28+
#[derive(Clone, PartialOrd, Eq, PartialEq, Hash)]
2929
pub enum TapTree<Pk: MiniscriptKey> {
3030
/// A taproot tree structure
3131
Tree(Arc<TapTree<Pk>>, Arc<TapTree<Pk>>),
@@ -89,16 +89,6 @@ impl<Pk: MiniscriptKey> PartialOrd for Tr<Pk> {
8989
}
9090
}
9191

92-
impl<Pk: MiniscriptKey> Ord for Tr<Pk> {
93-
fn cmp(&self, other: &Self) -> cmp::Ordering {
94-
match self.internal_key.cmp(&other.internal_key) {
95-
cmp::Ordering::Equal => {}
96-
ord => return ord,
97-
}
98-
self.tree.cmp(&other.tree)
99-
}
100-
}
101-
10292
impl<Pk: MiniscriptKey> hash::Hash for Tr<Pk> {
10393
fn hash<H: hash::Hasher>(&self, state: &mut H) {
10494
self.internal_key.hash(state);

src/interpreter/stack.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use bitcoin;
1818
use bitcoin::blockdata::{opcodes, script};
1919
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
20-
use bitcoin::{locktime, LockTime};
20+
use bitcoin::LockTime;
2121

2222
use super::error::PkEvalErrInner;
2323
use super::{
@@ -235,13 +235,13 @@ impl<'txin> Stack<'txin> {
235235
n: &LockTime,
236236
lock_time: LockTime,
237237
) -> Option<Result<SatisfiedConstraint, Error>> {
238-
match locktime::is_satisfied(*n, lock_time) {
238+
match lock_time.is_satisfied(*n) {
239239
Ok(true) => {
240240
self.push(Element::Satisfied);
241241
Some(Ok(SatisfiedConstraint::AbsoluteTimelock { n: *n }))
242242
},
243-
Ok(false) => Some(Err(Error::AbsoluteLocktimeNotMet(n.to_u32()))),
244-
Err(_) => Some(Err(Error::AbsoluteLocktimeComparisonInvalid(n.to_u32(), lock_time.to_u32()))),
243+
Ok(false) => Some(Err(Error::AbsoluteLocktimeNotMet(n.to_consensus_u32()))),
244+
Err(_) => Some(Err(Error::AbsoluteLocktimeComparisonInvalid(n.to_consensus_u32(), lock_time.to_consensus_u32()))),
245245
}
246246
}
247247

src/miniscript/astelem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
655655
.push_slice(&Pk::hash_to_hash160(hash)[..])
656656
.push_opcode(opcodes::all::OP_EQUALVERIFY),
657657
Terminal::After(t) => builder
658-
.push_int(t.to_u32() as i64)
658+
.push_int(t.to_consensus_u32() as i64)
659659
.push_opcode(opcodes::all::OP_CLTV),
660660
Terminal::Older(t) => builder.push_int(t as i64).push_opcode(opcodes::all::OP_CSV),
661661
Terminal::Sha256(h) => builder
@@ -790,7 +790,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
790790
match *self {
791791
Terminal::PkK(ref pk) => Ctx::pk_len(pk),
792792
Terminal::PkH(..) => 24,
793-
Terminal::After(n) => script_num_size(n.to_u32() as usize) + 1,
793+
Terminal::After(n) => script_num_size(n.to_consensus_u32() as usize) + 1,
794794
Terminal::Older(n) => script_num_size(n as usize) + 1,
795795
Terminal::Sha256(..) => 33 + 6,
796796
Terminal::Hash256(..) => 33 + 6,

src/miniscript/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ enum NonTerm {
125125
}
126126
/// All AST elements
127127
#[allow(broken_intra_doc_links)]
128-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
128+
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash)]
129129
pub enum Terminal<Pk: MiniscriptKey, Ctx: ScriptContext> {
130130
/// `1`
131131
True,

src/miniscript/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,7 @@ pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
7676
/// by the ast.
7777
impl<Pk: MiniscriptKey, Ctx: ScriptContext> PartialOrd for Miniscript<Pk, Ctx> {
7878
fn partial_cmp(&self, other: &Miniscript<Pk, Ctx>) -> Option<cmp::Ordering> {
79-
Some(self.node.cmp(&other.node))
80-
}
81-
}
82-
83-
/// `Ord` of `Miniscript` must depend only on node and not the type information.
84-
/// The type information and extra_properties can be deterministically determined
85-
/// by the ast.
86-
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Ord for Miniscript<Pk, Ctx> {
87-
fn cmp(&self, other: &Miniscript<Pk, Ctx>) -> cmp::Ordering {
88-
self.node.cmp(&other.node)
79+
self.node.partial_cmp(&other.node)
8980
}
9081
}
9182

src/miniscript/types/extra_props.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl Property for ExtData {
342342

343343
fn from_after(t: LockTime) -> Self {
344344
ExtData {
345-
pk_cost: script_num_size(t.to_u32() as usize) + 1,
345+
pk_cost: script_num_size(t.to_consensus_u32() as usize) + 1,
346346
has_free_verify: false,
347347
ops: OpLimits::new(1, Some(0), None),
348348
stack_elem_count_sat: Some(0),
@@ -936,7 +936,7 @@ impl Property for ExtData {
936936
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
937937
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
938938
// only consumes 4 bytes from the stack.
939-
if t.to_u32() == 0 || (t.to_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
939+
if t.to_consensus_u32() == 0 || (t.to_consensus_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
940940
return Err(Error {
941941
fragment: fragment.clone(),
942942
error: ErrorKind::InvalidTime,

src/miniscript/types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub enum ErrorKind {
100100
}
101101

102102
/// Error type for typechecking
103-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
103+
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
104104
pub struct Error<Pk: MiniscriptKey, Ctx: ScriptContext> {
105105
/// The fragment that failed typecheck
106106
pub fragment: Terminal<Pk, Ctx>,
@@ -306,7 +306,7 @@ pub trait Property: Sized {
306306
/// Type property of an absolute timelock. Default implementation simply
307307
/// passes through to `from_time`
308308
fn from_after(t: LockTime) -> Self {
309-
Self::from_time(t.to_u32())
309+
Self::from_time(t.to_consensus_u32())
310310
}
311311

312312
/// Type property of a relative timelock. Default implementation simply
@@ -439,7 +439,7 @@ pub trait Property: Sized {
439439
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
440440
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
441441
// only consumes 4 bytes from the stack.
442-
if t.to_u32() == 0 || (t.to_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
442+
if t.to_consensus_u32() == 0 || (t.to_consensus_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
443443
return Err(Error {
444444
fragment: fragment.clone(),
445445
error: ErrorKind::InvalidTime,
@@ -822,7 +822,7 @@ impl Property for Type {
822822
// Note that for CLTV this is a limitation not of Bitcoin but Miniscript. The
823823
// number on the stack would be a 5 bytes signed integer but Miniscript's B type
824824
// only consumes 4 bytes from the stack.
825-
if t.to_u32() == 0 || (t.to_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
825+
if t.to_consensus_u32() == 0 || (t.to_consensus_u32() & SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 {
826826
return Err(Error {
827827
fragment: fragment.clone(),
828828
error: ErrorKind::InvalidTime,

src/policy/concrete.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use crate::{errstr, Error, ForEach, ForEachKey, MiniscriptKey};
4646
/// Concrete policy which corresponds directly to a Miniscript structure,
4747
/// and whose disjunctions are annotated with satisfaction probabilities
4848
/// to assist the compiler
49-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
49+
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash)]
5050
pub enum Policy<Pk: MiniscriptKey> {
5151
/// Unsatisfiable
5252
Unsatisfiable,
@@ -532,9 +532,9 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
532532
}
533533
}
534534
Policy::After(n) => {
535-
if n.to_u32() == 0 {
535+
if n.to_consensus_u32() == 0 {
536536
Err(PolicyError::ZeroTime)
537-
} else if n.to_u32() > 2u32.pow(31) {
537+
} else if n.to_consensus_u32() > 2u32.pow(31) {
538538
Err(PolicyError::TimeTooFar)
539539
} else {
540540
Ok(())

src/policy/semantic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{errstr, expression, Error, ForEach, ForEachKey, MiniscriptKey};
3232
/// Semantic policies store only hashes of keys to ensure that objects
3333
/// representing the same policy are lifted to the same `Semantic`,
3434
/// regardless of their choice of `pk` or `pk_h` nodes.
35-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
35+
#[derive(Clone, PartialEq, Eq, PartialOrd)]
3636
pub enum Policy<Pk: MiniscriptKey> {
3737
/// Unsatisfiable
3838
Unsatisfiable,
@@ -504,7 +504,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
504504
| Policy::Ripemd160(..)
505505
| Policy::Hash160(..) => vec![],
506506
Policy::Older(..) => vec![],
507-
Policy::After(t) => vec![t.to_u32()],
507+
Policy::After(t) => vec![t.to_consensus_u32()],
508508
Policy::Threshold(_, ref subs) => subs.iter().fold(vec![], |mut acc, x| {
509509
acc.extend(x.real_absolute_timelocks());
510510
acc

src/psbt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use bitcoin::secp256k1::{self, Secp256k1};
2929
use bitcoin::util::psbt::{self, PartiallySignedTransaction as Psbt};
3030
use bitcoin::util::sighash::SighashCache;
3131
use bitcoin::util::taproot::{self, ControlBlock, LeafVersion, TapLeafHash};
32-
use bitcoin::{self, locktime, EcdsaSighashType, LockTime, SchnorrSighashType, Script};
32+
use bitcoin::{self, EcdsaSighashType, LockTime, SchnorrSighashType, Script};
3333

3434
use crate::miniscript::iter::PkPkh;
3535
use crate::miniscript::limits::SEQUENCE_LOCKTIME_DISABLE_FLAG;
@@ -343,7 +343,7 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfie
343343
return false;
344344
}
345345

346-
match locktime::is_satisfied(n, lock_time) {
346+
match lock_time.is_satisfied(n) {
347347
Err(_) => false,
348348
Ok(res) => res,
349349
}

0 commit comments

Comments
 (0)