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,

0 commit comments

Comments
 (0)