|
22 | 22 | use std::{error, fmt};
|
23 | 23 |
|
24 | 24 | use bitcoin;
|
| 25 | +use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d}; |
25 | 26 | use bitcoin::secp256k1::{self, Secp256k1};
|
26 | 27 | use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
|
27 | 28 | use bitcoin::Script;
|
28 | 29 |
|
29 | 30 | use interpreter;
|
30 | 31 | use miniscript::limits::SEQUENCE_LOCKTIME_DISABLE_FLAG;
|
31 | 32 | use miniscript::satisfy::{bitcoinsig_from_rawsig, After, Older};
|
32 |
| -use BitcoinSig; |
33 | 33 | use Satisfier;
|
| 34 | +use {BitcoinSig, Preimage32}; |
34 | 35 | use {MiniscriptKey, ToPublicKey};
|
35 | 36 |
|
36 | 37 | mod finalizer;
|
@@ -279,6 +280,44 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfie
|
279 | 280 | <Satisfier<Pk>>::check_older(&Older(seq), n)
|
280 | 281 | }
|
281 | 282 | }
|
| 283 | + |
| 284 | + fn lookup_hash160(&self, h: hash160::Hash) -> Option<Preimage32> { |
| 285 | + self.psbt.inputs[self.index] |
| 286 | + .hash160_preimages |
| 287 | + .get(&h) |
| 288 | + .and_then(try_vec_as_preimage32) |
| 289 | + } |
| 290 | + |
| 291 | + fn lookup_sha256(&self, h: sha256::Hash) -> Option<Preimage32> { |
| 292 | + self.psbt.inputs[self.index] |
| 293 | + .sha256_preimages |
| 294 | + .get(&h) |
| 295 | + .and_then(try_vec_as_preimage32) |
| 296 | + } |
| 297 | + |
| 298 | + fn lookup_hash256(&self, h: sha256d::Hash) -> Option<Preimage32> { |
| 299 | + self.psbt.inputs[self.index] |
| 300 | + .hash256_preimages |
| 301 | + .get(&h) |
| 302 | + .and_then(try_vec_as_preimage32) |
| 303 | + } |
| 304 | + |
| 305 | + fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<Preimage32> { |
| 306 | + self.psbt.inputs[self.index] |
| 307 | + .ripemd160_preimages |
| 308 | + .get(&h) |
| 309 | + .and_then(try_vec_as_preimage32) |
| 310 | + } |
| 311 | +} |
| 312 | + |
| 313 | +fn try_vec_as_preimage32(vec: &Vec<u8>) -> Option<Preimage32> { |
| 314 | + if vec.len() == 32 { |
| 315 | + let mut arr = [0u8; 32]; |
| 316 | + arr.copy_from_slice(&vec); |
| 317 | + Some(arr) |
| 318 | + } else { |
| 319 | + None |
| 320 | + } |
282 | 321 | }
|
283 | 322 |
|
284 | 323 | fn sanity_check(psbt: &Psbt) -> Result<(), Error> {
|
|
0 commit comments