use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{Height, TxStatus, Txid, Vin};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct TxOutspend {
#[schemars(example = true)]
pub spent: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub txid: Option<Txid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vin: Option<Vin>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<TxStatus>,
}
impl TxOutspend {
pub const UNSPENT: Self = Self {
spent: false,
txid: None,
vin: None,
status: None,
};
pub fn is_deeply_spent(&self, current_height: Height) -> bool {
self.spent
&& self
.status
.as_ref()
.and_then(|s| s.block_height)
.is_some_and(|h| (*current_height).saturating_sub(*h) > 6)
}
}