Skip to content

Commit 7b4b562

Browse files
committed
wip: Change MiniscriptKey to Key
1 parent d3af6d9 commit 7b4b562

28 files changed

+373
-373
lines changed

examples/sign_multisig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
assert_eq!(descriptor.max_weight_to_satisfy().unwrap(), 253);
2424

2525
// Sometimes it is necessary to have additional information to get the
26-
// `bitcoin::PublicKey` from the `MiniscriptKey` which can be supplied by
26+
// `bitcoin::PublicKey` from the `Key` which can be supplied by
2727
// the `to_pk_ctx` parameter. For example, when calculating the script
2828
// pubkey of a descriptor with xpubs, the secp context and child information
2929
// maybe required.

src/descriptor/bare.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ use crate::policy::{semantic, Liftable};
2020
use crate::prelude::*;
2121
use crate::util::{varint_len, witness_to_scriptsig};
2222
use crate::{
23-
BareCtx, Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey, TranslateErr,
23+
BareCtx, Error, ForEachKey, Miniscript, Key, Satisfier, ToPublicKey, TranslateErr,
2424
TranslatePk, Translator,
2525
};
2626

2727
/// Create a Bare Descriptor. That is descriptor that is
2828
/// not wrapped in sh or wsh. This covers the Pk descriptor
2929
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
30-
pub struct Bare<Pk: MiniscriptKey> {
30+
pub struct Bare<Pk: Key> {
3131
/// underlying miniscript
3232
ms: Miniscript<Pk, BareCtx>,
3333
}
3434

35-
impl<Pk: MiniscriptKey> Bare<Pk> {
35+
impl<Pk: Key> Bare<Pk> {
3636
/// Create a new raw descriptor
3737
pub fn new(ms: Miniscript<Pk, BareCtx>) -> Result<Self, Error> {
3838
// do the top-level checks
@@ -92,7 +92,7 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
9292
}
9393
}
9494

95-
impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
95+
impl<Pk: Key + ToPublicKey> Bare<Pk> {
9696
/// Obtains the corresponding script pubkey for this descriptor.
9797
pub fn script_pubkey(&self) -> ScriptBuf {
9898
self.ms.encode()
@@ -135,13 +135,13 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
135135
}
136136
}
137137

138-
impl<Pk: MiniscriptKey> fmt::Debug for Bare<Pk> {
138+
impl<Pk: Key> fmt::Debug for Bare<Pk> {
139139
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
140140
write!(f, "{:?}", self.ms)
141141
}
142142
}
143143

144-
impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
144+
impl<Pk: Key> fmt::Display for Bare<Pk> {
145145
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
146146
use fmt::Write;
147147
let mut wrapped_f = checksum::Formatter::new(f);
@@ -150,7 +150,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
150150
}
151151
}
152152

153-
impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
153+
impl<Pk: Key> Liftable<Pk> for Bare<Pk> {
154154
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
155155
self.ms.lift()
156156
}
@@ -175,16 +175,16 @@ impl_from_str!(
175175
}
176176
);
177177

178-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
178+
impl<Pk: Key> ForEachKey<Pk> for Bare<Pk> {
179179
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
180180
self.ms.for_each_key(pred)
181181
}
182182
}
183183

