global: rename some indexes

This commit is contained in:
nym21
2025-06-23 22:00:09 +02:00
parent 589bb02411
commit 0f3c267a48
32 changed files with 1517 additions and 12239 deletions

View File

@@ -0,0 +1,61 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct EmptyOutputIndex(TypeIndex);
impl From<TypeIndex> for EmptyOutputIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<EmptyOutputIndex> for usize {
fn from(value: EmptyOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for EmptyOutputIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for EmptyOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<EmptyOutputIndex> for EmptyOutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for EmptyOutputIndex {
fn to_string() -> &'static str {
"emptyoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["emptyout", "emptyoutputindex"]
}
}

View File

@@ -1,8 +1,5 @@
mod addressbytes;
mod addressbyteshash;
// mod addressindex;
// mod addressindexoutputindex;
// mod addresstype;
mod bitcoin;
mod blockhash;
mod blockhashprefix;
@@ -12,15 +9,25 @@ mod dateindex;
mod decadeindex;
mod difficultyepoch;
mod dollars;
mod emptyoutputindex;
mod feerate;
mod halvingepoch;
mod height;
mod inputindex;
mod monthindex;
mod ohlc;
mod opreturnindex;
mod outputindex;
mod outputtype;
mod outputtypeindex;
mod p2aaddressindex;
mod p2msoutputindex;
mod p2pk33addressindex;
mod p2pk65addressindex;
mod p2pkhaddressindex;
mod p2shaddressindex;
mod p2traddressindex;
mod p2wpkhaddressindex;
mod p2wshaddressindex;
mod quarterindex;
mod rawlocktime;
mod sats;
@@ -35,7 +42,9 @@ mod txid;
mod txidprefix;
mod txindex;
mod txversion;
mod typeindex;
mod unit;
mod unknownoutputindex;
mod version;
mod vin;
mod vout;
@@ -45,9 +54,6 @@ mod yearindex;
pub use addressbytes::*;
pub use addressbyteshash::*;
// pub use addressindex::*;
// pub use addressindexoutputindex::*;
// pub use addresstype::*;
pub use bitcoin::*;
pub use blockhash::*;
pub use blockhashprefix::*;
@@ -55,17 +61,28 @@ pub use cents::*;
pub use date::*;
pub use dateindex::*;
pub use decadeindex::*;
pub use decadeindex::*;
pub use difficultyepoch::*;
pub use dollars::*;
pub use emptyoutputindex::*;
pub use feerate::*;
pub use halvingepoch::*;
pub use height::*;
pub use inputindex::*;
pub use monthindex::*;
pub use ohlc::*;
pub use opreturnindex::*;
pub use outputindex::*;
pub use outputtype::*;
pub use outputtypeindex::*;
pub use p2aaddressindex::*;
pub use p2msoutputindex::*;
pub use p2pk33addressindex::*;
pub use p2pk65addressindex::*;
pub use p2pkhaddressindex::*;
pub use p2shaddressindex::*;
pub use p2traddressindex::*;
pub use p2wpkhaddressindex::*;
pub use p2wshaddressindex::*;
pub use quarterindex::*;
pub use rawlocktime::*;
pub use sats::*;
@@ -80,7 +97,9 @@ pub use txid::*;
pub use txidprefix::*;
pub use txindex::*;
pub use txversion::*;
pub use typeindex::*;
pub use unit::*;
pub use unknownoutputindex::*;
pub use version::*;
pub use vin::*;
pub use vout::*;

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct OpReturnIndex(TypeIndex);
impl From<TypeIndex> for OpReturnIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<OpReturnIndex> for usize {
fn from(value: OpReturnIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for OpReturnIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for OpReturnIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<OpReturnIndex> for OpReturnIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for OpReturnIndex {
fn to_string() -> &'static str {
"opreturnindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["op", "opreturn", "opreturnindex"]
}
}

View File

@@ -1,752 +0,0 @@
use std::ops::Add;
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct OutputTypeIndex(u32);
impl OutputTypeIndex {
pub fn increment(&mut self) {
self.0 += 1;
}
pub fn incremented(self) -> Self {
Self(self.0 + 1)
}
pub fn copy_then_increment(&mut self) -> Self {
let i = *self;
self.increment();
i
}
}
impl From<u32> for OutputTypeIndex {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<u64> for OutputTypeIndex {
fn from(value: u64) -> Self {
Self(value as u32)
}
}
impl From<OutputTypeIndex> for u64 {
fn from(value: OutputTypeIndex) -> Self {
value.0 as u64
}
}
impl From<usize> for OutputTypeIndex {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl From<OutputTypeIndex> for usize {
fn from(value: OutputTypeIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for OutputTypeIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u32)
}
}
impl Add<OutputTypeIndex> for OutputTypeIndex {
type Output = Self;
fn add(self, rhs: OutputTypeIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl From<ByteView> for OutputTypeIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<OutputTypeIndex> for ByteView {
fn from(value: OutputTypeIndex) -> Self {
Self::new(value.as_bytes())
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct EmptyOutputIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for EmptyOutputIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<EmptyOutputIndex> for usize {
fn from(value: EmptyOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for EmptyOutputIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for EmptyOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for EmptyOutputIndex {
fn to_string() -> &'static str {
"emptyoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["empty", "emptyoutputindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2MSIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2MSIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2MSIndex> for usize {
fn from(value: P2MSIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2MSIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2MSIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2MSIndex {
fn to_string() -> &'static str {
"p2msindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["ms", "p2ms", "p2msindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2AIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2AIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2AIndex> for usize {
fn from(value: P2AIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2AIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2AIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2AIndex {
fn to_string() -> &'static str {
"p2aindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["a", "p2a", "p2aindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct OpReturnIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for OpReturnIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<OpReturnIndex> for usize {
fn from(value: OpReturnIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for OpReturnIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for OpReturnIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for OpReturnIndex {
fn to_string() -> &'static str {
"opreturnindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["op", "opreturn", "opreturnindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct UnknownOutputIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for UnknownOutputIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<UnknownOutputIndex> for usize {
fn from(value: UnknownOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for UnknownOutputIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for UnknownOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for UnknownOutputIndex {
fn to_string() -> &'static str {
"unknownoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["unknown", "unknownoutputindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PK33Index(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PK33Index {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK33Index> for usize {
fn from(value: P2PK33Index) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK33Index {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PK33Index {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2PK33Index {
fn to_string() -> &'static str {
"p2pk33index"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk33", "p2pk33", "p2pk33index"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PK65Index(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PK65Index {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK65Index> for usize {
fn from(value: P2PK65Index) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK65Index {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PK65Index {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2PK65Index {
fn to_string() -> &'static str {
"p2pk65index"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk65", "p2pk65", "p2pk65index"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PKHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PKHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PKHIndex> for usize {
fn from(value: P2PKHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PKHIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PKHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2PKHIndex {
fn to_string() -> &'static str {
"p2pkhindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pkh", "p2pkh", "p2pkhindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2SHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2SHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2SHIndex> for usize {
fn from(value: P2SHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2SHIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2SHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2SHIndex {
fn to_string() -> &'static str {
"p2shindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["sh", "p2sh", "p2shindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2TRIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2TRIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2TRIndex> for usize {
fn from(value: P2TRIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2TRIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2TRIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2TRIndex {
fn to_string() -> &'static str {
"p2trindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["tr", "p2tr", "p2trindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2WPKHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2WPKHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2WPKHIndex> for usize {
fn from(value: P2WPKHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WPKHIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2WPKHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2WPKHIndex {
fn to_string() -> &'static str {
"p2wpkhindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wpkh", "p2wpkh", "p2wpkhindex"]
}
}
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2WSHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2WSHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2WSHIndex> for usize {
fn from(value: P2WSHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WSHIndex {
fn from(value: usize) -> Self {
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2WSHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
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)
}
}
impl Printable for P2WSHIndex {
fn to_string() -> &'static str {
"p2wshindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wsh", "p2wsh", "p2wshindex"]
}
}

View File

@@ -0,0 +1,61 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2AAddressIndex(TypeIndex);
impl From<TypeIndex> for P2AAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2AAddressIndex> for usize {
fn from(value: P2AAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2AAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2AAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2AAddressIndex> for P2AAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2AAddressIndex {
fn to_string() -> &'static str {
"p2aaddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["aaddr", "p2aaddr", "p2aaddressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2MSOutputIndex(TypeIndex);
impl From<TypeIndex> for P2MSOutputIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2MSOutputIndex> for usize {
fn from(value: P2MSOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2MSOutputIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2MSOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2MSOutputIndex> for P2MSOutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2MSOutputIndex {
fn to_string() -> &'static str {
"p2msoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["msout", "p2msout", "p2msoutputindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PK33AddressIndex(TypeIndex);
impl From<TypeIndex> for P2PK33AddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK33AddressIndex> for usize {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK33AddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2PK33AddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2PK33AddressIndex> for P2PK33AddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2PK33AddressIndex {
fn to_string() -> &'static str {
"p2pk33addressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk33addr", "p2pk33addr", "p2pk33addressindex"]
}
}

View File

@@ -0,0 +1,61 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PK65AddressIndex(TypeIndex);
impl From<TypeIndex> for P2PK65AddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK65AddressIndex> for usize {
fn from(value: P2PK65AddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK65AddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2PK65AddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2PK65AddressIndex> for P2PK65AddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2PK65AddressIndex {
fn to_string() -> &'static str {
"p2pk65addressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk65addr", "p2pk65addr", "p2pk65addressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2PKHAddressIndex(TypeIndex);
impl From<TypeIndex> for P2PKHAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2PKHAddressIndex> for usize {
fn from(value: P2PKHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PKHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2PKHAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2PKHAddressIndex> for P2PKHAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2PKHAddressIndex {
fn to_string() -> &'static str {
"p2pkhaddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pkhaddr", "p2pkhaddr", "p2pkhaddressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2SHAddressIndex(TypeIndex);
impl From<TypeIndex> for P2SHAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2SHAddressIndex> for usize {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2SHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2SHAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2SHAddressIndex> for P2SHAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2SHAddressIndex {
fn to_string() -> &'static str {
"p2shaddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["shaddr", "p2shaddr", "p2shaddressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2TRAddressIndex(TypeIndex);
impl From<TypeIndex> for P2TRAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2TRAddressIndex> for usize {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2TRAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2TRAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2TRAddressIndex> for P2TRAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2TRAddressIndex {
fn to_string() -> &'static str {
"p2traddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["traddr", "p2traddr", "p2traddressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2WPKHAddressIndex(TypeIndex);
impl From<TypeIndex> for P2WPKHAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2WPKHAddressIndex> for usize {
fn from(value: P2WPKHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WPKHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2WPKHAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2WPKHAddressIndex> for P2WPKHAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2WPKHAddressIndex {
fn to_string() -> &'static str {
"p2wpkhaddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wpkhaddr", "p2wpkhaddr", "p2wpkhaddressindex"]
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct P2WSHAddressIndex(TypeIndex);
impl From<TypeIndex> for P2WSHAddressIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<P2WSHAddressIndex> for usize {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WSHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for P2WSHAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<P2WSHAddressIndex> for P2WSHAddressIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for P2WSHAddressIndex {
fn to_string() -> &'static str {
"p2wshaddressindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wshaddr", "p2wshaddr", "p2wshaddressindex"]
}
}

View File

@@ -7,8 +7,9 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable};
use super::{
EmptyOutputIndex, OpReturnIndex, P2AIndex, P2MSIndex, P2PK33Index, P2PK65Index, P2PKHIndex,
P2SHIndex, P2TRIndex, P2WPKHIndex, P2WSHIndex, UnknownOutputIndex,
EmptyOutputIndex, OpReturnIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex,
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex,
P2WSHAddressIndex, UnknownOutputIndex,
};
#[derive(
@@ -93,20 +94,20 @@ impl From<StoredU32> for usize {
}
}
impl From<P2PK65Index> for StoredU32 {
fn from(value: P2PK65Index) -> Self {
impl From<P2PK65AddressIndex> for StoredU32 {
fn from(value: P2PK65AddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PK33Index> for StoredU32 {
fn from(value: P2PK33Index) -> Self {
impl From<P2PK33AddressIndex> for StoredU32 {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PKHIndex> for StoredU32 {
fn from(value: P2PKHIndex) -> Self {
impl From<P2PKHAddressIndex> for StoredU32 {
fn from(value: P2PKHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
@@ -117,38 +118,38 @@ impl From<OpReturnIndex> for StoredU32 {
}
}
impl From<P2MSIndex> for StoredU32 {
fn from(value: P2MSIndex) -> Self {
impl From<P2MSOutputIndex> for StoredU32 {
fn from(value: P2MSOutputIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2SHIndex> for StoredU32 {
fn from(value: P2SHIndex) -> Self {
impl From<P2SHAddressIndex> for StoredU32 {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WSHIndex> for StoredU32 {
fn from(value: P2WSHIndex) -> Self {
impl From<P2WSHAddressIndex> for StoredU32 {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WPKHIndex> for StoredU32 {
fn from(value: P2WPKHIndex) -> Self {
impl From<P2WPKHAddressIndex> for StoredU32 {
fn from(value: P2WPKHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2TRIndex> for StoredU32 {
fn from(value: P2TRIndex) -> Self {
impl From<P2TRAddressIndex> for StoredU32 {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2AIndex> for StoredU32 {
fn from(value: P2AIndex) -> Self {
impl From<P2AAddressIndex> for StoredU32 {
fn from(value: P2AAddressIndex) -> Self {
Self::from(usize::from(value))
}
}

View File

@@ -8,8 +8,9 @@ use crate::{CheckedSub, Printable};
use super::{
DateIndex, EmptyOutputIndex, Height, InputIndex, MonthIndex, OpReturnIndex, OutputIndex,
P2AIndex, P2MSIndex, P2PK33Index, P2PK65Index, P2PKHIndex, P2SHIndex, P2TRIndex, P2WPKHIndex,
P2WSHIndex, TxIndex, UnknownOutputIndex, YearIndex,
P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex,
P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex,
UnknownOutputIndex, YearIndex,
};
#[derive(
@@ -122,20 +123,20 @@ impl From<TxIndex> for StoredUsize {
}
}
impl From<P2PK65Index> for StoredUsize {
fn from(value: P2PK65Index) -> Self {
impl From<P2PK65AddressIndex> for StoredUsize {
fn from(value: P2PK65AddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PK33Index> for StoredUsize {
fn from(value: P2PK33Index) -> Self {
impl From<P2PK33AddressIndex> for StoredUsize {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2PKHIndex> for StoredUsize {
fn from(value: P2PKHIndex) -> Self {
impl From<P2PKHAddressIndex> for StoredUsize {
fn from(value: P2PKHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
@@ -146,38 +147,38 @@ impl From<OpReturnIndex> for StoredUsize {
}
}
impl From<P2MSIndex> for StoredUsize {
fn from(value: P2MSIndex) -> Self {
impl From<P2MSOutputIndex> for StoredUsize {
fn from(value: P2MSOutputIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2SHIndex> for StoredUsize {
fn from(value: P2SHIndex) -> Self {
impl From<P2SHAddressIndex> for StoredUsize {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WSHIndex> for StoredUsize {
fn from(value: P2WSHIndex) -> Self {
impl From<P2WSHAddressIndex> for StoredUsize {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2WPKHIndex> for StoredUsize {
fn from(value: P2WPKHIndex) -> Self {
impl From<P2WPKHAddressIndex> for StoredUsize {
fn from(value: P2WPKHAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2TRIndex> for StoredUsize {
fn from(value: P2TRIndex) -> Self {
impl From<P2TRAddressIndex> for StoredUsize {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(usize::from(value))
}
}
impl From<P2AIndex> for StoredUsize {
fn from(value: P2AIndex) -> Self {
impl From<P2AAddressIndex> for StoredUsize {
fn from(value: P2AAddressIndex) -> Self {
Self::from(usize::from(value))
}
}

View File

@@ -0,0 +1,99 @@
use std::ops::Add;
use byteview::ByteView;
use serde::Serialize;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct TypeIndex(u32);
impl TypeIndex {
pub fn increment(&mut self) {
self.0 += 1;
}
pub fn incremented(self) -> Self {
Self(self.0 + 1)
}
pub fn copy_then_increment(&mut self) -> Self {
let i = *self;
self.increment();
i
}
}
impl From<u32> for TypeIndex {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<u64> for TypeIndex {
fn from(value: u64) -> Self {
Self(value as u32)
}
}
impl From<TypeIndex> for u64 {
fn from(value: TypeIndex) -> Self {
value.0 as u64
}
}
impl From<usize> for TypeIndex {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl From<TypeIndex> for usize {
fn from(value: TypeIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for TypeIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u32)
}
}
impl Add<TypeIndex> for TypeIndex {
type Output = Self;
fn add(self, rhs: TypeIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl From<ByteView> for TypeIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<TypeIndex> for ByteView {
fn from(value: TypeIndex) -> Self {
Self::new(value.as_bytes())
}
}
impl CheckedSub<TypeIndex> for TypeIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}

View File

@@ -0,0 +1,62 @@
use std::ops::Add;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Deref,
DerefMut,
Default,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct UnknownOutputIndex(TypeIndex);
impl From<TypeIndex> for UnknownOutputIndex {
fn from(value: TypeIndex) -> Self {
Self(value)
}
}
impl From<UnknownOutputIndex> for usize {
fn from(value: UnknownOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for UnknownOutputIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
}
}
impl Add<usize> for UnknownOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
}
}
impl CheckedSub<UnknownOutputIndex> for UnknownOutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for UnknownOutputIndex {
fn to_string() -> &'static str {
"unknownoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["unknownout", "unknownoutputindex"]
}
}