Skip to content

Commit

Permalink
blanket_traits: remove crate:: in a bunch of places
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Mar 5, 2024
1 parent 9280609 commit 3c1c896
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 46 deletions.
12 changes: 6 additions & 6 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::policy::{semantic, Liftable};
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
BareCtx, Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey, TranslateErr,
TranslatePk, Translator,
BareCtx, Error, ForEachKey, FromStrKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey,
TranslateErr, TranslatePk, Translator,
};

/// Create a Bare Descriptor. That is descriptor that is
Expand Down Expand Up @@ -166,15 +166,15 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> { self.ms.lift() }
}

impl<Pk: crate::FromStrKey> FromTree for Bare<Pk> {
impl<Pk: FromStrKey> FromTree for Bare<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
let sub = Miniscript::<Pk, BareCtx>::from_tree(top)?;
BareCtx::top_level_checks(&sub)?;
Bare::new(sub)
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Bare<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Bare<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down Expand Up @@ -364,7 +364,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
}
}

impl<Pk: crate::FromStrKey> FromTree for Pkh<Pk> {
impl<Pk: FromStrKey> FromTree for Pkh<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
if top.name == "pkh" && top.args.len() == 1 {
Ok(Pkh::new(expression::terminal(&top.args[0], |pk| Pk::from_str(pk))?)?)
Expand All @@ -378,7 +378,7 @@ impl<Pk: crate::FromStrKey> FromTree for Pkh<Pk> {
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Pkh<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Pkh<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down
8 changes: 4 additions & 4 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use crate::miniscript::{satisfy, Legacy, Miniscript, Segwitv0};
use crate::plan::{AssetProvider, Plan};
use crate::prelude::*;
use crate::{
expression, hash256, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey,
TranslateErr, TranslatePk, Translator,
expression, hash256, BareCtx, Error, ForEachKey, FromStrKey, MiniscriptKey, Satisfier,
ToPublicKey, TranslateErr, TranslatePk, Translator,
};

mod bare;
Expand Down Expand Up @@ -918,7 +918,7 @@ impl Descriptor<DefiniteDescriptorKey> {
}
}

impl<Pk: crate::FromStrKey> crate::expression::FromTree for Descriptor<Pk> {
impl<Pk: FromStrKey> crate::expression::FromTree for Descriptor<Pk> {
/// Parse an expression tree into a descriptor.
fn from_tree(top: &expression::Tree) -> Result<Descriptor<Pk>, Error> {
Ok(match (top.name, top.args.len() as u32) {
Expand All @@ -932,7 +932,7 @@ impl<Pk: crate::FromStrKey> crate::expression::FromTree for Descriptor<Pk> {
}
}

impl<Pk: crate::FromStrKey> FromStr for Descriptor<Pk> {
impl<Pk: FromStrKey> FromStr for Descriptor<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Descriptor<Pk>, Error> {
// tr tree parsing has special code
Expand Down
12 changes: 6 additions & 6 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::policy::{semantic, Liftable};
use crate::prelude::*;
use crate::util::varint_len;
use crate::{
Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, Segwitv0, ToPublicKey, TranslateErr,
TranslatePk, Translator,
Error, ForEachKey, FromStrKey, Miniscript, MiniscriptKey, Satisfier, Segwitv0, ToPublicKey,
TranslateErr, TranslatePk, Translator,
};
/// A Segwitv0 wsh descriptor
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Wsh<Pk> {
}
}

impl<Pk: crate::FromStrKey> crate::expression::FromTree for Wsh<Pk> {
impl<Pk: FromStrKey> crate::expression::FromTree for Wsh<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
if top.name == "wsh" && top.args.len() == 1 {
let top = &top.args[0];
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Wsh<Pk> {
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Wsh<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Wsh<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Wpkh<Pk> {
}
}

impl<Pk: crate::FromStrKey> crate::expression::FromTree for Wpkh<Pk> {
impl<Pk: FromStrKey> crate::expression::FromTree for Wpkh<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
if top.name == "wpkh" && top.args.len() == 1 {
Ok(Wpkh::new(expression::terminal(&top.args[0], |pk| Pk::from_str(pk))?)?)
Expand All @@ -487,7 +487,7 @@ impl<Pk: crate::FromStrKey> crate::expression::FromTree for Wpkh<Pk> {
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Wpkh<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Wpkh<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down
8 changes: 4 additions & 4 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::policy::{semantic, Liftable};
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
push_opcode_size, Error, ForEachKey, Legacy, Miniscript, MiniscriptKey, Satisfier, Segwitv0,
ToPublicKey, TranslateErr, TranslatePk, Translator,
push_opcode_size, Error, ForEachKey, FromStrKey, Legacy, Miniscript, MiniscriptKey, Satisfier,
Segwitv0, ToPublicKey, TranslateErr, TranslatePk, Translator,
};

/// A Legacy p2sh Descriptor
Expand Down Expand Up @@ -81,7 +81,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Sh<Pk> {
}
}

impl<Pk: crate::FromStrKey> crate::expression::FromTree for Sh<Pk> {
impl<Pk: FromStrKey> crate::expression::FromTree for Sh<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
if top.name == "sh" && top.args.len() == 1 {
let top = &top.args[0];
Expand All @@ -106,7 +106,7 @@ impl<Pk: crate::FromStrKey> crate::expression::FromTree for Sh<Pk> {
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Sh<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Sh<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down
10 changes: 5 additions & 5 deletions src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::policy::Liftable;
use crate::prelude::*;
use crate::util::{varint_len, witness_size};
use crate::{
errstr, Error, ForEachKey, MiniscriptKey, Satisfier, ScriptContext, Tap, ToPublicKey,
TranslateErr, TranslatePk, Translator,
errstr, Error, ForEachKey, FromStrKey, MiniscriptKey, Satisfier, ScriptContext, Tap,
ToPublicKey, TranslateErr, TranslatePk, Translator,
};

/// A Taproot Tree representation.
Expand Down Expand Up @@ -467,7 +467,7 @@ where
}

#[rustfmt::skip]
impl<Pk: crate::FromStrKey> Tr<Pk> {
impl<Pk: FromStrKey> Tr<Pk> {
// Helper function to parse taproot script path
fn parse_tr_script_spend(tree: &expression::Tree,) -> Result<TapTree<Pk>, Error> {
match tree {
Expand All @@ -488,7 +488,7 @@ impl<Pk: crate::FromStrKey> Tr<Pk> {
}
}

impl<Pk: crate::FromStrKey> crate::expression::FromTree for Tr<Pk> {
impl<Pk: FromStrKey> crate::expression::FromTree for Tr<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
if top.name == "tr" {
match top.args.len() {
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<Pk: crate::FromStrKey> crate::expression::FromTree for Tr<Pk> {
}
}

impl<Pk: crate::FromStrKey> core::str::FromStr for Tr<Pk> {
impl<Pk: FromStrKey> core::str::FromStr for Tr<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let desc_str = verify_checksum(s)?;
Expand Down
9 changes: 4 additions & 5 deletions src/miniscript/astelem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::miniscript::{types, ScriptContext};
use crate::prelude::*;
use crate::util::MsKeyBuilder;
use crate::{
errstr, expression, AbsLockTime, Error, Miniscript, MiniscriptKey, Terminal, ToPublicKey,
errstr, expression, AbsLockTime, Error, FromStrKey, Miniscript, MiniscriptKey, Terminal,
ToPublicKey,
};

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
Expand Down Expand Up @@ -240,15 +241,13 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for Terminal<Pk, Ctx> {
}
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> crate::expression::FromTree
for Arc<Terminal<Pk, Ctx>>
{
impl<Pk: FromStrKey, Ctx: ScriptContext> crate::expression::FromTree for Arc<Terminal<Pk, Ctx>> {
fn from_tree(top: &expression::Tree) -> Result<Arc<Terminal<Pk, Ctx>>, Error> {
Ok(Arc::new(expression::FromTree::from_tree(top)?))
}
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> crate::expression::FromTree for Terminal<Pk, Ctx> {
impl<Pk: FromStrKey, Ctx: ScriptContext> crate::expression::FromTree for Terminal<Pk, Ctx> {
fn from_tree(top: &expression::Tree) -> Result<Terminal<Pk, Ctx>, Error> {
let (frag_name, frag_wrap) = super::split_expression_name(top.name)?;
let unwrapped = match (frag_name, top.args.len()) {
Expand Down
15 changes: 6 additions & 9 deletions src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ use crate::miniscript::decode::Terminal;
use crate::miniscript::types::extra_props::ExtData;
use crate::miniscript::types::Type;
use crate::{
expression, plan, Error, ForEachKey, MiniscriptKey, ToPublicKey, TranslatePk, Translator,
expression, plan, Error, ForEachKey, FromStrKey, MiniscriptKey, ToPublicKey, TranslatePk,
Translator,
};
#[cfg(test)]
mod ms_tests;
Expand Down Expand Up @@ -617,7 +618,7 @@ where
Ok(ms)
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
impl<Pk: FromStrKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
/// Attempt to parse an insane(scripts don't clear sanity checks)
/// from string into a Miniscript representation.
/// Use this to parse scripts with repeated pubkeys, timelock mixing, malleable
Expand Down Expand Up @@ -648,17 +649,13 @@ impl<Pk: crate::FromStrKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
}
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> crate::expression::FromTree
for Arc<Miniscript<Pk, Ctx>>
{
impl<Pk: FromStrKey, Ctx: ScriptContext> crate::expression::FromTree for Arc<Miniscript<Pk, Ctx>> {
fn from_tree(top: &expression::Tree) -> Result<Arc<Miniscript<Pk, Ctx>>, Error> {
Ok(Arc::new(expression::FromTree::from_tree(top)?))
}
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> crate::expression::FromTree
for Miniscript<Pk, Ctx>
{
impl<Pk: FromStrKey, Ctx: ScriptContext> crate::expression::FromTree for Miniscript<Pk, Ctx> {
/// Parse an expression tree into a Miniscript. As a general rule, this
/// should not be called directly; rather go through the descriptor API.
fn from_tree(top: &expression::Tree) -> Result<Miniscript<Pk, Ctx>, Error> {
Expand All @@ -667,7 +664,7 @@ impl<Pk: crate::FromStrKey, Ctx: ScriptContext> crate::expression::FromTree
}
}

impl<Pk: crate::FromStrKey, Ctx: ScriptContext> str::FromStr for Miniscript<Pk, Ctx> {
impl<Pk: FromStrKey, Ctx: ScriptContext> str::FromStr for Miniscript<Pk, Ctx> {
type Err = Error;
/// Parse a Miniscript from string and perform sanity checks
/// See [Miniscript::from_str_insane] to parse scripts from string that
Expand Down
8 changes: 4 additions & 4 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::prelude::*;
use crate::sync::Arc;
#[cfg(all(doc, not(feature = "compiler")))]
use crate::Descriptor;
use crate::{errstr, AbsLockTime, Error, ForEachKey, MiniscriptKey, Translator};
use crate::{errstr, AbsLockTime, Error, ForEachKey, FromStrKey, MiniscriptKey, Translator};

/// Maximum TapLeafs allowed in a compiled TapTree
#[cfg(feature = "compiler")]
Expand Down Expand Up @@ -930,7 +930,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Policy<Pk> {
}
}

impl<Pk: crate::FromStrKey> str::FromStr for Policy<Pk> {
impl<Pk: FromStrKey> str::FromStr for Policy<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
expression::check_valid_chars(s)?;
Expand All @@ -945,7 +945,7 @@ impl<Pk: crate::FromStrKey> str::FromStr for Policy<Pk> {
serde_string_impl_pk!(Policy, "a miniscript concrete policy");

#[rustfmt::skip]
impl<Pk: crate::FromStrKey> Policy<Pk> {
impl<Pk: FromStrKey> Policy<Pk> {
/// Helper function for `from_tree` to parse subexpressions with
/// names of the form x@y
fn from_tree_prob(top: &expression::Tree, allow_prob: bool,)
Expand Down Expand Up @@ -1050,7 +1050,7 @@ impl<Pk: crate::FromStrKey> Policy<Pk> {
}
}

impl<Pk: crate::FromStrKey> expression::FromTree for Policy<Pk> {
impl<Pk: FromStrKey> expression::FromTree for Policy<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Policy<Pk>, Error> {
Policy::from_tree_prob(top, false).map(|(_, result)| result)
}
Expand Down
8 changes: 5 additions & 3 deletions src/policy/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use super::ENTAILMENT_MAX_TERMINALS;
use crate::iter::{Tree, TreeLike};
use crate::prelude::*;
use crate::sync::Arc;
use crate::{errstr, expression, AbsLockTime, Error, ForEachKey, MiniscriptKey, Translator};
use crate::{
errstr, expression, AbsLockTime, Error, ForEachKey, FromStrKey, MiniscriptKey, Translator,
};

/// Abstract policy which corresponds to the semantics of a miniscript and
/// which allows complex forms of analysis, e.g. filtering and normalization.
Expand Down Expand Up @@ -308,7 +310,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Policy<Pk> {
}
}

impl<Pk: crate::FromStrKey> str::FromStr for Policy<Pk> {
impl<Pk: FromStrKey> str::FromStr for Policy<Pk> {
type Err = Error;
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
expression::check_valid_chars(s)?;
Expand All @@ -320,7 +322,7 @@ impl<Pk: crate::FromStrKey> str::FromStr for Policy<Pk> {

serde_string_impl_pk!(Policy, "a miniscript semantic policy");

impl<Pk: crate::FromStrKey> expression::FromTree for Policy<Pk> {
impl<Pk: FromStrKey> expression::FromTree for Policy<Pk> {
fn from_tree(top: &expression::Tree) -> Result<Policy<Pk>, Error> {
match (top.name, top.args.len()) {
("UNSATISFIABLE", 0) => Ok(Policy::Unsatisfiable),
Expand Down

0 comments on commit 3c1c896

Please sign in to comment.