Skip to content

Commit 13c0771

Browse files
committed
Shorten translatefpk identifier
Recently we refactored the translate pk traits, in doing so the identifier fpk and fpkh were favoured over translatefpk, and translatefpkh respectively. I missed a bunch of places. Be uniform across the code base and use the identifiers fpk and fpkh. This patch is the result of applying s/translatefpk/fpk/g to all source files. Refactor only, no logic changes.
1 parent 0537c4d commit 13c0771

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

src/descriptor/sortedmulti.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
9090
pks.map(|pks| SortedMultiVec::new(k as usize, pks))?
9191
}
9292

93-
/// This will panic if translatefpk returns an uncompressed key when
93+
/// This will panic if fpk returns an uncompressed key when
9494
/// converting to a Segwit descriptor. To prevent this panic, ensure
95-
/// translatefpk returns an error in this case instead.
95+
/// fpk returns an error in this case instead.
9696
pub fn translate_pk<FPk, Q, FuncError>(
9797
&self,
98-
translatefpk: &mut FPk,
98+
fpk: &mut FPk,
9999
) -> Result<SortedMultiVec<Q, Ctx>, FuncError>
100100
where
101101
FPk: FnMut(&Pk) -> Result<Q, FuncError>,
102102
Q: MiniscriptKey,
103103
{
104-
let pks: Result<Vec<Q>, _> = self.pks.iter().map(&mut *translatefpk).collect();
104+
let pks: Result<Vec<Q>, _> = self.pks.iter().map(&mut *fpk).collect();
105105
Ok(SortedMultiVec {
106106
k: self.k,
107107
pks: pks?,

src/descriptor/tr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
129129
// Helper function to translate keys
130130
fn translate_helper<FPk, FPkh, Q, Error>(
131131
&self,
132-
translatefpk: &mut FPk,
133-
translatefpkh: &mut FPkh,
132+
fpk: &mut FPk,
133+
fpkh: &mut FPkh,
134134
) -> Result<TapTree<Q>, Error>
135135
where
136136
FPk: FnMut(&Pk) -> Result<Q, Error>,
@@ -139,12 +139,10 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
139139
{
140140
let frag = match self {
141141
TapTree::Tree(l, r) => TapTree::Tree(
142-
Arc::new(l.translate_helper(translatefpk, translatefpkh)?),
143-
Arc::new(r.translate_helper(translatefpk, translatefpkh)?),
142+
Arc::new(l.translate_helper(fpk, fpkh)?),
143+
Arc::new(r.translate_helper(fpk, fpkh)?),
144144
),
145-
TapTree::Leaf(ms) => {
146-
TapTree::Leaf(Arc::new(ms.translate_pk(translatefpk, translatefpkh)?))
147-
}
145+
TapTree::Leaf(ms) => TapTree::Leaf(Arc::new(ms.translate_pk(fpk, fpkh)?)),
148146
};
149147
Ok(frag)
150148
}

src/policy/concrete.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,44 +185,42 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
185185
/// let expected_policy = Policy::from_str(&format!("and(pk({}),pk({}))", alice_key, bob_key)).unwrap();
186186
/// assert_eq!(real_policy, expected_policy);
187187
/// ```
188-
pub fn translate_pk<Fpk, Q, E>(&self, mut translatefpk: Fpk) -> Result<Policy<Q>, E>
188+
pub fn translate_pk<Fpk, Q, E>(&self, mut fpk: Fpk) -> Result<Policy<Q>, E>
189189
where
190190
Fpk: FnMut(&Pk) -> Result<Q, E>,
191191
Q: MiniscriptKey,
192192
{
193-
self._translate_pk(&mut translatefpk)
193+
self._translate_pk(&mut fpk)
194194
}
195195

196-
fn _translate_pk<Fpk, Q, E>(&self, translatefpk: &mut Fpk) -> Result<Policy<Q>, E>
196+
fn _translate_pk<Fpk, Q, E>(&self, fpk: &mut Fpk) -> Result<Policy<Q>, E>
197197
where
198198
Fpk: FnMut(&Pk) -> Result<Q, E>,
199199
Q: MiniscriptKey,
200200
{
201201
match *self {
202202
Policy::Unsatisfiable => Ok(Policy::Unsatisfiable),
203203
Policy::Trivial => Ok(Policy::Trivial),
204-
Policy::Key(ref pk) => translatefpk(pk).map(Policy::Key),
204+
Policy::Key(ref pk) => fpk(pk).map(Policy::Key),
205205
Policy::Sha256(ref h) => Ok(Policy::Sha256(h.clone())),
206206
Policy::Hash256(ref h) => Ok(Policy::Hash256(h.clone())),
207207
Policy::Ripemd160(ref h) => Ok(Policy::Ripemd160(h.clone())),
208208
Policy::Hash160(ref h) => Ok(Policy::Hash160(h.clone())),
209209
Policy::After(n) => Ok(Policy::After(n)),
210210
Policy::Older(n) => Ok(Policy::Older(n)),
211211
Policy::Threshold(k, ref subs) => {
212-
let new_subs: Result<Vec<Policy<Q>>, _> = subs
213-
.iter()
214-
.map(|sub| sub._translate_pk(translatefpk))
215-
.collect();
212+
let new_subs: Result<Vec<Policy<Q>>, _> =
213+
subs.iter().map(|sub| sub._translate_pk(fpk)).collect();
216214
new_subs.map(|ok| Policy::Threshold(k, ok))
217215
}
218216
Policy::And(ref subs) => Ok(Policy::And(
219217
subs.iter()
220-
.map(|sub| sub._translate_pk(translatefpk))
218+
.map(|sub| sub._translate_pk(fpk))
221219
.collect::<Result<Vec<Policy<Q>>, E>>()?,
222220
)),
223221
Policy::Or(ref subs) => Ok(Policy::Or(
224222
subs.iter()
225-
.map(|&(ref prob, ref sub)| Ok((*prob, sub._translate_pk(translatefpk)?)))
223+
.map(|&(ref prob, ref sub)| Ok((*prob, sub._translate_pk(fpk)?)))
226224
.collect::<Result<Vec<(usize, Policy<Q>)>, E>>()?,
227225
)),
228226
}

src/policy/semantic.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,32 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
9999
/// let expected_policy = Policy::<PublicKey>::from_str(&format!("and(pkh({}),pkh({}))", alice_pkh, bob_pkh)).unwrap();
100100
/// assert_eq!(real_policy, expected_policy);
101101
/// ```
102-
pub fn translate_pkh<Fpkh, Q, E>(&self, mut translatefpkh: Fpkh) -> Result<Policy<Q>, E>
102+
pub fn translate_pkh<Fpkh, Q, E>(&self, mut fpkh: Fpkh) -> Result<Policy<Q>, E>
103103
where
104104
Fpkh: FnMut(&Pk::Hash) -> Result<Q::Hash, E>,
105105
Q: MiniscriptKey,
106106
{
107-
self._translate_pkh(&mut translatefpkh)
107+
self._translate_pkh(&mut fpkh)
108108
}
109109

110-
fn _translate_pkh<Fpkh, Q, E>(&self, translatefpkh: &mut Fpkh) -> Result<Policy<Q>, E>
110+
fn _translate_pkh<Fpkh, Q, E>(&self, fpkh: &mut Fpkh) -> Result<Policy<Q>, E>
111111
where
112112
Fpkh: FnMut(&Pk::Hash) -> Result<Q::Hash, E>,
113113
Q: MiniscriptKey,
114114
{
115115
match *self {
116116
Policy::Unsatisfiable => Ok(Policy::Unsatisfiable),
117117
Policy::Trivial => Ok(Policy::Trivial),
118-
Policy::KeyHash(ref pkh) => translatefpkh(pkh).map(Policy::KeyHash),
118+
Policy::KeyHash(ref pkh) => fpkh(pkh).map(Policy::KeyHash),
119119
Policy::Sha256(ref h) => Ok(Policy::Sha256(h.clone())),
120120
Policy::Hash256(ref h) => Ok(Policy::Hash256(h.clone())),
121121
Policy::Ripemd160(ref h) => Ok(Policy::Ripemd160(h.clone())),
122122
Policy::Hash160(ref h) => Ok(Policy::Hash160(h.clone())),
123123
Policy::After(n) => Ok(Policy::After(n)),
124124
Policy::Older(n) => Ok(Policy::Older(n)),
125125
Policy::Threshold(k, ref subs) => {
126-
let new_subs: Result<Vec<Policy<Q>>, _> = subs
127-
.iter()
128-
.map(|sub| sub._translate_pkh(translatefpkh))
129-
.collect();
126+
let new_subs: Result<Vec<Policy<Q>>, _> =
127+
subs.iter().map(|sub| sub._translate_pkh(fpkh)).collect();
130128
new_subs.map(|ok| Policy::Threshold(k, ok))
131129
}
132130
}

0 commit comments

Comments
 (0)