Skip to content

Commit 690a1aa

Browse files
committed
Rename traits MiniscriptKey and ScriptContext
In an effort to make the code more terse with no loss of clarity rename the crate's main two traits `MiniscriptKey` to `Key` and `ScriptContext` to `Context`. The diff is big but can be verified by simply doing a search-and-replace on `MiniscriptKey` -> `Key` and `ScriptContext` -> `Context`. Then run `cargo +nightly fmt`. No other manual changes.
1 parent c15d4ef commit 690a1aa

34 files changed

+552
-578
lines changed

bitcoind-tests/tests/setup/test_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use bitcoin::secp256k1;
2525
use internals::hex::exts::DisplayHex;
2626
use miniscript::descriptor::{SinglePub, SinglePubKey};
2727
use miniscript::{
28-
bitcoin, hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext,
29-
TranslatePk, Translator,
28+
bitcoin, hash256, Context, Descriptor, DescriptorPublicKey, Error, Miniscript, TranslatePk,
29+
Translator,
3030
};
3131
use rand::RngCore;
3232
use secp256k1::XOnlyPublicKey;
@@ -150,7 +150,7 @@ pub fn random_pk(mut seed: u8) -> bitcoin::PublicKey {
150150
#[allow(dead_code)]
151151
// https://github.com/rust-lang/rust/issues/46379. The code is pub fn and integration test, but still shows warnings
152152
/// Parse an insane miniscript into a miniscript with the format described above at file header
153-
pub fn parse_insane_ms<Ctx: ScriptContext>(
153+
pub fn parse_insane_ms<Ctx: Context>(
154154
ms: &str,
155155
pubdata: &PubData,
156156
) -> Miniscript<DescriptorPublicKey, Ctx> {

bitcoind-tests/tests/test_desc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bitcoin::{
1919
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
2020
use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf};
2121
use miniscript::psbt::{PsbtExt, PsbtInputExt};
22-
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
22+
use miniscript::{Context, Descriptor, Miniscript, ToPublicKey};
2323
mod setup;
2424

2525
use rand::RngCore;
@@ -318,7 +318,7 @@ pub fn test_desc_satisfy(
318318
}
319319

320320
// Find all secret corresponding to the known public keys in ms
321-
fn find_sks_ms<Ctx: ScriptContext>(
321+
fn find_sks_ms<Ctx: Context>(
322322
ms: &Miniscript<bitcoin::PublicKey, Ctx>,
323323
testdata: &TestData,
324324
) -> Vec<secp256k1::SecretKey> {

examples/sign_multisig.rs

+1-1
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

+22-22
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ use bitcoin::{Address, Network, ScriptBuf};
1414

1515
use super::checksum::{self, verify_checksum};
1616
use crate::expression::{self, FromTree};
17-
use crate::miniscript::context::{ScriptContext, ScriptContextError};
17+
use crate::miniscript::context::{Context, ContextError};
1818
use crate::policy::{semantic, Liftable};
1919
use crate::prelude::*;
2020
use crate::util::{varint_len, witness_to_scriptsig};
2121
use crate::{
22-
BareCtx, Error, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey, TranslateErr,
23-
TranslatePk, Translator,
22+
BareCtx, Error, ForEachKey, Key, Miniscript, Satisfier, ToPublicKey, TranslateErr, TranslatePk,
23+
Translator,
2424
};
2525

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

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

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

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

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

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

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

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

@@ -197,14 +197,14 @@ where
197197

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

205-
impl<Pk: MiniscriptKey> Pkh<Pk> {
205+
impl<Pk: Key> Pkh<Pk> {
206206
/// Create a new Pkh descriptor
207-
pub fn new(pk: Pk) -> Result<Self, ScriptContextError> {
207+
pub fn new(pk: Pk) -> Result<Self, ContextError> {
208208
// do the top-level checks
209209
match BareCtx::check_pk(&pk) {
210210
Ok(()) => Ok(Pkh { pk }),
@@ -254,7 +254,7 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
254254
}
255255
}
256256

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

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

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

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

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

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

src/descriptor/key.rs

+4-4
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

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use crate::miniscript::decode::Terminal;
2525
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
2626
use crate::prelude::*;
2727
use crate::{
28-
expression, hash256, BareCtx, Error, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey,
29-
TranslateErr, TranslatePk, Translator,
28+
expression, hash256, BareCtx, Error, ForEachKey, Key, Satisfier, ToPublicKey, TranslateErr,
29+
TranslatePk, Translator,
3030
};
3131

3232
mod bare;
@@ -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
@@ -378,7 +378,7 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
378378
}
379379
}
380380

381-
impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
381+
impl<Pk: Key + ToPublicKey> Descriptor<Pk> {
382382
/// Computes the Bitcoin address of the descriptor, if one exists
383383
///
384384
/// Some descriptors like pk() don't have an address.
@@ -511,8 +511,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
511511

512512
impl<P, Q> TranslatePk<P, Q> for Descriptor<P>
513513
where
514-
P: MiniscriptKey,
515-
Q: MiniscriptKey,
514+
P: Key,
515+
Q: Key,
516516
{
517517
type Output = Descriptor<Q>;
518518

@@ -533,7 +533,7 @@ where
533533
}
534534
}
535535

536-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
536+
impl<Pk: Key> ForEachKey<Pk> for Descriptor<Pk> {
537537
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
538538
match *self {
539539
Descriptor::Bare(ref bare) => bare.for_each_key(pred),
@@ -919,7 +919,7 @@ impl_from_str!(
919919
}
920920
);
921921

922-
impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
922+
impl<Pk: Key> fmt::Debug for Descriptor<Pk> {
923923
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
924924
match *self {
925925
Descriptor::Bare(ref sub) => fmt::Debug::fmt(sub, f),
@@ -932,7 +932,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Descriptor<Pk> {
932932
}
933933
}
934934

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

0 commit comments

Comments
 (0)