Skip to content

Do some random trivial fixes #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness};
use sync::Arc;

use self::checksum::verify_checksum;
use crate::miniscript::decode::Terminal;
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
use crate::prelude::*;
use crate::{
expression, hash256, miniscript, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier,
ToPublicKey, TranslateErr, TranslatePk, Translator,
expression, hash256, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey,
TranslateErr, TranslatePk, Translator,
};

mod bare;
Expand Down Expand Up @@ -167,12 +168,10 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
/// Create a new pk descriptor
pub fn new_pk(pk: Pk) -> Self {
// roundabout way to constuct `c:pk_k(pk)`
let ms: Miniscript<Pk, BareCtx> =
Miniscript::from_ast(miniscript::decode::Terminal::Check(Arc::new(
Miniscript::from_ast(miniscript::decode::Terminal::PkK(pk))
.expect("Type check cannot fail"),
)))
.expect("Type check cannot fail");
let ms: Miniscript<Pk, BareCtx> = Miniscript::from_ast(Terminal::Check(Arc::new(
Miniscript::from_ast(Terminal::PkK(pk)).expect("Type check cannot fail"),
)))
.expect("Type check cannot fail");
Descriptor::Bare(Bare::new(ms).expect("Context checks cannot fail for p2pk"))
}

Expand Down
8 changes: 4 additions & 4 deletions src/descriptor/sortedmulti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::miniscript::decode::Terminal;
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
use crate::prelude::*;
use crate::{
errstr, expression, miniscript, policy, script_num_size, Error, ForEachKey, Miniscript,
MiniscriptKey, Satisfier, ToPublicKey, TranslateErr, Translator,
errstr, expression, policy, script_num_size, Error, ForEachKey, Miniscript, MiniscriptKey,
Satisfier, ToPublicKey, TranslateErr, Translator,
};

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

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

use super::*;
use crate::miniscript::context::Legacy;

#[test]
fn too_many_pubkeys() {
Expand Down
2 changes: 1 addition & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::prelude::*;
use crate::{errstr, Error, MAX_RECURSION_DEPTH};

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

/// Map of valid characters in descriptor strings.
#[rustfmt::skip]
Expand Down
94 changes: 36 additions & 58 deletions src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,52 @@ use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for &'a Miniscript<Pk, Ctx> {
fn as_node(&self) -> Tree<Self> {
use Terminal::*;
match self.node {
Terminal::PkK(..)
| Terminal::PkH(..)
| Terminal::RawPkH(..)
| Terminal::After(..)
| Terminal::Older(..)
| Terminal::Sha256(..)
| Terminal::Hash256(..)
| Terminal::Ripemd160(..)
| Terminal::Hash160(..)
| Terminal::True
| Terminal::False
| Terminal::Multi(..)
| Terminal::MultiA(..) => Tree::Nullary,
Terminal::Alt(ref sub)
| Terminal::Swap(ref sub)
| Terminal::Check(ref sub)
| Terminal::DupIf(ref sub)
| Terminal::Verify(ref sub)
| Terminal::NonZero(ref sub)
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(sub),
Terminal::AndV(ref left, ref right)
| Terminal::AndB(ref left, ref right)
| Terminal::OrB(ref left, ref right)
| Terminal::OrD(ref left, ref right)
| Terminal::OrC(ref left, ref right)
| Terminal::OrI(ref left, ref right) => Tree::Binary(left, right),
Terminal::AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
Alt(ref sub)
| Swap(ref sub)
| Check(ref sub)
| DupIf(ref sub)
| Verify(ref sub)
| NonZero(ref sub)
| ZeroNotEqual(ref sub) => Tree::Unary(sub),
AndV(ref left, ref right)
| AndB(ref left, ref right)
| OrB(ref left, ref right)
| OrD(ref left, ref right)
| OrC(ref left, ref right)
| OrI(ref left, ref right) => Tree::Binary(left, right),
AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
}
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>> {
fn as_node(&self) -> Tree<Self> {
use Terminal::*;
match self.node {
Terminal::PkK(..)
| Terminal::PkH(..)
| Terminal::RawPkH(..)
| Terminal::After(..)
| Terminal::Older(..)
| Terminal::Sha256(..)
| Terminal::Hash256(..)
| Terminal::Ripemd160(..)
| Terminal::Hash160(..)
| Terminal::True
| Terminal::False
| Terminal::Multi(..)
| Terminal::MultiA(..) => Tree::Nullary,
Terminal::Alt(ref sub)
| Terminal::Swap(ref sub)
| Terminal::Check(ref sub)
| Terminal::DupIf(ref sub)
| Terminal::Verify(ref sub)
| Terminal::NonZero(ref sub)
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
Terminal::AndV(ref left, ref right)
| Terminal::AndB(ref left, ref right)
| Terminal::OrB(ref left, ref right)
| Terminal::OrD(ref left, ref right)
| Terminal::OrC(ref left, ref right)
| Terminal::OrI(ref left, ref right) => {
Tree::Binary(Arc::clone(left), Arc::clone(right))
}
Terminal::AndOr(ref a, ref b, ref c) => {
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
Alt(ref sub)
| Swap(ref sub)
| Check(ref sub)
| DupIf(ref sub)
| Verify(ref sub)
| NonZero(ref sub)
| ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
AndV(ref left, ref right)
| AndB(ref left, ref right)
| OrB(ref left, ref right)
| OrD(ref left, ref right)
| OrC(ref left, ref right)
| OrI(ref left, ref right) => Tree::Binary(Arc::clone(left), Arc::clone(right)),
AndOr(ref a, ref b, ref c) => {
Tree::Nary(Arc::from([Arc::clone(a), Arc::clone(b), Arc::clone(c)]))
}
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
}
}
}