global: utxos part 4

This commit is contained in:
nym21
2025-05-19 17:53:09 +02:00
parent 411c5e4c4d
commit 5893376279
36 changed files with 1502 additions and 391 deletions

View File

@@ -32,6 +32,46 @@ pub enum OutputType {
Unknown = 255,
}
impl OutputType {
pub fn is_spendable(&self) -> bool {
match self {
Self::P2PK65 => true,
Self::P2PK33 => true,
Self::P2PKH => true,
Self::P2MS => true,
Self::P2SH => true,
Self::OpReturn => false,
Self::P2WPKH => true,
Self::P2WSH => true,
Self::P2TR => true,
Self::P2A => true,
Self::Empty => false,
Self::Unknown => false,
}
}
pub fn is_unspendable(&self) -> bool {
!self.is_spendable()
}
pub fn as_vec() -> Vec<Self> {
vec![
Self::P2PK65,
Self::P2PK33,
Self::P2PKH,
Self::P2MS,
Self::P2SH,
Self::OpReturn,
Self::P2WPKH,
Self::P2WSH,
Self::P2TR,
Self::P2A,
Self::Empty,
Self::Unknown,
]
}
}
impl From<&ScriptBuf> for OutputType {
fn from(script: &ScriptBuf) -> Self {
if script.is_p2pk() {

View File

@@ -15,6 +15,7 @@ use super::{
Debug,
Deref,
Clone,
Default,
Copy,
PartialEq,
Eq,

View File

@@ -1,4 +1,7 @@
use std::ops::{Add, Div};
use std::{
cmp::Ordering,
ops::{Add, Div},
};
use derive_deref::Deref;
use jiff::{civil::date, tz::TimeZone};
@@ -26,6 +29,8 @@ use super::Date;
)]
pub struct Timestamp(u32);
const ONE_DAY_IN_SEC: i64 = 24 * 60 * 60;
impl Timestamp {
pub const ZERO: Self = Self(0);
@@ -39,6 +44,19 @@ impl Timestamp {
let d = date(d.year(), d.month(), d.day()).at(d.hour(), d.minute(), 0, 0);
Self::from(d.to_zoned(TimeZone::UTC).unwrap().timestamp())
}
pub fn difference_in_days_between(earlier: Self, later: Self) -> usize {
match later.cmp(&earlier) {
Ordering::Less => panic!("Shouldn't be used with inverted"),
Ordering::Equal => 0,
Ordering::Greater => {
(jiff::Timestamp::from(earlier)
.duration_until(jiff::Timestamp::from(later))
.as_secs()
/ ONE_DAY_IN_SEC) as usize
}
}
}
}
impl From<u32> for Timestamp {