Skip to content

Commit f03dc1e

Browse files
authored
Merge pull request #220 from apoelstra/2021-01--satisfier-improvements
remove FromStr bound on MiniscriptKey and MiniscriptKey::Hash
2 parents a346afd + e5b8a73 commit f03dc1e

File tree

11 files changed

+71
-59
lines changed

11 files changed

+71
-59
lines changed

src/descriptor/bare.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
7878
}
7979
}
8080

81-
impl<Pk: MiniscriptKey> FromTree for Bare<Pk>
81+
impl<Pk> FromTree for Bare<Pk>
8282
where
83+
Pk: MiniscriptKey + FromStr,
84+
Pk::Hash: FromStr,
8385
<Pk as FromStr>::Err: ToString,
8486
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
8587
{
@@ -90,8 +92,10 @@ where
9092
}
9193
}
9294

93-
impl<Pk: MiniscriptKey> FromStr for Bare<Pk>
95+
impl<Pk> FromStr for Bare<Pk>
9496
where
97+
Pk: MiniscriptKey + FromStr,
98+
Pk::Hash: FromStr,
9599
<Pk as FromStr>::Err: ToString,
96100
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
97101
{
@@ -104,11 +108,7 @@ where
104108
}
105109
}
106110

107-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk>
108-
where
109-
<Pk as FromStr>::Err: ToString,
110-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
111-
{
111+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
112112
fn sanity_check(&self) -> Result<(), Error> {
113113
self.ms.sanity_check()?;
114114
Ok(())
@@ -237,8 +237,10 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
237237
}
238238
}
239239

240-
impl<Pk: MiniscriptKey> FromTree for Pkh<Pk>
240+
impl<Pk> FromTree for Pkh<Pk>
241241
where
242+
Pk: MiniscriptKey + FromStr,
243+
Pk::Hash: FromStr,
242244
<Pk as FromStr>::Err: ToString,
243245
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
244246
{
@@ -257,8 +259,10 @@ where
257259
}
258260
}
259261

260-
impl<Pk: MiniscriptKey> FromStr for Pkh<Pk>
262+
impl<Pk> FromStr for Pkh<Pk>
261263
where
264+
Pk: MiniscriptKey + FromStr,
265+
Pk::Hash: FromStr,
262266
<Pk as FromStr>::Err: ToString,
263267
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
264268
{
@@ -271,11 +275,7 @@ where
271275
}
272276
}
273277

274-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk>
275-
where
276-
<Pk as FromStr>::Err: ToString,
277-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
278-
{
278+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
279279
fn sanity_check(&self) -> Result<(), Error> {
280280
Ok(())
281281
}

src/descriptor/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Descriptor<P> {
290290
}
291291
}
292292

