Skip to content

Commit

Permalink
Rename Liftable to Lift
Browse files Browse the repository at this point in the history
In Rust, by convention, traits with a single method are named the same
as the method. `Liftable` should be called `Lift`, make it so.
  • Loading branch information
tcharding committed Oct 3, 2023
1 parent f8717e4 commit b71f55f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::str::FromStr;

use miniscript::bitcoin::Network;
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};
use miniscript::policy::{Concrete, Lift};

fn main() {
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/compile_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use honggfuzz::fuzz;
use miniscript::{policy, Miniscript, Segwitv0};
use policy::Liftable;
use policy::Lift;

type Script = Miniscript<String, Segwitv0>;
type Policy = policy::Concrete<String>;
Expand Down
6 changes: 3 additions & 3 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::{semantic, Lift};
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
}
}

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

Expand Down Expand Up @@ -361,7 +361,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Pkh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
Ok(semantic::Policy::Key(self.pk.clone()))
}
Expand Down
6 changes: 3 additions & 3 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::{semantic, Lift};
use crate::prelude::*;
use crate::util::varint_len;
use crate::{
Expand Down Expand Up @@ -219,7 +219,7 @@ pub enum WshInner<Pk: MiniscriptKey> {
Ms(Miniscript<Pk, Segwitv0>),
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wsh<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Wsh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
match self.inner {
WshInner::SortedMulti(ref smv) => smv.lift(),
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Wpkh<Pk> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Wpkh<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Wpkh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
Ok(semantic::Policy::Key(self.pk.clone()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::expression::{self, FromTree};
use crate::miniscript::context::ScriptContext;
use crate::miniscript::satisfy::{Placeholder, Satisfaction};
use crate::plan::AssetProvider;
use crate::policy::{semantic, Liftable};
use crate::policy::{semantic, Lift};
use crate::prelude::*;
use crate::util::{varint_len, witness_to_scriptsig};
use crate::{
Expand Down Expand Up @@ -48,7 +48,7 @@ pub enum ShInner<Pk: MiniscriptKey> {
Ms(Miniscript<Pk, Legacy>),
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Sh<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Sh<Pk> {
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
match self.inner {
ShInner::Wsh(ref wsh) => wsh.lift(),
Expand Down
2 changes: 1 addition & 1 deletion src/descriptor/sortedmulti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
pub fn max_satisfaction_size(&self) -> usize { 1 + 73 * self.k }
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> policy::Liftable<Pk> for SortedMultiVec<Pk, Ctx> {
impl<Pk: MiniscriptKey, Ctx: ScriptContext> policy::Lift<Pk> for SortedMultiVec<Pk, Ctx> {
fn lift(&self) -> Result<policy::semantic::Policy<Pk>, Error> {
let ret = policy::semantic::Policy::Threshold(
self.k,
Expand Down
6 changes: 3 additions & 3 deletions src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::miniscript::satisfy::{Placeholder, Satisfaction, SchnorrSigType, Witn
use crate::miniscript::Miniscript;
use crate::plan::AssetProvider;
use crate::policy::semantic::Policy;
use crate::policy::Liftable;
use crate::policy::Lift;
use crate::prelude::*;
use crate::util::{varint_len, witness_size};
use crate::{
Expand Down Expand Up @@ -616,7 +616,7 @@ fn split_once(inp: &str, delim: char) -> Option<(&str, &str)> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for TapTree<Pk> {
fn lift(&self) -> Result<Policy<Pk>, Error> {
fn lift_helper<Pk: MiniscriptKey>(s: &TapTree<Pk>) -> Result<Policy<Pk>, Error> {
match *s {
Expand All @@ -632,7 +632,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Tr<Pk> {
fn lift(&self) -> Result<Policy<Pk>, Error> {
match &self.tree {
Some(root) => {
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ mod tests {
use super::{Miniscript, ScriptContext, Segwitv0, Tap};
use crate::miniscript::types::{self, ExtData, Property, Type};
use crate::miniscript::Terminal;
use crate::policy::Liftable;
use crate::policy::Lift;
use crate::prelude::*;
use crate::test_utils::{StrKeyTranslator, StrXOnlyKeyTranslator};
use crate::{hex_script, ExtParams, Satisfier, ToPublicKey, TranslatePk};
Expand Down
2 changes: 1 addition & 1 deletion src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ mod tests {

use super::*;
use crate::miniscript::{Legacy, Segwitv0, Tap};
use crate::policy::Liftable;
use crate::policy::Lift;
use crate::{script_num_size, ToPublicKey};

type SPolicy = Concrete<String>;
Expand Down
2 changes: 1 addition & 1 deletion src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use {
crate::miniscript::ScriptContext,
crate::policy::compiler::CompilerError,
crate::policy::compiler::OrdF64,
crate::policy::{compiler, Concrete, Liftable, Semantic},
crate::policy::{compiler, Concrete, Lift, Semantic},
crate::Descriptor,
crate::Miniscript,
crate::Tap,
Expand Down
20 changes: 10 additions & 10 deletions src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ENTAILMENT_MAX_TERMINALS: usize = 20;
/// exceed resource limits for any compilation but cannot detect such policies
/// while lifting. Note that our compiler would not succeed for any such
/// policies.
pub trait Liftable<Pk: MiniscriptKey> {
pub trait Lift<Pk: MiniscriptKey> {
/// Converts this object into an abstract policy.
fn lift(&self) -> Result<Semantic<Pk>, Error>;
}
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx> {
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Lift<Pk> for Miniscript<Pk, Ctx> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
// check whether the root miniscript can have a spending path that is
// a combination of heightlock and timelock
Expand All @@ -113,7 +113,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx>
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Lift<Pk> for Terminal<Pk, Ctx> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
let ret = match *self {
Terminal::PkK(ref pk) | Terminal::PkH(ref pk) => Semantic::Key(pk.clone()),
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Descriptor<Pk> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
match *self {
Descriptor::Bare(ref bare) => bare.lift(),
Expand All @@ -177,11 +177,11 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk> {
}
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Semantic<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Semantic<Pk> {
fn lift(&self) -> Result<Semantic<Pk>, Error> { Ok(self.clone()) }
}

impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk> {
impl<Pk: MiniscriptKey> Lift<Pk> for Concrete<Pk> {
fn lift(&self) -> Result<Semantic<Pk>, Error> {
// do not lift if there is a possible satisfaction
// involving combination of timelocks and heightlocks
Expand All @@ -197,7 +197,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk> {
Concrete::Ripemd160(ref h) => Semantic::Ripemd160(h.clone()),
Concrete::Hash160(ref h) => Semantic::Hash160(h.clone()),
Concrete::And(ref subs) => {
let semantic_subs: Result<_, Error> = subs.iter().map(Liftable::lift).collect();
let semantic_subs: Result<_, Error> = subs.iter().map(Lift::lift).collect();
Semantic::Threshold(2, semantic_subs?)
}
Concrete::Or(ref subs) => {
Expand All @@ -206,15 +206,15 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk> {
Semantic::Threshold(1, semantic_subs?)
}
Concrete::Threshold(k, ref subs) => {
let semantic_subs: Result<_, Error> = subs.iter().map(Liftable::lift).collect();
let semantic_subs: Result<_, Error> = subs.iter().map(Lift::lift).collect();
Semantic::Threshold(k, semantic_subs?)
}
}
.normalized();
Ok(ret)
}
}
impl<Pk: MiniscriptKey> Liftable<Pk> for Arc<Concrete<Pk>> {
impl<Pk: MiniscriptKey> Lift<Pk> for Arc<Concrete<Pk>> {
fn lift(&self) -> Result<Semantic<Pk>, Error> { self.as_ref().lift() }
}

Expand All @@ -228,7 +228,7 @@ mod tests {

use super::super::miniscript::context::Segwitv0;
use super::super::miniscript::Miniscript;
use super::{Concrete, Liftable, Semantic};
use super::{Concrete, Lift, Semantic};
#[cfg(feature = "compiler")]
use crate::descriptor::Tr;
use crate::prelude::*;
Expand Down

0 comments on commit b71f55f

Please sign in to comment.