Skip to content

Commit

Permalink
Rename abstract::Policy to Abstract
Browse files Browse the repository at this point in the history
Use the identifier `Abstract` to further disambiguate the abstract
policy and the concrete policy. This has the nice advantage of removing
a few usages of the kind-of-ugly `r#abstract::Policy`.
  • Loading branch information
tcharding committed Sep 27, 2023
1 parent 70b2e5f commit b79be87
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 273 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/roundtrip_semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use honggfuzz::fuzz;

type Policy = miniscript::r#abstract::Policy<String>;
type Policy = miniscript::r#abstract::Abstract<String>;

fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
Expand Down
4 changes: 2 additions & 2 deletions src/abstract/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::error;
use crate::descriptor::Descriptor;
use crate::miniscript::{Miniscript, ScriptContext};
use crate::policy::concrete::Policy as Concrete;
use crate::r#abstract::Policy as Abstract;
use crate::r#abstract::Abstract;
use crate::sync::Arc;
use crate::{Error, MiniscriptKey, Terminal};

Expand Down Expand Up @@ -227,7 +227,7 @@ mod tests {
use crate::{descriptor::TapTree, Descriptor, Tap};

type ConcretePol = crate::policy::concrete::Policy<String>;
type AbstractPol = crate::r#abstract::Policy<String>;
type AbstractPol = crate::r#abstract::Abstract<String>;

fn concrete_policy_rtt(s: &str) {
let conc = ConcretePol::from_str(s).unwrap();
Expand Down
487 changes: 247 additions & 240 deletions src/abstract/mod.rs

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::prelude::*;
use crate::r#abstract::{self, Liftable};
use crate::r#abstract::{Abstract, Liftable};
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
BareCtx, Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey, TranslateErr,
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> { self.ms.lift() }
fn lift(&self) -> Result<Abstract<Pk>, Error> { self.ms.lift() }
}

impl_from_tree!(
Expand Down Expand Up @@ -362,9 +362,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> {
Ok(r#abstract::Policy::Key(self.pk.clone()))
}
fn lift(&self) -> Result<Abstract<Pk>, Error> { Ok(Abstract::Key(self.pk.clone())) }
}

impl_from_tree!(
Expand Down
8 changes: 3 additions & 5 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::r#abstract::{self, Liftable};
use crate::prelude::*;
use crate::r#abstract::{Abstract, Liftable};
use crate::util::varint_len;
use crate::{
Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, Segwitv0, ToPublicKey, TranslateErr,
Expand Down Expand Up @@ -220,7 +220,7 @@ pub enum WshInner<Pk: MiniscriptKey> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wsh<Pk> {
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> {
fn lift(&self) -> Result<Abstract<Pk>, Error> {
match self.inner {
WshInner::SortedMulti(ref smv) => smv.lift(),
WshInner::Ms(ref ms) => ms.lift(),
Expand Down Expand Up @@ -469,9 +469,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Wpkh<Pk> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wpkh<Pk> {
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> {
Ok(r#abstract::Policy::Key(self.pk.clone()))
}
fn lift(&self) -> Result<Abstract<Pk>, Error> { Ok(Abstract::Key(self.pk.clone())) }
}

impl_from_tree!(
Expand Down
6 changes: 3 additions & 3 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::ScriptContext;
use crate::miniscript::satisfy::{Placeholder, Satisfaction};
use crate::plan::AssetProvider;
use crate::r#abstract::{self, Liftable};
use crate::prelude::*;
use crate::r#abstract::{Abstract, Liftable};
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
push_opcode_size, Error, ForEachKey, Legacy, Miniscript, MiniscriptKey, Satisfier, Segwitv0,
Expand Down Expand Up @@ -49,10 +49,10 @@ pub enum ShInner<Pk: MiniscriptKey> {
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Sh<Pk> {
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> {
fn lift(&self) -> Result<Abstract<Pk>, Error> {
match self.inner {
ShInner::Wsh(ref wsh) => wsh.lift(),
ShInner::Wpkh(ref pk) => Ok(r#abstract::Policy::Key(pk.as_inner().clone())),
ShInner::Wpkh(ref pk) => Ok(Abstract::Key(pk.as_inner().clone())),
ShInner::SortedMulti(ref smv) => smv.lift(),
ShInner::Ms(ref ms) => ms.lift(),
}
Expand Down
15 changes: 5 additions & 10 deletions src/descriptor/sortedmulti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::miniscript::decode::Terminal;
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
use crate::miniscript::satisfy::{Placeholder, Satisfaction};
use crate::plan::AssetProvider;
use crate::r#abstract;
use crate::prelude::*;
use crate::r#abstract::{Abstract, Liftable};
use crate::{
errstr, expression, script_num_size, Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier,
ToPublicKey, TranslateErr, Translator,
Expand Down Expand Up @@ -196,16 +196,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
pub fn max_satisfaction_size(&self) -> usize { 1 + 73 * self.k }
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> crate::r#abstract::Liftable<Pk>
for SortedMultiVec<Pk, Ctx>
{
fn lift(&self) -> Result<r#abstract::Policy<Pk>, Error> {
let ret = r#abstract::Policy::Threshold(
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for SortedMultiVec<Pk, Ctx> {
fn lift(&self) -> Result<Abstract<Pk>, Error> {
let ret = Abstract::Threshold(
self.k,
self.pks
.iter()
.map(|k| r#abstract::Policy::Key(k.clone()))
.collect(),
self.pks.iter().map(|k| Abstract::Key(k.clone())).collect(),
);
Ok(ret)
}
Expand Down
10 changes: 5 additions & 5 deletions src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use crate::expression::{self, FromTree};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, SchnorrSigType, Witness};
use crate::miniscript::Miniscript;
use crate::plan::AssetProvider;
use crate::r#abstract::Policy as Abstract;
use crate::prelude::*;
use crate::r#abstract::Liftable;
use crate::r#abstract::{Abstract, Liftable};
use crate::util::{varint_len, witness_size};
use crate::{
errstr, Error, ForEachKey, MiniscriptKey, Satisfier, ScriptContext, Tap, ToPublicKey,
Expand Down Expand Up @@ -635,9 +634,10 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
fn lift(&self) -> Result<Abstract<Pk>, Error> {
match &self.tree {
Some(root) => {
Ok(Abstract::Threshold(1, vec![Abstract::Key(self.internal_key.clone()), root.lift()?]))
}
Some(root) => Ok(Abstract::Threshold(
1,
vec![Abstract::Key(self.internal_key.clone()), root.lift()?],
)),
None => Ok(Abstract::Key(self.internal_key.clone())),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bitcoin::{absolute, Sequence};
use {
crate::descriptor::TapTree, crate::miniscript::ScriptContext, crate::policy::compiler,
crate::policy::compiler::CompilerError, crate::policy::compiler::OrdF64,
crate::policy::concrete::Policy as Concrete, crate::r#abstract::Policy as Abstract,
crate::policy::concrete::Policy as Concrete, crate::r#abstract::Abstract,
crate::r#abstract::Liftable, crate::Descriptor, crate::Miniscript, crate::Tap,
core::cmp::Reverse,
};
Expand Down Expand Up @@ -553,7 +553,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
impl<Pk: MiniscriptKey> Policy<Pk> {
/// Converts a policy using one kind of public key to another type of public key.
///
/// For example usage please see [`crate::abstract::Policy::translate_pk`].
/// For example usage please see [`crate::abstract::Abstract::translate_pk`].
pub fn translate_pk<Q, E, T>(&self, t: &mut T) -> Result<Policy<Q>, E>
where
T: Translator<Pk, Q, E>,
Expand Down

0 comments on commit b79be87

Please sign in to comment.