mirror of
				https://github.com/comit-network/xmr-btc-swap.git
				synced 2025-10-31 07:02:08 -04:00 
			
		
		
		
	Debugging: Checked sub to calculate tx confirmation
This commit is contained in:
		
							parent
							
								
									181e7c5096
								
							
						
					
					
						commit
						d4d42ae3ae
					
				
					 2 changed files with 9 additions and 16 deletions
				
			
		|  | @ -1,6 +1,5 @@ | ||||||
| use std::ops::{Add, Sub}; |  | ||||||
| 
 |  | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
|  | use std::ops::Add; | ||||||
| 
 | 
 | ||||||
| /// Represent a timelock, expressed in relative block height as defined in
 | /// Represent a timelock, expressed in relative block height as defined in
 | ||||||
| /// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
 | /// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
 | ||||||
|  | @ -27,7 +26,7 @@ impl From<Timelock> for u32 { | ||||||
| /// after the genesis block.
 | /// after the genesis block.
 | ||||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)] | #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)] | ||||||
| #[serde(transparent)] | #[serde(transparent)] | ||||||
| pub struct BlockHeight(u32); | pub struct BlockHeight(pub u32); | ||||||
| 
 | 
 | ||||||
| impl From<BlockHeight> for u32 { | impl From<BlockHeight> for u32 { | ||||||
|     fn from(height: BlockHeight) -> Self { |     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)] | #[derive(Debug, Clone, Copy)] | ||||||
| pub enum ExpiredTimelocks { | pub enum ExpiredTimelocks { | ||||||
|     None, |     None, | ||||||
|  |  | ||||||
|  | @ -264,14 +264,16 @@ impl WaitForTransactionFinality for Wallet { | ||||||
|         let mut interval = interval(execution_params.bitcoin_avg_block_time / 4); |         let mut interval = interval(execution_params.bitcoin_avg_block_time / 4); | ||||||
| 
 | 
 | ||||||
|         loop { |         loop { | ||||||
|             tracing::debug!("syncing wallet"); |  | ||||||
|             let tx_block_height = self.transaction_block_height(txid).await; |             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 block_height = self.get_block_height().await; | ||||||
|             let confirmations = block_height - tx_block_height; |             tracing::debug!("block_height: {}", block_height.0); | ||||||
|  |             if let Some(confirmations) = block_height.0.checked_sub(tx_block_height.0) { | ||||||
|                 tracing::debug!("confirmations: {:?}", confirmations); |                 tracing::debug!("confirmations: {:?}", confirmations); | ||||||
|             if confirmations >= BlockHeight::new(execution_params.bitcoin_finality_confirmations) { |                 if confirmations >= execution_params.bitcoin_finality_confirmations { | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|             interval.tick().await; |             interval.tick().await; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 rishflab
						rishflab