Skip to content

Commit 1f645ad

Browse files
committed
Merge #582: Do some random trivial fixes
4067238 Remove unnecessary path from Terminal (Tobin C. Harding) c6fa7ca Import Terminal::* to make code more terse (Tobin C. Harding) c3c508e Remove double whitespace (Tobin C. Harding) Pull request description: All changes explained in their respective patch. ACKs for top commit: apoelstra: ACK 4067238 Tree-SHA512: 614c652e8037f65884bd8514f6a4fd50f0b3d1be0bfa31baa8372d8491d0b9b2b35057d785260d782b2255ef9c82a246ad4b534ce1d9a6cc33cba6fa384b8bc9
2 parents d1051cb + 4067238 commit 1f645ad

File tree

4 files changed

+48
-71
lines changed

4 files changed

+48
-71
lines changed

src/descriptor/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness};
2121
use sync::Arc;
2222

2323
use self::checksum::verify_checksum;
24+
use crate::miniscript::decode::Terminal;
2425
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
2526
use crate::prelude::*;
2627
use crate::{
27-
expression, hash256, miniscript, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier,
28-
ToPublicKey, TranslateErr, TranslatePk, Translator,
28+
expression, hash256, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey,
29+
TranslateErr, TranslatePk, Translator,
2930
};
3031

3132
mod bare;
@@ -166,12 +167,10 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
166167
/// Create a new pk descriptor
167168
pub fn new_pk(pk: Pk) -> Self {
168169
// roundabout way to constuct `c:pk_k(pk)`
169-
let ms: Miniscript<Pk, BareCtx> =
170-
Miniscript::from_ast(miniscript::decode::Terminal::Check(Arc::new(
171-
Miniscript::from_ast(miniscript::decode::Terminal::PkK(pk))
172-
.expect("Type check cannot fail"),
173-
)))
174-
.expect("Type check cannot fail");
170+
let ms: Miniscript<Pk, BareCtx> = Miniscript::from_ast(Terminal::Check(Arc::new(
171+
Miniscript::from_ast(Terminal::PkK(pk)).expect("Type check cannot fail"),
172+
)))
173+
.expect("Type check cannot fail");
175174
Descriptor::Bare(Bare::new(ms).expect("Context checks cannot fail for p2pk"))
176175
}
177176

src/descriptor/sortedmulti.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::miniscript::decode::Terminal;
1616
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
1717
use crate::prelude::*;
1818
use crate::{
19-
errstr, expression, miniscript, policy, script_num_size, Error, ForEachKey, Miniscript,
20-
MiniscriptKey, Satisfier, ToPublicKey, TranslateErr, Translator,
19+
errstr, expression, policy, script_num_size, Error, ForEachKey, Miniscript, MiniscriptKey,
20+
Satisfier, ToPublicKey, TranslateErr, Translator,
2121
};
2222

2323
/// Contents of a "sortedmulti" descriptor
@@ -44,7 +44,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
4444
// Check the limits before creating a new SortedMultiVec
4545
// For example, under p2sh context the scriptlen can only be
4646
// upto 520 bytes.
47-
let term: miniscript::decode::Terminal<Pk, Ctx> = Terminal::Multi(k, pks.clone());
47+
let term: Terminal<Pk, Ctx> = Terminal::Multi(k, pks.clone());
4848
let ms = Miniscript::from_ast(term)?;
4949

