[wallet] Add assume_height_reached in PSBTSatisfier

This commit is contained in:
Alekos Filini 2020-04-28 16:59:15 +02:00
parent 3895b30083
commit 04d04fd0b2
No known key found for this signature in database
GPG Key ID: 5E8AFC3034FDFA4F
2 changed files with 15 additions and 4 deletions

View File

@ -21,6 +21,7 @@ pub mod utils;
pub struct PSBTSatisfier<'a> { pub struct PSBTSatisfier<'a> {
input: &'a psbt::Input, input: &'a psbt::Input,
assume_height_reached: bool,
create_height: Option<u32>, create_height: Option<u32>,
current_height: Option<u32>, current_height: Option<u32>,
} }
@ -28,11 +29,13 @@ pub struct PSBTSatisfier<'a> {
impl<'a> PSBTSatisfier<'a> { impl<'a> PSBTSatisfier<'a> {
pub fn new( pub fn new(
input: &'a psbt::Input, input: &'a psbt::Input,
assume_height_reached: bool,
create_height: Option<u32>, create_height: Option<u32>,
current_height: Option<u32>, current_height: Option<u32>,
) -> Self { ) -> Self {
PSBTSatisfier { PSBTSatisfier {
input, input,
assume_height_reached,
create_height, create_height,
current_height, current_height,
} }
@ -95,15 +98,23 @@ impl<'a> Satisfier<bitcoin::PublicKey> for PSBTSatisfier<'a> {
// TODO: also check if `nSequence` right // TODO: also check if `nSequence` right
debug!("check_older: {}", height); debug!("check_older: {}", height);
// TODO: test >= / > if let Some(current_height) = self.current_height {
self.current_height.unwrap_or(0) >= self.create_height.unwrap_or(0) + height // TODO: test >= / >
current_height >= self.create_height.unwrap_or(0) + height
} else {
self.assume_height_reached
}
} }
fn check_after(&self, height: u32) -> bool { fn check_after(&self, height: u32) -> bool {
// TODO: also check if `nLockTime` is right // TODO: also check if `nLockTime` is right
debug!("check_after: {}", height); debug!("check_after: {}", height);
self.current_height.unwrap_or(0) > height if let Some(current_height) = self.current_height {
current_height > height
} else {
self.assume_height_reached
}
} }
} }

View File

@ -656,7 +656,7 @@ where
}; };
// TODO: use height once we sync headers // TODO: use height once we sync headers
let satisfier = PSBTSatisfier::new(&psbt.inputs[n], None, None); let satisfier = PSBTSatisfier::new(&psbt.inputs[n], true, None, None);
match desc.satisfy(input, satisfier) { match desc.satisfy(input, satisfier) {
Ok(_) => continue, Ok(_) => continue,