4
4
5
5
use std:: { fmt, hash} ;
6
6
7
- use bitcoin:: hashes:: hex:: ToHex ;
8
- use elements:: encode:: serialize;
9
7
use elements:: script:: Builder ;
10
- use elements:: { confidential , Transaction , TxOut } ;
8
+ use elements:: { Transaction , TxOut } ;
11
9
12
10
use crate :: expression:: Tree ;
13
11
use crate :: interpreter:: { self , Stack } ;
@@ -23,35 +21,17 @@ mod arith;
23
21
mod csfs;
24
22
mod introspect_ops;
25
23
mod outputs_pref;
24
+ pub mod param;
26
25
mod tx_ver;
27
26
28
27
pub use arith:: { Arith , EvalError , Expr , ExprInner } ;
29
28
pub use csfs:: { CheckSigFromStack , CsfsKey , CsfsMsg } ;
30
- pub use introspect_ops:: { AssetExpr , CovOps , SpkExpr , ValueExpr } ;
29
+ pub use introspect_ops:: { AssetExpr , CovOps , Spk , SpkExpr , ValueExpr } ;
31
30
32
- use self :: introspect_ops:: Spk ;
33
31
pub use self :: outputs_pref:: LegacyOutputsPref ;
32
+ pub use self :: param:: { ArgFromStr , CovExtArgs , ExtParam , NoExtParam } ;
34
33
pub use self :: tx_ver:: LegacyVerEq ;
35
34
36
- /// Trait for parsing extension arg from String
37
- /// Parse an argument from `s` given context of parent and argument position
38
- ///
39
- /// When parsing all allowed parameters from string, we need to restrict where
40
- /// the parameters can be allowed. For example, csfs() should not have a txout
41
- /// parameter.
42
- ///
43
- /// All parameters that should be parsed from extensions need to implement this
44
- pub trait ArgFromStr : Sized {
45
- /// Parse an argument from `s` given context of parent and argument position
46
- fn arg_from_str ( s : & str , parent : & str , pos : usize ) -> Result < Self , Error > ;
47
- }
48
- /// Abstract parameter to Miniscript Extension
49
- pub trait ExtParam : Clone + Eq + Ord + fmt:: Debug + fmt:: Display + hash:: Hash + ArgFromStr { }
50
-
51
- impl < T > ExtParam for T where
52
- T : Clone + Eq + Ord + fmt:: Debug + fmt:: Display + hash:: Hash + ArgFromStr
53
- {
54
- }
55
35
56
36
/// Extensions to elements-miniscript.
57
37
/// Refer to implementations(unimplemented!) for example and tutorials
@@ -138,24 +118,6 @@ pub trait ParseableExt:
138
118
S : Satisfier < Pk > ;
139
119
}
140
120
141
- /// No Extensions for elements-miniscript
142
- /// All the implementations for the this function are unreachable
143
- #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Clone , Copy , Hash ) ]
144
- pub enum NoExtParam { }
145
-
146
- impl fmt:: Display for NoExtParam {
147
- fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
148
- match * self { }
149
- }
150
- }
151
-
152
- impl ArgFromStr for NoExtParam {
153
- fn arg_from_str ( _s : & str , _parent : & str , _pos : usize ) -> Result < Self , Error > {
154
- // This will be removed in a followup commit
155
- unreachable ! ( "Called ArgFromStr for NoExt" )
156
- }
157
- }
158
-
159
121
/// No Extensions for elements-miniscript
160
122
/// All the implementations for the this function are unreachable
161
123
#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Clone , Copy , Hash ) ]
@@ -263,132 +225,6 @@ pub enum CovenantExt<T: ExtParam> {
263
225
Introspect ( CovOps < T > ) ,
264
226
}
265
227
266
- /// All known Extension parameters/arguments
267
- #[ derive( Debug , PartialEq , Eq , Clone , Hash ) ]
268
- pub enum CovExtArgs {
269
- /// XOnlyPublicKey (in CSFS)
270
- XOnlyKey ( CsfsKey ) ,
271
- /// Message
272
- CsfsMsg ( CsfsMsg ) ,
273
- /// Asset
274
- Asset ( confidential:: Asset ) ,
275
- /// Value
276
- Value ( confidential:: Value ) ,
277
- /// Script
278
- Script ( Spk ) ,
279
- }
280
-
281
- impl From < CsfsMsg > for CovExtArgs {
282
- fn from ( v : CsfsMsg ) -> Self {
283
- Self :: CsfsMsg ( v)
284
- }
285
- }
286
-
287
- impl From < Spk > for CovExtArgs {
288
- fn from ( v : Spk ) -> Self {
289
- Self :: Script ( v)
290
- }
291
- }
292
-
293
- impl From < confidential:: Value > for CovExtArgs {
294
- fn from ( v : confidential:: Value ) -> Self {
295
- Self :: Value ( v)
296
- }
297
- }
298
-
299
- impl From < confidential:: Asset > for CovExtArgs {
300
- fn from ( v : confidential:: Asset ) -> Self {
301
- Self :: Asset ( v)
302
- }
303
- }
304
-
305
- impl From < CsfsKey > for CovExtArgs {
306
- fn from ( v : CsfsKey ) -> Self {
307
- Self :: XOnlyKey ( v)
308
- }
309
- }
310
-
311
- impl CovExtArgs {
312
- /// Creates a new csfs key variant of [`CovExtArgs`]
313
- pub fn csfs_key ( key : bitcoin:: XOnlyPublicKey ) -> Self {
314
- CovExtArgs :: XOnlyKey ( CsfsKey ( key) )
315
- }
316
-
317
- /// Creates a csfs message variant of [`CovExtArgs`]
318
- pub fn csfs_msg ( msg : elements:: secp256k1_zkp:: Message ) -> Self {
319
- CovExtArgs :: CsfsMsg ( CsfsMsg :: new ( msg. as_ref ( ) . to_vec ( ) ) . expect ( "32 byte size message" ) )
320
- }
321
-
322
- /// Creates a new asset variant of [`CovExtArgs`]
323
- pub fn asset ( asset : confidential:: Asset ) -> Self {
324
- Self :: from ( asset)
325
- }
326
-
327
- /// Creates a new value variant of [`CovExtArgs`]
328
- pub fn value ( value : confidential:: Value ) -> Self {
329
- Self :: from ( value)
330
- }
331
-
332
- /// Creates a new script pubkey of [`CovExtArgs`]
333
- pub fn spk ( spk : elements:: Script ) -> Self {
334
- Self :: from ( Spk ( spk) )
335
- }
336
- }
337
-
338
- impl PartialOrd for CovExtArgs {
339
- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
340
- // HACKY implementation, need Ord/PartialOrd to make it work with other components
341
- // in the library
342
- self . to_string ( ) . partial_cmp ( & other. to_string ( ) )
343
- }
344
- }
345
-
346
- impl Ord for CovExtArgs {
347
- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
348
- // HACKY implementation, need Ord/PartialOrd to make it work with other components
349
- // in the library
350
- self . to_string ( ) . cmp ( & other. to_string ( ) )
351
- }
352
- }
353
-
354
- impl fmt:: Display for CovExtArgs {
355
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
356
- match self {
357
- CovExtArgs :: XOnlyKey ( x) => write ! ( f, "{}" , x) ,
358
- CovExtArgs :: CsfsMsg ( m) => write ! ( f, "{}" , m) ,
359
- CovExtArgs :: Asset ( a) => write ! ( f, "{}" , serialize( a) . to_hex( ) ) ,
360
- CovExtArgs :: Value ( v) => write ! ( f, "{}" , serialize( v) . to_hex( ) ) ,
361
- CovExtArgs :: Script ( s) => write ! ( f, "{}" , s) ,
362
- }
363
- }
364
- }
365
-
366
- impl ArgFromStr for CovExtArgs {
367
- fn arg_from_str ( s : & str , parent : & str , pos : usize ) -> Result < Self , Error > {
368
- let arg = match ( parent, pos) {
369
- ( "csfs" , 0 ) => CovExtArgs :: XOnlyKey ( CsfsKey :: arg_from_str ( s, parent, pos) ?) ,
370
- ( "csfs" , 1 ) => CovExtArgs :: CsfsMsg ( CsfsMsg :: arg_from_str ( s, parent, pos) ?) ,
371
- ( "asset_eq" , 0 ) | ( "asset_eq" , 1 ) | ( "is_exp_asset" , 0 ) => {
372
- CovExtArgs :: Asset ( confidential:: Asset :: arg_from_str ( s, parent, pos) ?)
373
- }
374
- ( "value_eq" , 0 ) | ( "value_eq" , 1 ) | ( "is_exp_value" , 0 ) => {
375
- CovExtArgs :: Value ( confidential:: Value :: arg_from_str ( s, parent, pos) ?)
376
- }
377
- ( "spk_eq" , 0 ) | ( "spk_eq" , 1 ) => CovExtArgs :: Script ( Spk :: arg_from_str ( s, parent, pos) ?) ,
378
- _ => return Err ( Error :: Unexpected ( s. to_string ( ) ) ) ,
379
- } ;
380
- Ok ( arg)
381
- }
382
- }
383
-
384
- impl ArgFromStr for String {
385
- fn arg_from_str ( s : & str , _parent : & str , _pos : usize ) -> Result < Self , Error > {
386
- // Abstract strings are parsed without context as they don't contain any concrete
387
- // information
388
- Ok ( String :: from ( s) )
389
- }
390
- }
391
-
392
228
// Apply the function on each arm
393
229
macro_rules! all_arms_fn {
394
230
( $slf: ident, $trt: ident, $f: ident, $( $args: ident, ) * ) => {
0 commit comments