computer: store part 3

This commit is contained in:
nym21
2025-06-29 17:39:31 +02:00
parent 663092b501
commit 6e996797b8
25 changed files with 605 additions and 225 deletions

View File

@@ -0,0 +1,38 @@
use std::mem;
use derive_deref::{Deref, DerefMut};
use crate::{OutputIndex, TypeIndex};
use super::GroupedByAddressType;
#[derive(Debug, Default, Deref, DerefMut)]
pub struct AddressIndexToTypeIndedToOutputIndex(
GroupedByAddressType<Vec<(TypeIndex, OutputIndex)>>,
);
impl AddressIndexToTypeIndedToOutputIndex {
pub fn merge(&mut self, mut other: Self) {
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
Self::merge_(&mut self.p2sh, &mut other.p2sh);
Self::merge_(&mut self.p2wpkh, &mut other.p2wpkh);
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
Self::merge_(&mut self.p2tr, &mut other.p2tr);
Self::merge_(&mut self.p2a, &mut other.p2a);
}
fn merge_(own: &mut Vec<(TypeIndex, OutputIndex)>, other: &mut Vec<(TypeIndex, OutputIndex)>) {
if own.len() >= other.len() {
own.append(other);
} else {
other.append(own);
mem::swap(own, other);
}
}
pub fn inner(self) -> GroupedByAddressType<Vec<(TypeIndex, OutputIndex)>> {
self.0
}
}

View File

@@ -17,17 +17,17 @@ pub struct GroupedByAddressType<T> {
}
impl<T> GroupedByAddressType<T> {
pub fn get_mut(&mut self, output_type: OutputType) -> &mut T {
match output_type {
OutputType::P2PK65 => &mut self.p2pk65,
OutputType::P2PK33 => &mut self.p2pk33,
OutputType::P2PKH => &mut self.p2pkh,
OutputType::P2SH => &mut self.p2sh,
OutputType::P2WPKH => &mut self.p2wpkh,
OutputType::P2WSH => &mut self.p2wsh,
OutputType::P2TR => &mut self.p2tr,
OutputType::P2A => &mut self.p2a,
_ => unreachable!(),
pub fn get_mut(&mut self, address_type: OutputType) -> Option<&mut T> {
match address_type {
OutputType::P2PK65 => Some(&mut self.p2pk65),
OutputType::P2PK33 => Some(&mut self.p2pk33),
OutputType::P2PKH => Some(&mut self.p2pkh),
OutputType::P2SH => Some(&mut self.p2sh),
OutputType::P2WPKH => Some(&mut self.p2wpkh),
OutputType::P2WSH => Some(&mut self.p2wsh),
OutputType::P2TR => Some(&mut self.p2tr),
OutputType::P2A => Some(&mut self.p2a),
_ => None,
}
}

View File

@@ -1,4 +1,5 @@
mod address;
mod addressindex_to_typeindex_to_outputindex;
mod by_address_type;
mod by_date_range;
mod by_epoch;
@@ -15,6 +16,7 @@ mod filter;
mod utxo;
pub use address::*;
pub use addressindex_to_typeindex_to_outputindex::*;
pub use by_address_type::*;
pub use by_date_range::*;
pub use by_epoch::*;

View File

@@ -162,7 +162,7 @@ impl fmt::Display for P2PKHBytes {
.push_opcode(opcodes::all::OP_CHECKSIG)
.into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}
@@ -192,7 +192,7 @@ impl fmt::Display for P2SHBytes {
.push_opcode(opcodes::all::OP_EQUAL)
.into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}
@@ -218,7 +218,7 @@ impl fmt::Display for P2WPKHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(0).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}
@@ -244,7 +244,7 @@ impl fmt::Display for P2WSHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(0).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}
@@ -270,7 +270,7 @@ impl fmt::Display for P2TRBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(1).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}
@@ -296,7 +296,7 @@ impl fmt::Display for P2ABytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(1).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
write!(f, "{address}")
}
}

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2AAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2AAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2AAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2AAddressIndex::from(value.0), value.1))
}
}
impl From<(P2AAddressIndex, OutputIndex)> for P2AAddressIndexOutputindex {
fn from(value: (P2AAddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PK33AddressIndex};
@@ -11,6 +11,12 @@ pub struct P2PK33AddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2PK33AddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2PK33AddressIndex::from(value.0), value.1))
}
}
impl From<(P2PK33AddressIndex, OutputIndex)> for P2PK33AddressIndexOutputindex {
fn from(value: (P2PK33AddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PK65AddressIndex};
@@ -11,6 +11,12 @@ pub struct P2PK65AddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2PK65AddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2PK65AddressIndex::from(value.0), value.1))
}
}
impl From<(P2PK65AddressIndex, OutputIndex)> for P2PK65AddressIndexOutputindex {
fn from(value: (P2PK65AddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2PKHAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2PKHAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2PKHAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2PKHAddressIndex::from(value.0), value.1))
}
}
impl From<(P2PKHAddressIndex, OutputIndex)> for P2PKHAddressIndexOutputindex {
fn from(value: (P2PKHAddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2SHAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2SHAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2SHAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2SHAddressIndex::from(value.0), value.1))
}
}
impl From<(P2SHAddressIndex, OutputIndex)> for P2SHAddressIndexOutputindex {
fn from(value: (P2SHAddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2TRAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2TRAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2TRAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2TRAddressIndex::from(value.0), value.1))
}
}
impl From<(P2TRAddressIndex, OutputIndex)> for P2TRAddressIndexOutputindex {
fn from(value: (P2TRAddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2WPKHAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2WPKHAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2WPKHAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2WPKHAddressIndex::from(value.0), value.1))
}
}
impl From<(P2WPKHAddressIndex, OutputIndex)> for P2WPKHAddressIndexOutputindex {
fn from(value: (P2WPKHAddressIndex, OutputIndex)) -> Self {
Self {

View File

@@ -1,7 +1,7 @@
use byteview::ByteView;
use serde::Serialize;
use crate::{copy_first_4bytes, copy_first_8bytes};
use crate::{TypeIndex, copy_first_4bytes, copy_first_8bytes};
use super::{OutputIndex, P2WSHAddressIndex};
@@ -11,6 +11,12 @@ pub struct P2WSHAddressIndexOutputindex {
outputindex: OutputIndex,
}
impl From<(TypeIndex, OutputIndex)> for P2WSHAddressIndexOutputindex {
fn from(value: (TypeIndex, OutputIndex)) -> Self {
Self::from((P2WSHAddressIndex::from(value.0), value.1))
}
}
impl From<(P2WSHAddressIndex, OutputIndex)> for P2WSHAddressIndexOutputindex {
fn from(value: (P2WSHAddressIndex, OutputIndex)) -> Self {
Self {