184184
impl<P, Q> TranslatePk<P, Q> for Bare<P>
185185
where
186-
P: MiniscriptKey,
187-
Q: MiniscriptKey,
186+
P: Key,
187+
Q: Key,
188188
{
189189
type Output = Bare<Q>;
190190

@@ -198,12 +198,12 @@ where
198198

199199
/// A bare PkH descriptor at top level
200200
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
201-
pub struct Pkh<Pk: MiniscriptKey> {
201+
pub struct Pkh<Pk: Key> {
202202
/// underlying publickey
203203
pk: Pk,
204204
}
205205

206-
impl<Pk: MiniscriptKey> Pkh<Pk> {
206+
impl<Pk: Key> Pkh<Pk> {
207207
/// Create a new Pkh descriptor
208208
pub fn new(pk: Pk) -> Result<Self, ScriptContextError> {
209209
// do the top-level checks
@@ -255,7 +255,7 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
255255
}
256256
}
257257

258-
impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
258+
impl<Pk: Key + ToPublicKey> Pkh<Pk> {
259259
/// Obtains the corresponding script pubkey for this descriptor.
260260
pub fn script_pubkey(&self) -> ScriptBuf {
261261
// Fine to hard code the `Network` here because we immediately call
@@ -312,13 +312,13 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
312312
}
313313
}
314314

315-
impl<Pk: MiniscriptKey> fmt::Debug for Pkh<Pk> {
315+
impl<Pk: Key> fmt::Debug for Pkh<Pk> {
316316
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
317317
write!(f, "pkh({:?})", self.pk)
318318
}
319319
}
320320

321-
impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
321+
impl<Pk: Key> fmt::Display for Pkh<Pk> {
322322
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
323323
use fmt::Write;
324324
let mut wrapped_f = checksum::Formatter::new(f);
@@ -327,7 +327,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
327327
}
328328
}
329329

330-
impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
330+
impl<Pk: Key> Liftable<Pk> for Pkh<Pk> {
331331
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
332332
Ok(semantic::Policy::Key(self.pk.clone()))
333333
}
@@ -360,16 +360,16 @@ impl_from_str!(
360360
}
361361
);
362362

363-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
363+
impl<Pk: Key> ForEachKey<Pk> for Pkh<Pk> {
364364
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
365365
pred(&self.pk)
366366
}
367367
}
368368

369369
impl<P, Q> TranslatePk<P, Q> for Pkh<P>
370370
where
371-
P: MiniscriptKey,
372-
Q: MiniscriptKey,
371+
P: Key,
372+
Q: Key,
373373
{
374374
type Output = Pkh<Q>;
375375

src/descriptor/key.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
1616
use crate::prelude::*;
1717
#[cfg(feature = "serde")]
1818
use crate::serde::{Deserialize, Deserializer, Serialize, Serializer};
19-
use crate::{hash256, MiniscriptKey, ToPublicKey};
19+
use crate::{hash256, Key, ToPublicKey};
2020

2121
/// The descriptor pubkey, either a single pubkey or an xpub.
2222
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
@@ -982,7 +982,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
982982
}
983983
}
984984

