|
24 | 24 |
|
25 | 25 | use core::fmt::Display; |
26 | 26 | use core::str::FromStr; |
| 27 | +use std::collections::BTreeSet; |
27 | 28 | use std::fmt::Debug; |
| 29 | +use std::iter; |
28 | 30 |
|
29 | 31 | use amplify::confinement::ConfinedVec; |
30 | 32 | use amplify::num::u4; |
31 | | -use derive::{DeriveCompr, DeriveLegacy, DeriveSet, DeriveXOnly}; |
| 33 | +use derive::{ |
| 34 | + Derive, DeriveCompr, DeriveKey, DeriveLegacy, DeriveSet, DeriveXOnly, Keychain, NormalIndex, |
| 35 | + XkeyDecodeError, XpubAccount, |
| 36 | +}; |
32 | 37 | use indexmap::{indexmap, IndexMap}; |
33 | 38 |
|
34 | 39 | use crate::compiler::{DescrAst, DescrParseError, ScriptExpr}; |
@@ -61,6 +66,41 @@ impl DescrExpr { |
61 | 66 | } |
62 | 67 | } |
63 | 68 |
|
| 69 | +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Display)] |
| 70 | +#[display("")] |
| 71 | +pub struct NoKey; |
| 72 | +impl DeriveSet for NoKey { |
| 73 | + type Legacy = Self; |
| 74 | + type Compr = Self; |
| 75 | + type XOnly = Self; |
| 76 | +} |
| 77 | +impl<K> Derive<K> for NoKey { |
| 78 | + fn default_keychain(&self) -> Keychain { |
| 79 | + unreachable!(); |
| 80 | + } |
| 81 | + fn keychains(&self) -> BTreeSet<Keychain> { |
| 82 | + unreachable!(); |
| 83 | + } |
| 84 | + fn derive( |
| 85 | + &self, |
| 86 | + _keychain: impl Into<Keychain>, |
| 87 | + _index: impl Into<NormalIndex>, |
| 88 | + ) -> impl Iterator<Item = K> { |
| 89 | + iter::empty() |
| 90 | + } |
| 91 | +} |
| 92 | +impl<K> DeriveKey<K> for NoKey { |
| 93 | + fn xpub_spec(&self) -> &XpubAccount { |
| 94 | + unreachable!(); |
| 95 | + } |
| 96 | +} |
| 97 | +impl FromStr for NoKey { |
| 98 | + type Err = XkeyDecodeError; |
| 99 | + fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 100 | + Err(XkeyDecodeError::WrongExtendedKeyLength(s.len())) |
| 101 | + } |
| 102 | +} |
| 103 | + |
64 | 104 | pub fn check_forms<'s, K: Display + FromStr>( |
65 | 105 | ast: ScriptExpr<'s, K>, |
66 | 106 | ident: &str, |
|
0 commit comments