5050
// This would check all the consensus rules for p2sh/p2wsh and
@@ -225,9 +225,9 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for SortedMultiVec<Pk,
225225
#[cfg(test)]
226226
mod tests {
227227
use bitcoin::secp256k1::PublicKey;
228-
use miniscript::context::Legacy;
229228

230229
use super::*;
230+
use crate::miniscript::context::Legacy;
231231

232232
#[test]
233233
fn too_many_pubkeys() {

src/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::prelude::*;
88
use crate::{errstr, Error, MAX_RECURSION_DEPTH};
99

1010
/// Allowed characters are descriptor strings.
11-
pub const INPUT_CHARSET: &str = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
11+
pub const INPUT_CHARSET: &str = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
1212

1313
/// Map of valid characters in descriptor strings.
1414
#[rustfmt::skip]

src/iter/mod.rs

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,52 @@ use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};
1919

2020
impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for &'a Miniscript<Pk, Ctx> {
2121
fn as_node(&self) -> Tree<Self> {
22+
use Terminal::*;
2223
match self.node {
23-
Terminal::PkK(..)
24-
| Terminal::PkH(..)
25-
| Terminal::RawPkH(..)
26-
| Terminal::After(..)
27-
| Terminal::Older(..)
28-
| Terminal::Sha256(..)
29-
| Terminal::Hash256(..)
30-
| Terminal::Ripemd160(..)
31-
| Terminal::Hash160(..)
32-
| Terminal::True
33-
| Terminal::False
34-
| Terminal::Multi(..)
35-
| Terminal::MultiA(..) => Tree::Nullary,
36-
Terminal::Alt(ref sub)
37-
| Terminal::Swap(ref sub)
38-
| Terminal::Check(ref sub)
39-
| Terminal::DupIf(ref sub)
40-
| Terminal::Verify(ref sub)
41-
| Terminal::NonZero(ref sub)
42-
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(sub),
43-
Terminal::AndV(ref left, ref right)
44-
| Terminal::AndB(ref left, ref right)
45-
| Terminal::OrB(ref left, ref right)
46-
| Terminal::OrD(ref left, ref right)
47-
| Terminal::OrC(ref left, ref right)
48-
| Terminal::OrI(ref left, ref right) => Tree::Binary(left, right),
49-
Terminal::AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
50-
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
24+
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
25+
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
26+
Alt(ref sub)
27+
| Swap(ref sub)
28+
| Check(ref sub)
29+
| DupIf(ref sub)
30+
| Verify(ref sub)
31+
| NonZero(ref sub)
32+
| ZeroNotEqual(ref sub) => Tree::Unary(sub),
33+
AndV(ref left, ref right)
34+
| AndB(ref left, ref right)
35+
| OrB(ref left, ref right)
36+
| OrD(ref left, ref right)
37+
| OrC(ref left, ref right)
38+
| OrI(ref left, ref right) => Tree::Binary(left, right),
39+
AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
40+
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
5141
}
5242
}
5343
}
5444

5545
impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>> {
5646
fn as_node(&self) -> Tree<Self> {
47+
use Terminal::*;
5748
match self.node {
58-
Terminal::PkK(..)
59-
| Terminal::PkH(..)
60-
| Terminal::RawPkH(..)
61-
| Terminal::After(..)
62-
| Terminal::Older(..)
63-
| Terminal::Sha256(..)
64-
| Terminal::Hash256(..)
65-
| Terminal::Ripemd160(..)
66-
| Terminal::Hash160(..)
67-
| Terminal::True
68-
| Terminal::False
69-
| Terminal::Multi(..)
70-
| Terminal::MultiA(..) => Tree::Nullary,
71-
Terminal::Alt(ref sub)
72-
| Terminal::Swap(ref sub)
73-
| Terminal::Check(ref sub)
74-
| Terminal::DupIf(ref sub)
75-
| Terminal::Verify(ref sub)
76-
| Terminal::NonZero(ref sub)
77-
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
78-
Terminal::AndV(ref left, ref right)
79-
| Terminal::AndB(ref left, ref right)
80-
| Terminal::OrB(ref left, ref right)
81-
| Terminal::OrD(ref left, ref right)
82-
| Terminal::OrC(ref left, ref right)
83-
| Terminal::OrI(ref left, ref right) => {
84-
Tree::Binary(Arc::clone(left), Arc::clone(right))
85-
}
86-
Terminal::AndOr(ref a, ref b, ref c) => {
49+
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
50+
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
51+
Alt(ref sub)
52+
| Swap(ref sub)
53+
| Check(ref sub)
54+
| DupIf(ref sub)
55+
| Verify(ref sub)
56+
| NonZero(ref sub)
57+
| ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
58+
AndV(ref left, ref right)
59+
| AndB(ref left, ref right)
60+
| OrB(ref left, ref right)
61+
| OrD(ref left, ref right)
62+
| OrC(ref left, ref right)
63+
| OrI(ref left, ref right) => Tree::Binary(Arc::clone(left), Arc::clone(right)),
64+
AndOr(ref a, ref b, ref c) => {
8765
Tree::Nary(Arc::from([Arc::clone(a), Arc::clone(b), Arc::clone(c)]))
8866
}
89-
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
67+
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
9068
}
9169
}
9270
}

0 commit comments

Comments
 (0)