2021-03-11 07:16:00 +00:00
|
|
|
use anyhow::Context;
|
|
|
|
use bdk::electrum_client::HeaderNotification;
|
2021-01-21 02:43:25 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-03-11 07:16:00 +00:00
|
|
|
use std::convert::{TryFrom, TryInto};
|
2021-02-15 01:19:43 +00:00
|
|
|
use std::ops::Add;
|
2021-01-05 03:08:36 +00:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:00 +00:00
|
|
|
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")?,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 01:19:43 +00:00
|
|
|
impl Add<u32> for BlockHeight {
|
2021-01-05 03:08:36 +00:00
|
|
|
type Output = BlockHeight;
|
2021-02-15 01:19:43 +00:00
|
|
|
fn add(self, rhs: u32) -> Self::Output {
|
|
|
|
BlockHeight(self.0 + rhs)
|
2021-01-05 03:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-21 02:43:25 +00:00
|
|
|
|
2023-01-10 12:43:07 +00:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
2021-01-21 02:43:25 +00:00
|
|
|
pub enum ExpiredTimelocks {
|
|
|
|
None,
|
|
|
|
Cancel,
|
|
|
|
Punish,
|
|
|
|
}
|