Skip to content

Commit e000146

Browse files
committed
tr: cache TrSpendInfo when computing it
This was an oversight in #815.
1 parent 2284858 commit e000146

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/descriptor/tr/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
125125
/// This data is needed to compute the Taproot output, so this method is implicitly
126126
/// called through [`Self::script_pubkey`], [`Self::address`], etc. It is also needed
127127
/// to compute the hash needed to sign the output.
128-
pub fn spend_info(&self) -> TrSpendInfo<Pk>
128+
pub fn spend_info(&self) -> Arc<TrSpendInfo<Pk>>
129129
where
130130
Pk: ToPublicKey,
131131
{
132-
TrSpendInfo::from_tr(self)
132+
let mut lock = self.spend_info.lock().unwrap();
133+
match *lock {
134+
Some(ref res) => Arc::clone(res),
135+
None => {
136+
let arc = Arc::new(TrSpendInfo::from_tr(self));
137+
*lock = Some(Arc::clone(&arc));
138+
arc
139+
}
140+
}
133141
}
134142

135143
/// Checks whether the descriptor is safe.

0 commit comments

Comments
 (0)