985-
impl MiniscriptKey for DescriptorPublicKey {
985+
impl Key for DescriptorPublicKey {
986986
type Sha256 = sha256::Hash;
987987
type Hash256 = hash256::Hash;
988988
type Ripemd160 = ripemd160::Hash;
@@ -1103,7 +1103,7 @@ impl fmt::Display for DefiniteDescriptorKey {
11031103
}
11041104
}
11051105

1106-
impl MiniscriptKey for DefiniteDescriptorKey {
1106+
impl Key for DefiniteDescriptorKey {
11071107
type Sha256 = sha256::Hash;
11081108
type Hash256 = hash256::Hash;
11091109
type Ripemd160 = ripemd160::Hash;
@@ -1188,7 +1188,7 @@ mod test {
11881188

11891189
use super::{
11901190
DescriptorKeyParseError, DescriptorMultiXKey, DescriptorPublicKey, DescriptorSecretKey,
1191-
MiniscriptKey, Wildcard,
1191+
Key, Wildcard,
11921192
};
11931193
use crate::prelude::*;
11941194

src/descriptor/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use self::checksum::verify_checksum;
2525
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
2626
use crate::prelude::*;
2727
use crate::{
28-
expression, hash256, miniscript, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier,
28+
expression, hash256, miniscript, BareCtx, Error, ForEachKey, Key, Satisfier,
2929
ToPublicKey, TranslateErr, TranslatePk, Translator,
3030
};
3131

@@ -61,7 +61,7 @@ pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
6161

6262
/// Script descriptor
6363
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
64-
pub enum Descriptor<Pk: MiniscriptKey> {
64+
pub enum Descriptor<Pk: Key> {
6565
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
6666
Bare(Bare<Pk>),
6767
/// Pay-to-PubKey-Hash
@@ -76,42 +76,42 @@ pub enum Descriptor<Pk: MiniscriptKey> {
7676
Tr(Tr<Pk>),
7777
}
7878

79-
impl<Pk: MiniscriptKey> From<Bare<Pk>> for Descriptor<Pk> {
79+
impl<Pk: Key> From<Bare<Pk>> for Descriptor<Pk> {
8080
#[inline]
8181
fn from(inner: Bare<Pk>) -> Self {
8282
Descriptor::Bare(inner)
8383
}
8484
}
8585

86-
impl<Pk: MiniscriptKey> From<Pkh<Pk>> for Descriptor<Pk> {
86+
impl<Pk: Key> From<Pkh<Pk>> for Descriptor<Pk> {
8787
#[inline]
8888
fn from(inner: Pkh<Pk>) -> Self {
8989
Descriptor::Pkh(inner)
9090
}
9191
}
9292

93-
impl<Pk: MiniscriptKey> From<Wpkh<Pk>> for Descriptor<Pk> {
93+
impl<Pk: Key> From<Wpkh<Pk>> for Descriptor<Pk> {
9494
#[inline]
9595
fn from(inner: Wpkh<Pk>) -> Self {
9696
Descriptor::Wpkh(inner)
9797
}
9898
}
9999

100-
impl<Pk: MiniscriptKey> From<Sh<Pk>> for Descriptor<Pk> {
100+
impl<Pk: Key> From<Sh<Pk>> for Descriptor<Pk> {
101101
#[inline]
102102
fn from(inner: Sh<Pk>) -> Self {
103103
Descriptor::Sh(inner)
104104
}
105105
}
106106

107-
impl<Pk: MiniscriptKey> From<Wsh<Pk>> for Descriptor<Pk> {
107+
impl<Pk: Key> From<Wsh<Pk>> for Descriptor<Pk> {
108108
#[inline]
109109
fn from(inner: Wsh<Pk>) -> Self {
110110
Descriptor::Wsh(inner)
111111
}
112112
}
113113

114-
impl<Pk: MiniscriptKey> From<Tr<Pk>> for Descriptor<Pk> {
114+
impl<Pk: Key> From<Tr<Pk>> for Descriptor<Pk> {
115115
#[inline]
116116
fn from(inner: Tr<Pk>) -> Self {
117117
Descriptor::Tr(inner)
@@ -161,7 +161,7 @@ impl DescriptorType {
161161
}
162162
}
163163

164-
impl<Pk: MiniscriptKey> Descriptor<Pk> {
164+
impl<Pk: Key> Descriptor<Pk> {
165165
// Keys
166166

167167
/// Create a new pk descriptor
@@ -380,7 +380,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
380380
}
381381
}
382382

383-
impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
383+
impl<Pk: Key + ToPublicKey> Descriptor<Pk> {
384384
/// Computes the Bitcoin address of the descriptor, if one exists
385385
///
386386
/// Some descriptors like pk() don't have an address.
@@ -513,8 +513,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
513513

514514
impl<P, Q> TranslatePk<P, Q> for Descriptor<P>
515515
where
516-
P: MiniscriptKey,
517-
Q: MiniscriptKey,
516+
P: Key,
517+
Q: Key,
518518
{
519519
type Output = Descriptor<Q>;
520520

@@ -535,7 +535,7 @@ where
535535
}
536536
}
537537

538-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
538+
impl<Pk: Key> ForEachKey<Pk> for Descriptor<Pk> {
539539
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
540540
match *self {
541541
Descriptor::Bare(ref bare) => bare.for_each_key(pred),
@@ -921,7 +921,7 @@ impl_from_str!(
921921
}
922922
);
923923

924-
impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
924+
impl<Pk: Key> fmt::Debug for Descriptor<Pk> {
925925
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
926926
match *self {
927927
Descriptor::Bare(ref sub) => fmt::Debug::fmt(sub, f),
@@ -934,7 +934,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
934934
}
935935
}
936936

937-
impl<Pk: MiniscriptKey> fmt::Display for Descriptor<Pk> {
937+
impl<Pk: Key> fmt::Display for Descriptor<Pk> {
938938
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
939939
match *self {
940940
Descriptor::Bare(ref sub) => fmt::Display::fmt(sub, f),

0 commit comments

Comments
 (0)