computer: init store

This commit is contained in:
nym21
2025-06-27 10:52:36 +02:00
parent cf92c60a01
commit e73daa6214
23 changed files with 1064 additions and 70 deletions

View File

@@ -1,6 +1,11 @@
use byteview::ByteView;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{Dollars, Sats};
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
#[repr(C, packed)]
pub struct AddressData {
pub sent: Sats,
pub received: Sats,
@@ -13,3 +18,19 @@ impl AddressData {
(u64::from(self.received) - u64::from(self.sent)).into()
}
}
impl From<ByteView> for AddressData {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<AddressData> for ByteView {
fn from(value: AddressData) -> Self {
Self::from(&value)
}
}
impl From<&AddressData> for ByteView {
fn from(value: &AddressData) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -1,8 +1,28 @@
use byteview::ByteView;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Sats;
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
pub struct EmptyAddressData {
pub transfered: Sats,
}
impl EmptyAddressData {}
impl From<ByteView> for EmptyAddressData {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<EmptyAddressData> for ByteView {
fn from(value: EmptyAddressData) -> Self {
Self::from(&value)
}
}
impl From<&EmptyAddressData> for ByteView {
fn from(value: &EmptyAddressData) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -22,14 +22,22 @@ mod opreturnindex;
mod outputindex;
mod outputtype;
mod p2aaddressindex;
mod p2aaddressindex_outputindex;
mod p2msoutputindex;
mod p2pk33addressindex;
mod p2pk33addressindex_outputindex;
mod p2pk65addressindex;
mod p2pk65addressindex_outputindex;
mod p2pkhaddressindex;
mod p2pkhaddressindex_outputindex;
mod p2shaddressindex;
mod p2shaddressindex_outputindex;
mod p2traddressindex;
mod p2traddressindex_outputindex;
mod p2wpkhaddressindex;
mod p2wpkhaddressindex_outputindex;
mod p2wshaddressindex;
mod p2wshaddressindex_outputindex;
mod quarterindex;
mod rawlocktime;
mod sats;
@@ -78,14 +86,22 @@ pub use opreturnindex::*;
pub use outputindex::*;
pub use outputtype::*;
pub use p2aaddressindex::*;
pub use p2aaddressindex_outputindex::*;
pub use p2msoutputindex::*;
pub use p2pk33addressindex::*;
pub use p2pk33addressindex_outputindex::*;
pub use p2pk65addressindex::*;
pub use p2pk65addressindex_outputindex::*;
pub use p2pkhaddressindex::*;
pub use p2pkhaddressindex_outputindex::*;
pub use p2shaddressindex::*;
pub use p2shaddressindex_outputindex::*;
pub use p2traddressindex::*;
pub use p2traddressindex_outputindex::*;
pub use p2wpkhaddressindex::*;
pub use p2wpkhaddressindex_outputindex::*;
pub use p2wshaddressindex::*;
pub use p2wshaddressindex_outputindex::*;
pub use quarterindex::*;
pub use rawlocktime::*;
pub use sats::*;

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -29,6 +31,16 @@ impl From<TypeIndex> for P2AAddressIndex {
Self(value)
}
}
impl From<P2AAddressIndex> for u32 {
fn from(value: P2AAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2AAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<P2AAddressIndex> for usize {
fn from(value: P2AAddressIndex) -> Self {
Self::from(*value)
@@ -59,3 +71,19 @@ impl Printable for P2AAddressIndex {
&["aaddr", "p2aaddr", "p2aaddressindex"]
}
}
impl From<ByteView> for P2AAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2AAddressIndex> for ByteView {
fn from(value: P2AAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2AAddressIndex> for ByteView {
fn from(value: &P2AAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2AAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2AAddressIndexOutputindex {
addressindex: P2AAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2AAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2AAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2AAddressIndexOutputindex> for ByteView {
fn from(value: P2AAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2AAddressIndexOutputindex> for ByteView {
fn from(value: &P2AAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -29,6 +31,16 @@ impl From<TypeIndex> for P2PK33AddressIndex {
Self(value)
}
}
impl From<P2PK33AddressIndex> for u32 {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2PK33AddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<P2PK33AddressIndex> for usize {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(*value)
@@ -60,3 +72,19 @@ impl Printable for P2PK33AddressIndex {
&["pk33addr", "p2pk33addr", "p2pk33addressindex"]
}
}
impl From<ByteView> for P2PK33AddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2PK33AddressIndex> for ByteView {
fn from(value: P2PK33AddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2PK33AddressIndex> for ByteView {
fn from(value: &P2PK33AddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PK33AddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2PK33AddressIndexOutputindex {
addressindex: P2PK33AddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2PK33AddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2PK33AddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2PK33AddressIndexOutputindex> for ByteView {
fn from(value: P2PK33AddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2PK33AddressIndexOutputindex> for ByteView {
fn from(value: &P2PK33AddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -34,6 +36,16 @@ impl From<P2PK65AddressIndex> for usize {
Self::from(*value)
}
}
impl From<P2PK65AddressIndex> for u32 {
fn from(value: P2PK65AddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2PK65AddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<usize> for P2PK65AddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
@@ -59,3 +71,19 @@ impl Printable for P2PK65AddressIndex {
&["pk65addr", "p2pk65addr", "p2pk65addressindex"]
}
}
impl From<ByteView> for P2PK65AddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2PK65AddressIndex> for ByteView {
fn from(value: P2PK65AddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2PK65AddressIndex> for ByteView {
fn from(value: &P2PK65AddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PK65AddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2PK65AddressIndexOutputindex {
addressindex: P2PK65AddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2PK65AddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2PK65AddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2PK65AddressIndexOutputindex> for ByteView {
fn from(value: P2PK65AddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2PK65AddressIndexOutputindex> for ByteView {
fn from(value: &P2PK65AddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -34,6 +36,16 @@ impl From<P2PKHAddressIndex> for usize {
Self::from(*value)
}
}
impl From<P2PKHAddressIndex> for u32 {
fn from(value: P2PKHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2PKHAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<usize> for P2PKHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
@@ -60,3 +72,19 @@ impl Printable for P2PKHAddressIndex {
&["pkhaddr", "p2pkhaddr", "p2pkhaddressindex"]
}
}
impl From<ByteView> for P2PKHAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2PKHAddressIndex> for ByteView {
fn from(value: P2PKHAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2PKHAddressIndex> for ByteView {
fn from(value: &P2PKHAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PKHAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2PKHAddressIndexOutputindex {
addressindex: P2PKHAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2PKHAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2PKHAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2PKHAddressIndexOutputindex> for ByteView {
fn from(value: P2PKHAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2PKHAddressIndexOutputindex> for ByteView {
fn from(value: &P2PKHAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -29,6 +31,16 @@ impl From<TypeIndex> for P2SHAddressIndex {
Self(value)
}
}
impl From<P2SHAddressIndex> for u32 {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2SHAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<P2SHAddressIndex> for usize {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(*value)
@@ -60,3 +72,19 @@ impl Printable for P2SHAddressIndex {
&["shaddr", "p2shaddr", "p2shaddressindex"]
}
}
impl From<ByteView> for P2SHAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2SHAddressIndex> for ByteView {
fn from(value: P2SHAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2SHAddressIndex> for ByteView {
fn from(value: &P2SHAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2SHAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2SHAddressIndexOutputindex {
addressindex: P2SHAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2SHAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2SHAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2SHAddressIndexOutputindex> for ByteView {
fn from(value: P2SHAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2SHAddressIndexOutputindex> for ByteView {
fn from(value: &P2SHAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -29,6 +31,16 @@ impl From<TypeIndex> for P2TRAddressIndex {
Self(value)
}
}
impl From<P2TRAddressIndex> for u32 {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2TRAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<P2TRAddressIndex> for usize {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(*value)
@@ -60,3 +72,19 @@ impl Printable for P2TRAddressIndex {
&["traddr", "p2traddr", "p2traddressindex"]
}
}
impl From<ByteView> for P2TRAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2TRAddressIndex> for ByteView {
fn from(value: P2TRAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2TRAddressIndex> for ByteView {
fn from(value: &P2TRAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2TRAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2TRAddressIndexOutputindex {
addressindex: P2TRAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2TRAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2TRAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2TRAddressIndexOutputindex> for ByteView {
fn from(value: P2TRAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2TRAddressIndexOutputindex> for ByteView {
fn from(value: &P2TRAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -34,6 +36,16 @@ impl From<P2WPKHAddressIndex> for usize {
Self::from(*value)
}
}
impl From<P2WPKHAddressIndex> for u32 {
fn from(value: P2WPKHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2WPKHAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<usize> for P2WPKHAddressIndex {
fn from(value: usize) -> Self {
Self(TypeIndex::from(value))
@@ -60,3 +72,19 @@ impl Printable for P2WPKHAddressIndex {
&["wpkhaddr", "p2wpkhaddr", "p2wpkhaddressindex"]
}
}
impl From<ByteView> for P2WPKHAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2WPKHAddressIndex> for ByteView {
fn from(value: P2WPKHAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2WPKHAddressIndex> for ByteView {
fn from(value: &P2WPKHAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2WPKHAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2WPKHAddressIndexOutputindex {
addressindex: P2WPKHAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2WPKHAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2WPKHAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2WPKHAddressIndexOutputindex> for ByteView {
fn from(value: P2WPKHAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2WPKHAddressIndexOutputindex> for ByteView {
fn from(value: &P2WPKHAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -1,7 +1,9 @@
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, TypeIndex};
@@ -29,6 +31,16 @@ impl From<TypeIndex> for P2WSHAddressIndex {
Self(value)
}
}
impl From<P2WSHAddressIndex> for u32 {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(*value)
}
}
impl From<u32> for P2WSHAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<P2WSHAddressIndex> for usize {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(*value)
@@ -60,3 +72,19 @@ impl Printable for P2WSHAddressIndex {
&["wshaddr", "p2wshaddr", "p2wshaddressindex"]
}
}
impl From<ByteView> for P2WSHAddressIndex {
fn from(value: ByteView) -> Self {
Self::read_from_bytes(&value).unwrap()
}
}
impl From<P2WSHAddressIndex> for ByteView {
fn from(value: P2WSHAddressIndex) -> Self {
Self::from(&value)
}
}
impl From<&P2WSHAddressIndex> for ByteView {
fn from(value: &P2WSHAddressIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,40 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2WSHAddressIndex};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize)]
pub struct P2WSHAddressIndexOutputindex {
addressindex: P2WSHAddressIndex,
outputindex: OutputIndex,
}
impl From<ByteView> for P2WSHAddressIndexOutputindex {
fn from(value: ByteView) -> Self {
let addressindex =
P2WSHAddressIndex::from(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()));
let outputindex = OutputIndex::from(u64::from_be_bytes(copy_first_8bytes(&value).unwrap()));
Self {
addressindex,
outputindex,
}
}
}
impl From<P2WSHAddressIndexOutputindex> for ByteView {
fn from(value: P2WSHAddressIndexOutputindex) -> Self {
ByteView::from(&value)
}
}
impl From<&P2WSHAddressIndexOutputindex> for ByteView {
fn from(value: &P2WSHAddressIndexOutputindex) -> Self {
ByteView::from(
[
u32::from(value.addressindex).to_be_bytes().as_slice(),
u64::from(value.outputindex).to_be_bytes().as_slice(),
]
.concat(),
)
}
}

View File

@@ -45,6 +45,11 @@ impl From<u32> for TypeIndex {
Self(value)
}
}
impl From<TypeIndex> for u32 {
fn from(value: TypeIndex) -> Self {
value.0
}
}
impl From<u64> for TypeIndex {
fn from(value: u64) -> Self {