Skip to content

Commit fca7d9d

Browse files
tchardingsanket1729
authored andcommitted
Remove f_ prefix from translator method names
We can shorten the unusual `Translator` trait method names with no loss of meaning. It is not immediately obvious what the `f_` prefix means, it is a relic of history from when we used function pointers. Remove the `f_` prefix, shortening the translator method names to just the thing they are translating.
1 parent ac5537f commit fca7d9d

File tree

14 files changed

+68
-69
lines changed

14 files changed

+68
-69
lines changed

src/descriptor/bare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,6 @@ where
346346
where
347347
T: Translator<P, Q, E>,
348348
{
349-
Ok(Pkh::new(t.f_pk(&self.pk)?))
349+
Ok(Pkh::new(t.pk(&self.pk)?))
350350
}
351351
}

src/descriptor/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ impl Descriptor<DescriptorPublicKey> {
527527
struct Derivator(u32);
528528

529529
impl PkTranslator<DescriptorPublicKey, DerivedDescriptorKey, ()> for Derivator {
530-
fn f_pk(&mut self, pk: &DescriptorPublicKey) -> Result<DerivedDescriptorKey, ()> {
530+
fn pk(&mut self, pk: &DescriptorPublicKey) -> Result<DerivedDescriptorKey, ()> {
531531
Ok(pk.clone().derive(self.0))
532532
}
533533

534-
fn f_pkh(&mut self, pkh: &DescriptorPublicKey) -> Result<DerivedDescriptorKey, ()> {
534+
fn pkh(&mut self, pkh: &DescriptorPublicKey) -> Result<DerivedDescriptorKey, ()> {
535535
Ok(pkh.clone().derive(self.0))
536536
}
537537
}
@@ -574,14 +574,14 @@ impl Descriptor<DescriptorPublicKey> {
574574
PkTranslator<DerivedDescriptorKey, bitcoin::PublicKey, ConversionError>
575575
for Derivator<'a, C>
576576
{
577-
fn f_pk(
577+
fn pk(
578578
&mut self,
579579
pk: &DerivedDescriptorKey,
580580
) -> Result<bitcoin::PublicKey, ConversionError> {
581581
pk.derive_public_key(&self.0)
582582
}
583583

584-
fn f_pkh(
584+
fn pkh(
585585
&mut self,
586586
pkh: &DerivedDescriptorKey,
587587
) -> Result<bitcoin::hashes::hash160::Hash, ConversionError> {
@@ -633,15 +633,15 @@ impl Descriptor<DescriptorPublicKey> {
633633
impl<'a, C: secp256k1::Signing> Translator<String, DescriptorPublicKey, Error>
634634
for KeyMapWrapper<'a, C>
635635
{
636-
fn f_pk(&mut self, pk: &String) -> Result<DescriptorPublicKey, Error> {
636+
fn pk(&mut self, pk: &String) -> Result<DescriptorPublicKey, Error> {
637637
parse_key(pk, &mut self.0, self.1)
638638
}
639639

640-
fn f_pkh(&mut self, pkh: &String) -> Result<DescriptorPublicKey, Error> {
640+
fn pkh(&mut self, pkh: &String) -> Result<DescriptorPublicKey, Error> {
641641
parse_key(pkh, &mut self.0, self.1)
642642
}
643643

644-
fn f_sha256(&mut self, sha256: &String) -> Result<sha256::Hash, Error> {
644+
fn sha256(&mut self, sha256: &String) -> Result<sha256::Hash, Error> {
645645
let hash =
646646
sha256::Hash::from_str(sha256).map_err(|e| Error::Unexpected(e.to_string()))?;
647647
Ok(hash)
@@ -661,15 +661,15 @@ impl Descriptor<DescriptorPublicKey> {
661661
struct KeyMapLookUp<'a>(&'a KeyMap);
662662

663663
impl<'a> Translator<DescriptorPublicKey, String, ()> for KeyMapLookUp<'a> {
664-
fn f_pk(&mut self, pk: &DescriptorPublicKey) -> Result<String, ()> {
664+
fn pk(&mut self, pk: &DescriptorPublicKey) -> Result<String, ()> {
665665
key_to_string(pk, self.0)
666666
}
667667

668-
fn f_pkh(&mut self, pkh: &DescriptorPublicKey) -> Result<String, ()> {
668+
fn pkh(&mut self, pkh: &DescriptorPublicKey) -> Result<String, ()> {
669669
key_to_string(pkh, self.0)
670670
}
671671

672-
fn f_sha256(&mut self, sha256: &sha256::Hash) -> Result<String, ()> {
672+
fn sha256(&mut self, sha256: &sha256::Hash) -> Result<String, ()> {
673673
Ok(sha256.to_string())
674674
}
675675
}

src/descriptor/segwitv0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,6 @@ where
459459
where
460460
T: Translator<P, Q, E>,
461461
{
462-
Ok(Wpkh::new(t.f_pk(&self.pk)?).expect("Uncompressed keys in Wpkh"))
462+
Ok(Wpkh::new(t.pk(&self.pk)?).expect("Uncompressed keys in Wpkh"))
463463
}
464464
}

src/descriptor/sortedmulti.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
102102
T: Translator<Pk, Q, FuncError>,
103103
Q: MiniscriptKey,
104104
{
105-
let pks: Result<Vec<Q>, _> = self.pks.iter().map(|pk| t.f_pk(pk)).collect();
105+
let pks: Result<Vec<Q>, _> = self.pks.iter().map(|pk| t.pk(pk)).collect();
106106
Ok(SortedMultiVec {
107107
k: self.k,
108108
pks: pks?,

src/descriptor/tr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ where
611611
T: Translator<P, Q, E>,
612612
{
613613
let translate_desc = Tr {
614-
internal_key: translate.f_pk(&self.internal_key)?,
614+
internal_key: translate.pk(&self.internal_key)?,
615615
tree: match &self.tree {
616616
Some(tree) => Some(tree.translate_helper(translate)?),
617617
None => None,

src/interpreter/inner.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,15 @@ impl<Ctx: ScriptContext> ToNoChecks for Miniscript<bitcoin::PublicKey, Ctx> {
378378
struct TranslateFullPk;
379379

380380
impl PkTranslator<bitcoin::PublicKey, BitcoinKey, ()> for TranslateFullPk {
381-
fn f_pk(&mut self, pk: &bitcoin::PublicKey) -> Result<BitcoinKey, ()> {
381+
fn pk(&mut self, pk: &bitcoin::PublicKey) -> Result<BitcoinKey, ()> {
382382
Ok(BitcoinKey::Fullkey(*pk))
383383
}
384384

385-
fn f_pkh(&mut self, pkh: &hash160::Hash) -> Result<TypedHash160, ()> {
385+
fn pkh(&mut self, pkh: &hash160::Hash) -> Result<TypedHash160, ()> {
386386
Ok(TypedHash160::FullKey(*pkh))
387387
}
388388
}
389389

390-
// specify the () error type as this cannot error
391390
self.real_translate_pk(&mut TranslateFullPk)
392391
.expect("Translation should succeed")
393392
}
@@ -399,11 +398,11 @@ impl<Ctx: ScriptContext> ToNoChecks for Miniscript<bitcoin::XOnlyPublicKey, Ctx>
399398
struct TranslateXOnlyPk;
400399

401400
impl PkTranslator<bitcoin::XOnlyPublicKey, BitcoinKey, ()> for TranslateXOnlyPk {
402-
fn f_pk(&mut self, pk: &bitcoin::XOnlyPublicKey) -> Result<BitcoinKey, ()> {
401+
fn pk(&mut self, pk: &bitcoin::XOnlyPublicKey) -> Result<BitcoinKey, ()> {
403402
Ok(BitcoinKey::XOnlyPublicKey(*pk))
404403
}
405404

406-
fn f_pkh(&mut self, pkh: &hash160::Hash) -> Result<TypedHash160, ()> {
405+
fn pkh(&mut self, pkh: &hash160::Hash) -> Result<TypedHash160, ()> {
407406
Ok(TypedHash160::XonlyKey(*pkh))
408407
}
409408
}

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,13 @@ where
397397
Q: MiniscriptKey,
398398
{
399399
/// Translates public keys P -> Q.
400-
fn f_pk(&mut self, pk: &P) -> Result<Q, E>;
400+
fn pk(&mut self, pk: &P) -> Result<Q, E>;
401401

402402
/// Translates public key hashes P::Hash -> Q::Hash.
403-
fn f_pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
403+
fn pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
404404

405405
/// Translates sha256 hashes from P::Sha256 -> Q::Sha256
406-
fn f_sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
406+
fn sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
407407
}
408408

409409
/// Provides the conversion information required in [`TranslatePk`].
@@ -415,10 +415,10 @@ where
415415
Q: MiniscriptKey<Sha256 = P::Sha256>,
416416
{
417417
/// Provides the translation public keys P -> Q
418-
fn f_pk(&mut self, pk: &P) -> Result<Q, E>;
418+
fn pk(&mut self, pk: &P) -> Result<Q, E>;
419419

420420
/// Provides the translation public keys hashes P::Hash -> Q::Hash
421-
fn f_pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
421+
fn pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
422422
}
423423

424424
impl<P, Q, E, T> Translator<P, Q, E> for T
@@ -427,15 +427,15 @@ where
427427
P: MiniscriptKey,
428428
Q: MiniscriptKey<Sha256 = P::Sha256>,
429429
{
430-
fn f_pk(&mut self, pk: &P) -> Result<Q, E> {
431-
<Self as PkTranslator<P, Q, E>>::f_pk(self, pk)
430+
fn pk(&mut self, pk: &P) -> Result<Q, E> {
431+
<Self as PkTranslator<P, Q, E>>::pk(self, pk)
432432
}
433433

434-
fn f_pkh(&mut self, pkh: &<P as MiniscriptKey>::Hash) -> Result<<Q as MiniscriptKey>::Hash, E> {
435-
<Self as PkTranslator<P, Q, E>>::f_pkh(self, pkh)
434+
fn pkh(&mut self, pkh: &<P as MiniscriptKey>::Hash) -> Result<<Q as MiniscriptKey>::Hash, E> {
435+
<Self as PkTranslator<P, Q, E>>::pkh(self, pkh)
436436
}
437437

438-
fn f_sha256(&mut self, sha256: &<P as MiniscriptKey>::Sha256) -> Result<<Q>::Sha256, E> {
438+
fn sha256(&mut self, sha256: &<P as MiniscriptKey>::Sha256) -> Result<<Q>::Sha256, E> {
439439
Ok(sha256.clone())
440440
}
441441
}

src/miniscript/astelem.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
129129
T: Translator<Pk, Q, E>,
130130
{
131131
let frag: Terminal<Q, CtxQ> = match *self {
132-
Terminal::PkK(ref p) => Terminal::PkK(t.f_pk(p)?),
133-
Terminal::PkH(ref p) => Terminal::PkH(t.f_pkh(p)?),
132+
Terminal::PkK(ref p) => Terminal::PkK(t.pk(p)?),
133+
Terminal::PkH(ref p) => Terminal::PkH(t.pkh(p)?),
134134
Terminal::After(n) => Terminal::After(n),
135135
Terminal::Older(n) => Terminal::Older(n),
136-
Terminal::Sha256(ref x) => Terminal::Sha256(t.f_sha256(&x)?),
136+
Terminal::Sha256(ref x) => Terminal::Sha256(t.sha256(&x)?),
137137
Terminal::Hash256(x) => Terminal::Hash256(x),
138138
Terminal::Ripemd160(x) => Terminal::Ripemd160(x),
139139
Terminal::Hash160(x) => Terminal::Hash160(x),
@@ -185,11 +185,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
185185
Terminal::Thresh(k, subs?)
186186
}
187187
Terminal::Multi(k, ref keys) => {
188-
let keys: Result<Vec<Q>, _> = keys.iter().map(|k| t.f_pk(k)).collect();
188+
let keys: Result<Vec<Q>, _> = keys.iter().map(|k| t.pk(k)).collect();
189189
Terminal::Multi(k, keys?)
190190
}
191191
Terminal::MultiA(k, ref keys) => {
192-
let keys: Result<Vec<Q>, _> = keys.iter().map(|k| t.f_pk(k)).collect();
192+
let keys: Result<Vec<Q>, _> = keys.iter().map(|k| t.pk(k)).collect();
193193
Terminal::MultiA(k, keys?)
194194
}
195195
};

src/miniscript/iter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
121121
/// NB: The function analyzes only single miniscript item and not any of its descendants in AST.
122122
/// To obtain a list of all public keys within AST use [Miniscript::iter_pk()] function, for example
123123
/// `miniscript.iter_pubkeys().collect()`.
124-
pub fn get_leaf_pk(&self) -> Vec<Pk> {
124+
pub fn get_leapk(&self) -> Vec<Pk> {
125125
match self.node {
126126
Terminal::PkK(ref key) => vec![key.clone()],
127127
Terminal::Multi(_, ref keys) | Terminal::MultiA(_, ref keys) => keys.clone(),
@@ -138,7 +138,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
138138
/// NB: The function analyzes only single miniscript item and not any of its descendants in AST.
139139
/// To obtain a list of all public key hashes within AST use [Miniscript::iter_pkh()] function,
140140
/// for example `miniscript.iter_pubkey_hashes().collect()`.
141-
pub fn get_leaf_pkh(&self) -> Vec<Pk::Hash> {
141+
pub fn get_leapkh(&self) -> Vec<Pk::Hash> {
142142
match self.node {
143143
Terminal::PkH(ref hash) => vec![hash.clone()],
144144
Terminal::PkK(ref key) => vec![key.to_pubkeyhash()],
@@ -156,7 +156,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
156156
/// NB: The function analyzes only single miniscript item and not any of its descendants in AST.
157157
/// To obtain a list of all public keys or hashes within AST use [Miniscript::iter_pk_pkh()]
158158
/// function, for example `miniscript.iter_pubkeys_and_hashes().collect()`.
159-
pub fn get_leaf_pk_pkh(&self) -> Vec<PkPkh<Pk>> {
159+
pub fn get_leapk_pkh(&self) -> Vec<PkPkh<Pk>> {
160160
match self.node {
161161
Terminal::PkH(ref hash) => vec![PkPkh::HashedPubkey(hash.clone())],
162162
Terminal::PkK(ref key) => vec![PkPkh::PlainPubkey(key.clone())],
@@ -605,7 +605,7 @@ pub mod test {
605605
return;
606606
}
607607
let ms = *ms.branches().first().unwrap_or(&&ms);
608-
assert_eq!(ms.get_leaf_pk(), k);
608+
assert_eq!(ms.get_leapk(), k);
609609
})
610610
}
611611

@@ -624,7 +624,7 @@ pub mod test {
624624
.collect();
625625
// In our test cases we always have plain keys going first
626626
all.extend(h);
627-
assert_eq!(ms.get_leaf_pkh(), all);
627+
assert_eq!(ms.get_leapkh(), all);
628628
})
629629
}
630630

@@ -642,7 +642,7 @@ pub mod test {
642642
} else {
643643
k.into_iter().map(|k| PkPkh::PlainPubkey(k)).collect()
644644
};
645-
assert_eq!(ms.get_leaf_pk_pkh(), r);
645+
assert_eq!(ms.get_leapk_pkh(), r);
646646
})
647647
}
648648

src/policy/concrete.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,17 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
344344
/// // we would use the general Translator Trait.
345345
/// impl Translator<String, bitcoin::PublicKey, ()> for StrPkTranslator {
346346
/// // Provides the translation public keys P -> Q
347-
/// fn f_pk(&mut self, pk: &String) -> Result<bitcoin::PublicKey, ()> {
347+
/// fn pk(&mut self, pk: &String) -> Result<bitcoin::PublicKey, ()> {
348348
/// self.pk_map.get(pk).copied().ok_or(()) // Dummy Err
349349
/// }
350350
///
351351
/// // If our policy also contained other fragments, we could provide the translation here.
352-
/// fn f_pkh(&mut self, pkh: &String) -> Result<hash160::Hash, ()> {
352+
/// fn pkh(&mut self, pkh: &String) -> Result<hash160::Hash, ()> {
353353
/// unreachable!("Policy does not contain any pkh fragment");
354354
/// }
355355
///
356356
/// // If our policy also contained other fragments, we could provide the translation here.
357-
/// fn f_sha256(&mut self, sha256: &String) -> Result<sha256::Hash, ()> {
357+
/// fn sha256(&mut self, sha256: &String) -> Result<sha256::Hash, ()> {
358358
/// unreachable!("Policy does not contain any sha256 fragment");
359359
/// }
360360
/// }
@@ -385,8 +385,8 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
385385
match *self {
386386
Policy::Unsatisfiable => Ok(Policy::Unsatisfiable),
387387
Policy::Trivial => Ok(Policy::Trivial),
388-
Policy::Key(ref pk) => t.f_pk(pk).map(Policy::Key),
389-
Policy::Sha256(ref h) => t.f_sha256(h).map(Policy::Sha256),
388+
Policy::Key(ref pk) => t.pk(pk).map(Policy::Key),
389+
Policy::Sha256(ref h) => t.sha256(h).map(Policy::Sha256),
390390
Policy::Hash256(ref h) => Ok(Policy::Hash256(*h)),
391391
Policy::Ripemd160(ref h) => Ok(Policy::Ripemd160(*h)),
392392
Policy::Hash160(ref h) => Ok(Policy::Hash160(*h)),

0 commit comments

Comments
 (0)