mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-29 21:59:27 -07:00
computer: init store
This commit is contained in:
@@ -1,89 +1,464 @@
|
||||
use std::path::Path;
|
||||
use std::{path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex,
|
||||
P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex,
|
||||
Version,
|
||||
AddressData, EmptyAddressData, P2AAddressIndex, P2AAddressIndexOutputindex, P2PK33AddressIndex,
|
||||
P2PK33AddressIndexOutputindex, P2PK65AddressIndex, P2PK65AddressIndexOutputindex,
|
||||
P2PKHAddressIndex, P2PKHAddressIndexOutputindex, P2SHAddressIndex, P2SHAddressIndexOutputindex,
|
||||
P2TRAddressIndex, P2TRAddressIndexOutputindex, P2WPKHAddressIndex,
|
||||
P2WPKHAddressIndexOutputindex, P2WSHAddressIndex, P2WSHAddressIndexOutputindex, Unit, Version,
|
||||
};
|
||||
use brk_store::Store;
|
||||
use fjall::TransactionalKeyspace;
|
||||
use jiff::Unit;
|
||||
|
||||
const _VERSION: Version = Version::ZERO;
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
pub p2aaddressindex_to_addressdata: Store<(P2AAddressIndex, OutputIndex), Unit>,
|
||||
pub p2aaddressindex_to_emptyaddressdata: Store<(P2AAddressIndex, OutputIndex), Unit>,
|
||||
pub p2aaddressindex_to_utxos_received: Store<(P2AAddressIndex, OutputIndex), Unit>,
|
||||
pub p2aaddressindex_to_utxos_sent: Store<P2AAddressIndex, Unit>,
|
||||
pub p2aaddressindex_to_addressdata: Store<P2AAddressIndex, AddressData>,
|
||||
pub p2aaddressindex_to_emptyaddressdata: Store<P2AAddressIndex, EmptyAddressData>,
|
||||
pub p2aaddressindex_to_utxos_received: Store<P2AAddressIndexOutputindex, Unit>,
|
||||
pub p2aaddressindex_to_utxos_sent: Store<P2AAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2msoutputindex_to_addressdata: Store<P2MSOutputIndex, Unit>,
|
||||
pub p2msoutputindex_to_emptyaddressdata: Store<P2MSOutputIndex, Unit>,
|
||||
pub p2msoutputindex_to_utxos_received: Store<P2MSOutputIndex, Unit>,
|
||||
pub p2msoutputindex_to_utxos_sent: Store<P2MSOutputIndex, Unit>,
|
||||
pub p2pk33addressindex_to_addressdata: Store<P2PK33AddressIndex, AddressData>,
|
||||
pub p2pk33addressindex_to_emptyaddressdata: Store<P2PK33AddressIndex, EmptyAddressData>,
|
||||
pub p2pk33addressindex_to_utxos_received: Store<P2PK33AddressIndexOutputindex, Unit>,
|
||||
pub p2pk33addressindex_to_utxos_sent: Store<P2PK33AddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pk33addressindex_to_addressdata: Store<P2PK33AddressIndex, Unit>,
|
||||
pub p2pk33addressindex_to_emptyaddressdata: Store<P2PK33AddressIndex, Unit>,
|
||||
pub p2pk33addressindex_to_utxos_received: Store<P2PK33AddressIndex, Unit>,
|
||||
pub p2pk33addressindex_to_utxos_sent: Store<P2PK33AddressIndex, Unit>,
|
||||
pub p2pk65addressindex_to_addressdata: Store<P2PK65AddressIndex, AddressData>,
|
||||
pub p2pk65addressindex_to_emptyaddressdata: Store<P2PK65AddressIndex, EmptyAddressData>,
|
||||
pub p2pk65addressindex_to_utxos_received: Store<P2PK65AddressIndexOutputindex, Unit>,
|
||||
pub p2pk65addressindex_to_utxos_sent: Store<P2PK65AddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pk65addressindex_to_addressdata: Store<P2PK65AddressIndex, Unit>,
|
||||
pub p2pk65addressindex_to_emptyaddressdata: Store<P2PK65AddressIndex, Unit>,
|
||||
pub p2pk65addressindex_to_utxos_received: Store<P2PK65AddressIndex, Unit>,
|
||||
pub p2pk65addressindex_to_utxos_sent: Store<P2PK65AddressIndex, Unit>,
|
||||
pub p2pkhaddressindex_to_addressdata: Store<P2PKHAddressIndex, AddressData>,
|
||||
pub p2pkhaddressindex_to_emptyaddressdata: Store<P2PKHAddressIndex, EmptyAddressData>,
|
||||
pub p2pkhaddressindex_to_utxos_received: Store<P2PKHAddressIndexOutputindex, Unit>,
|
||||
pub p2pkhaddressindex_to_utxos_sent: Store<P2PKHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pkhaddressindex_to_addressdata: Store<P2PKHAddressIndex, Unit>,
|
||||
pub p2pkhaddressindex_to_emptyaddressdata: Store<P2PKHAddressIndex, Unit>,
|
||||
pub p2pkhaddressindex_to_utxos_received: Store<P2PKHAddressIndex, Unit>,
|
||||
pub p2pkhaddressindex_to_utxos_sent: Store<P2PKHAddressIndex, Unit>,
|
||||
pub p2shaddressindex_to_addressdata: Store<P2SHAddressIndex, AddressData>,
|
||||
pub p2shaddressindex_to_emptyaddressdata: Store<P2SHAddressIndex, EmptyAddressData>,
|
||||
pub p2shaddressindex_to_utxos_received: Store<P2SHAddressIndexOutputindex, Unit>,
|
||||
pub p2shaddressindex_to_utxos_sent: Store<P2SHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2shaddressindex_to_addressdata: Store<P2SHAddressIndex, Unit>,
|
||||
pub p2shaddressindex_to_emptyaddressdata: Store<P2SHAddressIndex, Unit>,
|
||||
pub p2shaddressindex_to_utxos_received: Store<P2SHAddressIndex, Unit>,
|
||||
pub p2shaddressindex_to_utxos_sent: Store<P2SHAddressIndex, Unit>,
|
||||
pub p2traddressindex_to_addressdata: Store<P2TRAddressIndex, AddressData>,
|
||||
pub p2traddressindex_to_emptyaddressdata: Store<P2TRAddressIndex, EmptyAddressData>,
|
||||
pub p2traddressindex_to_utxos_received: Store<P2TRAddressIndexOutputindex, Unit>,
|
||||
pub p2traddressindex_to_utxos_sent: Store<P2TRAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2traddressindex_to_addressdata: Store<P2TRAddressIndex, Unit>,
|
||||
pub p2traddressindex_to_emptyaddressdata: Store<P2TRAddressIndex, Unit>,
|
||||
pub p2traddressindex_to_utxos_received: Store<P2TRAddressIndex, Unit>,
|
||||
pub p2traddressindex_to_utxos_sent: Store<P2TRAddressIndex, Unit>,
|
||||
pub p2wpkhaddressindex_to_addressdata: Store<P2WPKHAddressIndex, AddressData>,
|
||||
pub p2wpkhaddressindex_to_emptyaddressdata: Store<P2WPKHAddressIndex, EmptyAddressData>,
|
||||
pub p2wpkhaddressindex_to_utxos_received: Store<P2WPKHAddressIndexOutputindex, Unit>,
|
||||
pub p2wpkhaddressindex_to_utxos_sent: Store<P2WPKHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2wpkhaddressindex_to_addressdata: Store<P2WPKHAddressIndex, Unit>,
|
||||
pub p2wpkhaddressindex_to_emptyaddressdata: Store<P2WPKHAddressIndex, Unit>,
|
||||
pub p2wpkhaddressindex_to_utxos_received: Store<P2WPKHAddressIndex, Unit>,
|
||||
pub p2wpkhaddressindex_to_utxos_sent: Store<P2WPKHAddressIndex, Unit>,
|
||||
|
||||
pub p2wshaddressindex_to_addressdata: Store<P2WSHAddressIndex, Unit>,
|
||||
pub p2wshaddressindex_to_emptyaddressdata: Store<P2WSHAddressIndex, Unit>,
|
||||
pub p2wshaddressindex_to_utxos_received: Store<P2WSHAddressIndex, Unit>,
|
||||
pub p2wshaddressindex_to_utxos_sent: Store<P2WSHAddressIndex, Unit>,
|
||||
pub p2wshaddressindex_to_addressdata: Store<P2WSHAddressIndex, AddressData>,
|
||||
pub p2wshaddressindex_to_emptyaddressdata: Store<P2WSHAddressIndex, EmptyAddressData>,
|
||||
pub p2wshaddressindex_to_utxos_received: Store<P2WSHAddressIndexOutputindex, Unit>,
|
||||
pub p2wshaddressindex_to_utxos_sent: Store<P2WSHAddressIndexOutputindex, Unit>,
|
||||
}
|
||||
|
||||
impl Stores {
|
||||
pub fn import(_: &Path, _: Version, _: &TransactionalKeyspace) -> color_eyre::Result<Self> {
|
||||
// let address_to_utxos_received = Store::import(
|
||||
// keyspace.clone(),
|
||||
// path,
|
||||
// "address_to_utxos_received",
|
||||
// version + VERSION + Version::ZERO,
|
||||
// )?;
|
||||
// let address_to_utxos_spent = Store::import(
|
||||
// keyspace.clone(),
|
||||
// path,
|
||||
// "address_to_utxos_spent",
|
||||
// version + VERSION + Version::ZERO,
|
||||
// )?;
|
||||
pub fn import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
keyspace: &TransactionalKeyspace,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let (
|
||||
(
|
||||
p2aaddressindex_to_addressdata,
|
||||
p2aaddressindex_to_emptyaddressdata,
|
||||
p2aaddressindex_to_utxos_received,
|
||||
p2aaddressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2pk33addressindex_to_addressdata,
|
||||
p2pk33addressindex_to_emptyaddressdata,
|
||||
p2pk33addressindex_to_utxos_received,
|
||||
p2pk33addressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2pk65addressindex_to_addressdata,
|
||||
p2pk65addressindex_to_emptyaddressdata,
|
||||
p2pk65addressindex_to_utxos_received,
|
||||
p2pk65addressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2pkhaddressindex_to_addressdata,
|
||||
p2pkhaddressindex_to_emptyaddressdata,
|
||||
p2pkhaddressindex_to_utxos_received,
|
||||
p2pkhaddressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2shaddressindex_to_addressdata,
|
||||
p2shaddressindex_to_emptyaddressdata,
|
||||
p2shaddressindex_to_utxos_received,
|
||||
p2shaddressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2traddressindex_to_addressdata,
|
||||
p2traddressindex_to_emptyaddressdata,
|
||||
p2traddressindex_to_utxos_received,
|
||||
p2traddressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2wpkhaddressindex_to_addressdata,
|
||||
p2wpkhaddressindex_to_emptyaddressdata,
|
||||
p2wpkhaddressindex_to_utxos_received,
|
||||
p2wpkhaddressindex_to_utxos_sent,
|
||||
),
|
||||
(
|
||||
p2wshaddressindex_to_addressdata,
|
||||
p2wshaddressindex_to_emptyaddressdata,
|
||||
p2wshaddressindex_to_utxos_received,
|
||||
p2wshaddressindex_to_utxos_sent,
|
||||
),
|
||||
) = thread::scope(|scope| {
|
||||
let p2a = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
todo!();
|
||||
// Ok(Self {
|
||||
// p2aaddressindex_to_utxos_received: Store::import(
|
||||
// keyspace,
|
||||
// path,
|
||||
// name,
|
||||
// version,
|
||||
// bloom_filter_bits,
|
||||
// ), // address_to_utxos_received,
|
||||
// // address_to_utxos_spent,
|
||||
// })
|
||||
let p2pk33 = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2pk65 = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2pkh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2sh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2tr = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2wpkh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2wsh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_utxos_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_utxos_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
(
|
||||
p2a.join().unwrap(),
|
||||
p2pk33.join().unwrap(),
|
||||
p2pk65.join().unwrap(),
|
||||
p2pkh.join().unwrap(),
|
||||
p2sh.join().unwrap(),
|
||||
p2tr.join().unwrap(),
|
||||
p2wpkh.join().unwrap(),
|
||||
p2wsh.join().unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
p2aaddressindex_to_addressdata,
|
||||
p2aaddressindex_to_emptyaddressdata,
|
||||
p2aaddressindex_to_utxos_received,
|
||||
p2aaddressindex_to_utxos_sent,
|
||||
|
||||
p2pk33addressindex_to_addressdata,
|
||||
p2pk33addressindex_to_emptyaddressdata,
|
||||
p2pk33addressindex_to_utxos_received,
|
||||
p2pk33addressindex_to_utxos_sent,
|
||||
|
||||
p2pk65addressindex_to_addressdata,
|
||||
p2pk65addressindex_to_emptyaddressdata,
|
||||
p2pk65addressindex_to_utxos_received,
|
||||
p2pk65addressindex_to_utxos_sent,
|
||||
|
||||
p2pkhaddressindex_to_addressdata,
|
||||
p2pkhaddressindex_to_emptyaddressdata,
|
||||
p2pkhaddressindex_to_utxos_received,
|
||||
p2pkhaddressindex_to_utxos_sent,
|
||||
|
||||
p2shaddressindex_to_addressdata,
|
||||
p2shaddressindex_to_emptyaddressdata,
|
||||
p2shaddressindex_to_utxos_received,
|
||||
p2shaddressindex_to_utxos_sent,
|
||||
|
||||
p2traddressindex_to_addressdata,
|
||||
p2traddressindex_to_emptyaddressdata,
|
||||
p2traddressindex_to_utxos_received,
|
||||
p2traddressindex_to_utxos_sent,
|
||||
|
||||
p2wpkhaddressindex_to_addressdata,
|
||||
p2wpkhaddressindex_to_emptyaddressdata,
|
||||
p2wpkhaddressindex_to_utxos_received,
|
||||
p2wpkhaddressindex_to_utxos_sent,
|
||||
|
||||
p2wshaddressindex_to_addressdata,
|
||||
p2wshaddressindex_to_emptyaddressdata,
|
||||
p2wshaddressindex_to_utxos_received,
|
||||
p2wshaddressindex_to_utxos_sent,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
40
crates/brk_core/src/structs/p2aaddressindex_outputindex.rs
Normal file
40
crates/brk_core/src/structs/p2aaddressindex_outputindex.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
40
crates/brk_core/src/structs/p2pkhaddressindex_outputindex.rs
Normal file
40
crates/brk_core/src/structs/p2pkhaddressindex_outputindex.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
40
crates/brk_core/src/structs/p2shaddressindex_outputindex.rs
Normal file
40
crates/brk_core/src/structs/p2shaddressindex_outputindex.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
40
crates/brk_core/src/structs/p2traddressindex_outputindex.rs
Normal file
40
crates/brk_core/src/structs/p2traddressindex_outputindex.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
40
crates/brk_core/src/structs/p2wshaddressindex_outputindex.rs
Normal file
40
crates/brk_core/src/structs/p2wshaddressindex_outputindex.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
use crate::{Error, Result};
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn copy_first_4bytes(slice: &[u8]) -> Result<[u8; 4]> {
|
||||
let mut buf: [u8; 4] = [0; 4];
|
||||
let buf_len = buf.len();
|
||||
if slice.len() < buf_len {
|
||||
return Err(Error::String("Buffer is too small to convert to 8 bytes"));
|
||||
}
|
||||
slice.iter().take(buf_len).enumerate().for_each(|(i, r)| {
|
||||
buf[i] = *r;
|
||||
});
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn copy_first_8bytes(slice: &[u8]) -> Result<[u8; 8]> {
|
||||
let mut buf: [u8; 8] = [0; 8];
|
||||
|
||||
@@ -9,7 +9,7 @@ A Model Context Protocol (MCP) which gives LLMs access to all available tools in
|
||||
|
||||
## Usage
|
||||
|
||||
To connect to the MCP you only need the correct URL, no token or auth is needed.
|
||||
To connect to the MCP use any of the previous URL, no token or auth is needed.
|
||||
|
||||
This implementation has only been tested with Claude and the [MCP inspector](https://modelcontextprotocol.io/docs/tools/inspector).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user