global: snapshot

This commit is contained in:
nym21
2025-04-27 16:29:21 +02:00
parent 1e38c21f8e
commit 9ae0a57f22
22 changed files with 1643 additions and 555 deletions

View File

@@ -5,7 +5,7 @@ use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use crate::{CheckedSub, Error};
#[derive(
Debug,
@@ -132,6 +132,11 @@ impl Add<usize> for EmptyOutputIndex {
Self(*self + rhs)
}
}
impl CheckedSub<EmptyOutputIndex> for EmptyOutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -172,6 +177,11 @@ impl Add<usize> for P2MSIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2MSIndex> for P2MSIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -212,6 +222,11 @@ impl Add<usize> for P2AIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2AIndex> for P2AIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -252,6 +267,11 @@ impl Add<usize> for OpReturnIndex {
Self(*self + rhs)
}
}
impl CheckedSub<OpReturnIndex> for OpReturnIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -292,6 +312,11 @@ impl Add<usize> for UnknownOutputIndex {
Self(*self + rhs)
}
}
impl CheckedSub<UnknownOutputIndex> for UnknownOutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -332,6 +357,11 @@ impl Add<usize> for P2PK33Index {
Self(*self + rhs)
}
}
impl CheckedSub<P2PK33Index> for P2PK33Index {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -372,6 +402,11 @@ impl Add<usize> for P2PK65Index {
Self(*self + rhs)
}
}
impl CheckedSub<P2PK65Index> for P2PK65Index {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -412,6 +447,11 @@ impl Add<usize> for P2PKHIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2PKHIndex> for P2PKHIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -452,6 +492,11 @@ impl Add<usize> for P2SHIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2SHIndex> for P2SHIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -492,6 +537,11 @@ impl Add<usize> for P2TRIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2TRIndex> for P2TRIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -532,6 +582,11 @@ impl Add<usize> for P2WPKHIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2WPKHIndex> for P2WPKHIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
#[derive(
Debug,
@@ -572,3 +627,8 @@ impl Add<usize> for P2WSHIndex {
Self(*self + rhs)
}
}
impl CheckedSub<P2WSHIndex> for P2WSHIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}

View File

@@ -6,6 +6,11 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{
EmptyOutputIndex, OpReturnIndex, P2AIndex, P2MSIndex, P2PK33Index, P2PK65Index, P2PKHIndex,
P2SHIndex, P2TRIndex, P2WPKHIndex, P2WSHIndex, UnknownOutputIndex,
};
#[derive(
Debug,
Deref,
@@ -86,3 +91,75 @@ impl From<StoredU32> for usize {
value.0 as usize
}
}
impl From<P2PK65Index> for StoredU32 {
fn from(value: P2PK65Index) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PK33Index> for StoredU32 {
fn from(value: P2PK33Index) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PKHIndex> for StoredU32 {
fn from(value: P2PKHIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<OpReturnIndex> for StoredU32 {
fn from(value: OpReturnIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2MSIndex> for StoredU32 {
fn from(value: P2MSIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2SHIndex> for StoredU32 {
fn from(value: P2SHIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WSHIndex> for StoredU32 {
fn from(value: P2WSHIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WPKHIndex> for StoredU32 {
fn from(value: P2WPKHIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2TRIndex> for StoredU32 {
fn from(value: P2TRIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2AIndex> for StoredU32 {
fn from(value: P2AIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<UnknownOutputIndex> for StoredU32 {
fn from(value: UnknownOutputIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<EmptyOutputIndex> for StoredU32 {
fn from(value: EmptyOutputIndex) -> Self {
Self::from(usize::from(value))
}
}