|
2 | 2 | //! |
3 | 3 | //! Macros meant to be used inside the Rust Miniscript library |
4 | 4 |
|
| 5 | +/// Macro for failing translation for other associated types. |
| 6 | +/// Handy for testing String -> concrete keys as we don't want to specify these |
| 7 | +/// functions repeatedly. |
| 8 | +#[macro_export] |
| 9 | +macro_rules! translate_assoc_fail { |
| 10 | + ($source: ty, $target:ty, $error_ty: ty) => { |
| 11 | + fn sha256( |
| 12 | + &mut self, |
| 13 | + _sha256: &<$source as MiniscriptKey>::Sha256, |
| 14 | + ) -> Result<<$target as MiniscriptKey>::Sha256, $error_ty> { |
| 15 | + panic!("Called sha256 on translate_only_pk") |
| 16 | + } |
| 17 | + |
| 18 | + fn hash256( |
| 19 | + &mut self, |
| 20 | + _hash256: &<$source as MiniscriptKey>::Hash256, |
| 21 | + ) -> Result<<$target as MiniscriptKey>::Hash256, $error_ty> { |
| 22 | + panic!("Called hash256 on translate_only_pk") |
| 23 | + } |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +/// Macro for translation of associated types where the associated type is the same |
| 28 | +/// Handy for Derived -> concrete keys where the associated types are the same. |
| 29 | +#[macro_export] |
| 30 | +macro_rules! translate_assoc_clone { |
| 31 | + ($source: ty, $target:ty, $error_ty: ty) => { |
| 32 | + fn sha256( |
| 33 | + &mut self, |
| 34 | + _sha256: &<$source as MiniscriptKey>::Sha256, |
| 35 | + ) -> Result<<$target as MiniscriptKey>::Sha256, $error_ty> { |
| 36 | + Ok(sha256.clone()) |
| 37 | + } |
| 38 | + |
| 39 | + fn hash256( |
| 40 | + &mut self, |
| 41 | + _hash256: &<$source as MiniscriptKey>::Hash256, |
| 42 | + ) -> Result<<$target as MiniscriptKey>::Hash256, $error_ty> { |
| 43 | + Ok(hash256.clone()) |
| 44 | + } |
| 45 | + }; |
| 46 | +} |
5 | 47 | /// Allows tests to create a miniscript directly from string as |
6 | 48 | /// `ms_str!("c:or_i(pk({}),pk({}))", pk1, pk2)` |
7 | 49 | #[cfg(test)] |
|
0 commit comments