mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-07-01 00:51:23 +00:00
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use anyhow::Context;
|
|
use bdk::electrum_client::HeaderNotification;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::convert::{TryFrom, TryInto};
|
|
use std::ops::Add;
|
|
|
|
/// Represent a block height, or block number, expressed in absolute block
|
|
/// count. E.g. The transaction was included in block #655123, 655123 block
|
|
/// after the genesis block.
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
#[serde(transparent)]
|
|
pub struct BlockHeight(u32);
|
|
|
|
impl From<BlockHeight> for u32 {
|
|
fn from(height: BlockHeight) -> Self {
|
|
height.0
|
|
}
|
|
}
|
|
|
|
impl TryFrom<HeaderNotification> for BlockHeight {
|
|
type Error = anyhow::Error;
|
|
|
|
fn try_from(value: HeaderNotification) -> Result<Self, Self::Error> {
|
|
Ok(Self(
|
|
value
|
|
.height
|
|
.try_into()
|
|
.context("Failed to fit usize into u32")?,
|
|
))
|
|
}
|
|
}
|
|
|
|
impl Add<u32> for BlockHeight {
|
|
type Output = BlockHeight;
|
|
fn add(self, rhs: u32) -> Self::Output {
|
|
BlockHeight(self.0 + rhs)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub enum ExpiredTimelocks {
|
|
None,
|
|
Cancel,
|
|
Punish,
|
|
}
|