293-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk>
294-
where
295-
<Pk as FromStr>::Err: ToString,
296-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
297-
{
293+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
298294
/// Whether the descriptor is safe
299295
/// Checks whether all the spend paths in the descriptor are possible
300296
/// on the bitcoin network under the current standardness and consensus rules
@@ -517,7 +513,8 @@ impl Descriptor<DescriptorPublicKey> {
517513

518514
impl<Pk> expression::FromTree for Descriptor<Pk>
519515
where
520-
Pk: MiniscriptKey,
516+
Pk: MiniscriptKey + str::FromStr,
517+
Pk::Hash: str::FromStr,
521518
<Pk as FromStr>::Err: ToString,
522519
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
523520
{
@@ -535,7 +532,8 @@ where
535532

536533
impl<Pk> FromStr for Descriptor<Pk>
537534
where
538-
Pk: MiniscriptKey,
535+
Pk: MiniscriptKey + str::FromStr,
536+
Pk::Hash: str::FromStr,
539537
<Pk as FromStr>::Err: ToString,
540538
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
541539
{

src/descriptor/segwitv0.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Wsh<Pk> {
8383
}
8484
}
8585

86-
impl<Pk: MiniscriptKey> FromTree for Wsh<Pk>
86+
impl<Pk> FromTree for Wsh<Pk>
8787
where
88+
Pk: MiniscriptKey + FromStr,
89+
Pk::Hash: FromStr,
8890
<Pk as FromStr>::Err: ToString,
8991
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
9092
{
@@ -130,8 +132,10 @@ impl<Pk: MiniscriptKey> fmt::Display for Wsh<Pk> {
130132
}
131133
}
132134

133-
impl<Pk: MiniscriptKey> FromStr for Wsh<Pk>
135+
impl<Pk> FromStr for Wsh<Pk>
134136
where
137+
Pk: MiniscriptKey + FromStr,
138+
Pk::Hash: FromStr,
135139
<Pk as FromStr>::Err: ToString,
136140
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
137141
{
@@ -144,11 +148,7 @@ where
144148
}
145149
}
146150

147-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk>
148-
where
149-
<Pk as FromStr>::Err: ToString,
150-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
151-
{
151+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk> {
152152
fn sanity_check(&self) -> Result<(), Error> {
153153
match self.inner {
154154
WshInner::SortedMulti(ref smv) => smv.sanity_check()?,
@@ -315,8 +315,10 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Wpkh<Pk> {
315315
}
316316
}
317317

318-
impl<Pk: MiniscriptKey> FromTree for Wpkh<Pk>
318+
impl<Pk> FromTree for Wpkh<Pk>
319319
where
320+
Pk: MiniscriptKey + FromStr,
321+
Pk::Hash: FromStr,
320322
<Pk as FromStr>::Err: ToString,
321323
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
322324
{
@@ -335,8 +337,10 @@ where
335337
}
336338
}
337339

338-
impl<Pk: MiniscriptKey> FromStr for Wpkh<Pk>
340+
impl<Pk> FromStr for Wpkh<Pk>
339341
where
342+
Pk: MiniscriptKey + FromStr,
343+
Pk::Hash: FromStr,
340344
<Pk as FromStr>::Err: ToString,
341345
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
342346
{
@@ -349,11 +353,7 @@ where
349353
}
350354
}
351355

352-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk>
353-
where
354-
<Pk as FromStr>::Err: ToString,
355-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
356-
{
356+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk> {
357357
fn sanity_check(&self) -> Result<(), Error> {
358358
if self.pk.is_uncompressed() {
359359
Err(Error::ContextError(ScriptContextError::CompressedOnly))

src/descriptor/sh.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ impl<Pk: MiniscriptKey> fmt::Display for Sh<Pk> {
9797
}
9898
}
9999

100-
impl<Pk: MiniscriptKey> FromTree for Sh<Pk>
100+
impl<Pk> FromTree for Sh<Pk>
101101
where
102+
Pk: MiniscriptKey + FromStr,
103+
Pk::Hash: FromStr,
102104
<Pk as FromStr>::Err: ToString,
103105
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
104106
{
@@ -126,8 +128,10 @@ where
126128
}
127129
}
128130

129-
impl<Pk: MiniscriptKey> FromStr for Sh<Pk>
131+
impl<Pk> FromStr for Sh<Pk>
130132
where
133+
Pk: MiniscriptKey + FromStr,
134+
Pk::Hash: FromStr,
131135
<Pk as FromStr>::Err: ToString,
132136
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
133137
{
@@ -184,11 +188,7 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
184188
}
185189
}
186190

187-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk>
188-
where
189-
<Pk as FromStr>::Err: ToString,
190-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
191-
{
191+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
192192
fn sanity_check(&self) -> Result<(), Error> {
193193
match self.inner {
194194
ShInner::Wsh(ref wsh) => wsh.sanity_check()?,

src/descriptor/sortedmulti.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
6666
/// Parse an expression tree into a SortedMultiVec
6767
pub fn from_tree(tree: &expression::Tree) -> Result<Self, Error>
6868
where
69+
Pk: FromStr,
6970
<Pk as FromStr>::Err: ToString,
7071
{
7172
if tree.args.is_empty() {

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,14 @@ pub use miniscript::satisfy::{BitcoinSig, Satisfier};
131131
pub use miniscript::Miniscript;
132132

133133
///Public key trait which can be converted to Hash type
134-
pub trait MiniscriptKey:
135-
Clone + Eq + Ord + str::FromStr + fmt::Debug + fmt::Display + hash::Hash
136-
{
134+
pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Hash {
137135
/// Check if the publicKey is uncompressed. The default
138136
/// implementation returns false
139137
fn is_uncompressed(&self) -> bool {
140138
false
141139
}
142140
/// The associated Hash type with the publicKey
143-
type Hash: Clone + Eq + Ord + str::FromStr + fmt::Display + fmt::Debug + hash::Hash;
141+
type Hash: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
144142

145143
/// Converts an object to PublicHash
146144
fn to_pubkeyhash(&self) -> Self::Hash;

src/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ macro_rules! serde_string_impl_pk {
2323
#[cfg(feature = "serde")]
2424
impl<'de, Pk $(, $gen)*> $crate::serde::Deserialize<'de> for $name<Pk $(, $gen)*>
2525
where
26-
Pk: $crate::MiniscriptKey,
26+
Pk: $crate::MiniscriptKey + $crate::std::str::FromStr,
27+
Pk::Hash: $crate::std::str::FromStr,
2728
<Pk as $crate::std::str::FromStr>::Err: $crate::std::fmt::Display,
2829
<<Pk as $crate::MiniscriptKey>::Hash as $crate::std::str::FromStr>::Err:
2930
$crate::std::fmt::Display,
@@ -41,7 +42,8 @@ macro_rules! serde_string_impl_pk {
4142
struct Visitor<Pk $(, $gen)*>(PhantomData<(Pk $(, $gen)*)>);
4243
impl<'de, Pk $(, $gen)*> $crate::serde::de::Visitor<'de> for Visitor<Pk $(, $gen)*>
4344
where
44-
Pk: $crate::MiniscriptKey,
45+
Pk: $crate::MiniscriptKey + $crate::std::str::FromStr,
46+
Pk::Hash: $crate::std::str::FromStr,
4547
<Pk as $crate::std::str::FromStr>::Err: $crate::std::fmt::Display,
4648
<<Pk as $crate::MiniscriptKey>::Hash as $crate::std::str::FromStr>::Err:
4749
$crate::std::fmt::Display,

src/miniscript/astelem.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for Terminal<Pk, Ctx> {
406406

407407
impl<Pk, Ctx> expression::FromTree for Arc<Terminal<Pk, Ctx>>
408408
where
409-
Pk: MiniscriptKey,
409+
Pk: MiniscriptKey + str::FromStr,
410+
Pk::Hash: str::FromStr,
410411
Ctx: ScriptContext,
411412
<Pk as str::FromStr>::Err: ToString,
412413
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
@@ -418,7 +419,8 @@ where
418419

419420
impl<Pk, Ctx> expression::FromTree for Terminal<Pk, Ctx>
420421
where
421-
Pk: MiniscriptKey,
422+
Pk: MiniscriptKey + str::FromStr,
423+
Pk::Hash: str::FromStr,
422424
Ctx: ScriptContext,
423425
<Pk as str::FromStr>::Err: ToString,
424426
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,

src/miniscript/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
303303
/// accept sane scripts.
304304
pub fn from_str_insane(s: &str) -> Result<Miniscript<Pk, Ctx>, Error>
305305
where
306+
Pk: str::FromStr,
307+
Pk::Hash: str::FromStr,
306308
<Pk as str::FromStr>::Err: ToString,
307309
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
308310
{
@@ -364,7 +366,8 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
364366

365367
impl<Pk, Ctx> expression::FromTree for Arc<Miniscript<Pk, Ctx>>
366368
where
367-
Pk: MiniscriptKey,
369+
Pk: MiniscriptKey + str::FromStr,
370+
Pk::Hash: str::FromStr,
368371
Ctx: ScriptContext,
369372
<Pk as str::FromStr>::Err: ToString,
370373
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
@@ -376,7 +379,8 @@ where
376379

377380
impl<Pk, Ctx> expression::FromTree for Miniscript<Pk, Ctx>
378381
where
379-
Pk: MiniscriptKey,
382+
Pk: MiniscriptKey + str::FromStr,
383+
Pk::Hash: str::FromStr,
380384
Ctx: ScriptContext,
381385
<Pk as str::FromStr>::Err: ToString,
382386
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
@@ -399,7 +403,8 @@ where
399403
/// do not clear the [Miniscript::sanity_check] checks.
400404
impl<Pk, Ctx> str::FromStr for Miniscript<Pk, Ctx>
401405
where
402-
Pk: MiniscriptKey,
406+
Pk: MiniscriptKey + str::FromStr,
407+
Pk::Hash: str::FromStr,
403408
Ctx: ScriptContext,
404409
<Pk as str::FromStr>::Err: ToString,
405410
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
@@ -460,7 +465,8 @@ mod tests {
460465
expected_debug: Str1,
461466
expected_display: Str2,
462467
) where
463-
Pk: MiniscriptKey,
468+
Pk: MiniscriptKey + str::FromStr,
469+
Pk::Hash: str::FromStr,
464470
Ctx: ScriptContext,
465471
<Pk as str::FromStr>::Err: ToString,
466472
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,

src/policy/concrete.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ impl<Pk: MiniscriptKey> fmt::Display for Policy<Pk> {
483483

484484
impl<Pk> str::FromStr for Policy<Pk>
485485
where
486-
Pk: MiniscriptKey,
486+
Pk: MiniscriptKey + str::FromStr,
487+
Pk::Hash: str::FromStr,
487488
<Pk as str::FromStr>::Err: ToString,
488489
<<Pk as MiniscriptKey>::Hash as str::FromStr>::Err: ToString,
489490
{
@@ -507,7 +508,8 @@ serde_string_impl_pk!(Policy, "a miniscript concrete policy");
507508

508509
impl<Pk> Policy<Pk>
509510
where
510-
Pk: MiniscriptKey,
511+
Pk: MiniscriptKey + str::FromStr,
512+
Pk::Hash: str::FromStr,
511513
<Pk as str::FromStr>::Err: ToString,
512514
{
513515
/// Helper function for `from_tree` to parse subexpressions with
@@ -617,7 +619,8 @@ where
617619

618620
impl<Pk> FromTree for Policy<Pk>
619621
where
620-
Pk: MiniscriptKey,
622+
Pk: MiniscriptKey + str::FromStr,
623+
Pk::Hash: str::FromStr,
621624
<Pk as str::FromStr>::Err: ToString,
622625
{
623626
fn from_tree(top: &expression::Tree) -> Result<Policy<Pk>, Error> {

0 commit comments

Comments
 (0)