Debugging: Checked sub to calculate tx confirmation

This commit is contained in:
rishflab 2021-02-10 12:31:16 +11:00
parent 181e7c5096
commit d4d42ae3ae
2 changed files with 9 additions and 16 deletions

View File

@ -1,6 +1,5 @@
use std::ops::{Add, Sub};
use serde::{Deserialize, Serialize};
use std::ops::Add;
/// Represent a timelock, expressed in relative block height as defined in
/// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
@ -27,7 +26,7 @@ impl From<Timelock> for u32 {
/// after the genesis block.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)]
#[serde(transparent)]
pub struct BlockHeight(u32);
pub struct BlockHeight(pub u32);
impl From<BlockHeight> for u32 {
fn from(height: BlockHeight) -> Self {
@ -49,14 +48,6 @@ impl Add<Timelock> for BlockHeight {
}
}
impl Sub<BlockHeight> for BlockHeight {
type Output = BlockHeight;
fn sub(self, rhs: BlockHeight) -> Self::Output {
BlockHeight(self.0 - rhs.0)
}
}
#[derive(Debug, Clone, Copy)]
pub enum ExpiredTimelocks {
None,

View File

@ -264,13 +264,15 @@ impl WaitForTransactionFinality for Wallet {
let mut interval = interval(execution_params.bitcoin_avg_block_time / 4);
loop {
tracing::debug!("syncing wallet");
let tx_block_height = self.transaction_block_height(txid).await;
tracing::debug!("tx_block_height: {}", tx_block_height.0);
let block_height = self.get_block_height().await;
let confirmations = block_height - tx_block_height;
tracing::debug!("confirmations: {:?}", confirmations);
if confirmations >= BlockHeight::new(execution_params.bitcoin_finality_confirmations) {
break;
tracing::debug!("block_height: {}", block_height.0);
if let Some(confirmations) = block_height.0.checked_sub(tx_block_height.0) {
tracing::debug!("confirmations: {:?}", confirmations);
if confirmations >= execution_params.bitcoin_finality_confirmations {
break;
}
}
interval.tick().await;
}