@@ -172,6 +172,14 @@ impl MiniscriptKey for bitcoin::PublicKey {
172
172
}
173
173
}
174
174
175
+ impl MiniscriptKey for bitcoin:: schnorr:: PublicKey {
176
+ type Hash = hash160:: Hash ;
177
+
178
+ fn to_pubkeyhash ( & self ) -> Self :: Hash {
179
+ hash160:: Hash :: hash ( & self . serialize ( ) )
180
+ }
181
+ }
182
+
175
183
impl MiniscriptKey for String {
176
184
type Hash = String ;
177
185
@@ -222,6 +230,20 @@ impl ToPublicKey for bitcoin::PublicKey {
222
230
}
223
231
}
224
232
233
+ impl ToPublicKey for bitcoin:: schnorr:: PublicKey {
234
+ fn to_public_key ( & self ) -> bitcoin:: PublicKey {
235
+ // This code should never be used.
236
+ // But is implemented for completeness
237
+ let mut data: Vec < u8 > = vec ! [ 0x02 ] ;
238
+ data. extend ( self . serialize ( ) . iter ( ) ) ;
239
+ bitcoin:: PublicKey :: from_slice ( & data) . expect ( "Cannot fail" )
240
+ }
241
+
242
+ fn hash_to_hash160 ( hash : & hash160:: Hash ) -> hash160:: Hash {
243
+ * hash
244
+ }
245
+ }
246
+
225
247
/// Dummy key which de/serializes to the empty string; useful sometimes for testing
226
248
#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug ) ]
227
249
pub struct DummyKey ;
@@ -468,7 +490,7 @@ pub enum Error {
468
490
InvalidOpcode ( opcodes:: All ) ,
469
491
/// Some opcode occurred followed by `OP_VERIFY` when it had
470
492
/// a `VERIFY` version that should have been used instead
471
- NonMinimalVerify ( miniscript :: lex :: Token ) ,
493
+ NonMinimalVerify ( String ) ,
472
494
/// Push was illegal in some context
473
495
InvalidPush ( Vec < u8 > ) ,
474
496
/// rust-bitcoin script error
@@ -541,6 +563,8 @@ pub enum Error {
541
563
ImpossibleSatisfaction ,
542
564
/// Bare descriptors don't have any addresses
543
565
BareDescriptorAddr ,
566
+ /// PubKey invalid under current context
567
+ PubKeyCtxError ( String , String ) ,
544
568
}
545
569
546
570
#[ doc( hidden) ]
@@ -604,7 +628,7 @@ impl fmt::Display for Error {
604
628
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
605
629
match * self {
606
630
Error :: InvalidOpcode ( op) => write ! ( f, "invalid opcode {}" , op) ,
607
- Error :: NonMinimalVerify ( tok) => write ! ( f, "{} VERIFY" , tok) ,
631
+ Error :: NonMinimalVerify ( ref tok) => write ! ( f, "{} VERIFY" , tok) ,
608
632
Error :: InvalidPush ( ref push) => write ! ( f, "invalid push {:?}" , push) , // TODO hexify this
609
633
Error :: Script ( ref e) => fmt:: Display :: fmt ( e, f) ,
610
634
Error :: CmsTooManyKeys ( n) => write ! ( f, "checkmultisig with {} keys" , n) ,
@@ -662,6 +686,9 @@ impl fmt::Display for Error {
662
686
Error :: AnalysisError ( ref e) => e. fmt ( f) ,
663
687
Error :: ImpossibleSatisfaction => write ! ( f, "Impossible to satisfy Miniscript" ) ,
664
688
Error :: BareDescriptorAddr => write ! ( f, "Bare descriptors don't have address" ) ,
689
+ Error :: PubKeyCtxError ( ref pk, ref ctx) => {
690
+ write ! ( f, "Pubkey error: {} under {} scriptcontext" , pk, ctx)
691
+ }
665
692
}
666
693
}
667
694
}
0 commit comments