parser: compress empty_address_data

This commit is contained in:
k
2024-10-09 00:33:14 +02:00
parent f5d427a04f
commit db60d4e453
4 changed files with 63 additions and 230 deletions

View File

@@ -79,11 +79,14 @@ impl AddressData {
}
pub fn from_empty(empty: &EmptyAddressData) -> Self {
let address_type = empty.address_type();
let transfered = empty.transfered();
Self {
address_type: empty.address_type,
address_type,
amount: Amount::ZERO,
sent: empty.transfered,
received: empty.transfered,
sent: transfered,
received: transfered,
realized_cap: Price::ZERO,
outputs_len: 0,
}

View File

@@ -19,3 +19,24 @@ pub enum AddressType {
P2WSH,
P2TR,
}
impl TryFrom<u64> for AddressType {
type Error = ();
fn try_from(u: u64) -> Result<Self, Self::Error> {
match u {
x if x == AddressType::Empty as u64 => Ok(AddressType::Empty),
x if x == AddressType::OpReturn as u64 => Ok(AddressType::OpReturn),
x if x == AddressType::PushOnly as u64 => Ok(AddressType::PushOnly),
x if x == AddressType::Unknown as u64 => Ok(AddressType::Unknown),
x if x == AddressType::MultiSig as u64 => Ok(AddressType::MultiSig),
x if x == AddressType::P2PK as u64 => Ok(AddressType::P2PK),
x if x == AddressType::P2PKH as u64 => Ok(AddressType::P2PKH),
x if x == AddressType::P2SH as u64 => Ok(AddressType::P2SH),
x if x == AddressType::P2WPKH as u64 => Ok(AddressType::P2WPKH),
x if x == AddressType::P2WSH as u64 => Ok(AddressType::P2WSH),
x if x == AddressType::P2TR as u64 => Ok(AddressType::P2TR),
_ => Err(()),
}
}
}

View File

@@ -4,12 +4,13 @@ use sanakirja::{direct_repr, Storable, UnsizedStorable};
use super::{AddressData, AddressType, Amount};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Allocative)]
pub struct EmptyAddressData {
pub address_type: AddressType,
pub transfered: Amount,
}
pub struct EmptyAddressData(u64);
direct_repr!(EmptyAddressData);
const SHIFT: u64 = 5;
const AND: u64 = (1 << SHIFT) - 1;
const MAX: u64 = (u64::MAX - 1) >> 5;
impl EmptyAddressData {
pub fn from_non_empty(non_empty: &AddressData) -> Self {
if non_empty.sent != non_empty.received {
@@ -17,9 +18,20 @@ impl EmptyAddressData {
panic!("Trying to convert not empty wallet to empty !");
}
Self {
address_type: non_empty.address_type,
transfered: non_empty.sent,
let transfered = non_empty.sent.to_sat();
if transfered >= MAX {
panic!("Too large !");
}
Self((transfered << SHIFT) + (non_empty.address_type as u64))
}
pub fn address_type(&self) -> AddressType {
(self.0 & AND).try_into().unwrap()
}
pub fn transfered(&self) -> Amount {
Amount::from_sat(self.0 >> SHIFT)
}
}

237
server/Cargo.lock generated
View File

@@ -761,16 +761,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-skiplist"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df29de440c58ca2cc6e587ec3d22347551a32435fbde9d2bff64e78a9ffa151b"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.20"
@@ -882,12 +872,6 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "double-ended-peekable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0d05e1c0dbad51b52c38bda7adceef61b9efc2baf04acfe8726a8c4630a6f57"
[[package]]
name = "either"
version = "1.13.0"
@@ -903,18 +887,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "enum_dispatch"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd"
dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.79",
]
[[package]]
name = "env_filter"
version = "0.1.2"
@@ -972,22 +944,6 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "fjall"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5eec62a0bf98435c5d6ba4563e4169880496ea044c45f343c4685269ab0866c"
dependencies = [
"byteorder",
"dashmap 6.1.0",
"log",
"lsm-tree",
"path-absolutize",
"std-semaphore",
"tempfile",
"xxhash-rust",
]
[[package]]
name = "flate2"
version = "1.0.34"
@@ -1132,12 +1088,6 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "guardian"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "493913a18c0d7bebb75127a26a432162c59edbe06f6cf712001e3e769345e8b5"
[[package]]
name = "h2"
version = "0.4.6"
@@ -1225,7 +1175,7 @@ dependencies = [
"new_debug_unreachable",
"once_cell",
"phf",
"rustc-hash 1.1.0",
"rustc-hash",
"triomphe",
]
@@ -1568,39 +1518,6 @@ dependencies = [
"hashbrown 0.13.2",
]
[[package]]
name = "lsm-tree"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5383b689c4a4968d43d8237627de5e180dafbce158f1a110bf1410ce9c4c9a5"
dependencies = [
"byteorder",
"crossbeam-skiplist",
"double-ended-peekable",
"enum_dispatch",
"guardian",
"log",
"lz4_flex",
"path-absolutize",
"quick_cache",
"rustc-hash 2.0.0",
"self_cell",
"smallvec",
"tempfile",
"value-log",
"varint-rs",
"xxhash-rust",
]
[[package]]
name = "lz4_flex"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5"
dependencies = [
"twox-hash",
]
[[package]]
name = "matchit"
version = "0.7.3"
@@ -1663,12 +1580,6 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "min-max-heap"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2687e6cf9c00f48e9284cf9fd15f2ef341d03cc7743abf9df4c5f07fdee50b18"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@@ -1966,14 +1877,12 @@ dependencies = [
"color-eyre",
"ctrlc",
"derive_deref",
"fjall",
"inferno",
"itertools",
"memory-stats",
"ordered-float",
"rayon",
"reqwest",
"rmp-serde",
"sanakirja",
"serde",
"serde_json",
@@ -1981,21 +1890,6 @@ dependencies = [
"zstd",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "path-absolutize"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4af381fe79fa195b4909485d99f73a80792331df0625188e707854f0b3383f5"
dependencies = [
"path-dedot",
]
[[package]]
name = "path-clean"
version = "0.1.0"
@@ -2008,15 +1902,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef"
[[package]]
name = "path-dedot"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07ba0ad7e047712414213ff67533e6dd477af0a4e1d14fb52343e53d30ea9397"
dependencies = [
"once_cell",
]
[[package]]
name = "pathdiff"
version = "0.2.1"
@@ -2173,16 +2058,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "quick_cache"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d7c94f8935a9df96bb6380e8592c70edf497a643f94bd23b2f76b399385dbf4"
dependencies = [
"equivalent",
"hashbrown 0.14.5",
]
[[package]]
name = "quote"
version = "1.0.37"
@@ -2369,28 +2244,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "rmp"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4"
dependencies = [
"byteorder",
"num-traits",
"paste",
]
[[package]]
name = "rmp-serde"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db"
dependencies = [
"byteorder",
"rmp",
"serde",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
@@ -2403,12 +2256,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "rustc_version"
version = "0.2.3"
@@ -2574,12 +2421,6 @@ dependencies = [
"libc",
]
[[package]]
name = "self_cell"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a"
[[package]]
name = "semver"
version = "0.9.0"
@@ -2791,7 +2632,7 @@ dependencies = [
"data-encoding",
"debugid",
"if_chain",
"rustc-hash 1.1.0",
"rustc-hash",
"rustc_version",
"serde",
"serde_json",
@@ -2851,12 +2692,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "std-semaphore"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ae9eec00137a8eed469fb4148acd9fc6ac8c3f9b110f52cd34698c8b5bfa0e"
[[package]]
name = "str_stack"
version = "0.1.0"
@@ -2904,7 +2739,7 @@ dependencies = [
"parking_lot 0.12.3",
"pathdiff",
"regex",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"serde_json",
"sourcemap",
@@ -2946,7 +2781,7 @@ dependencies = [
"bumpalo",
"hashbrown 0.14.5",
"ptr_meta",
"rustc-hash 1.1.0",
"rustc-hash",
"triomphe",
]
@@ -2958,7 +2793,7 @@ checksum = "b25ff0f3fd48ab1a95d86fd0505fdd1ac904f84d0350dc8222bbc824e9d4fdf6"
dependencies = [
"hstr",
"once_cell",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
]
@@ -2992,7 +2827,7 @@ dependencies = [
"num-bigint",
"once_cell",
"parking_lot 0.12.3",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"siphasher",
"sourcemap",
@@ -3015,7 +2850,7 @@ dependencies = [
"base64 0.21.7",
"once_cell",
"pathdiff",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"serde_json",
"sourcemap",
@@ -3147,7 +2982,7 @@ dependencies = [
"arrayvec",
"indexmap",
"is-macro",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"serde_derive",
"smallvec",
@@ -3374,7 +3209,7 @@ dependencies = [
"phf",
"radix_fmt",
"regex",
"rustc-hash 1.1.0",
"rustc-hash",
"ryu-js",
"serde",
"serde_json",
@@ -3427,7 +3262,7 @@ dependencies = [
"indexmap",
"once_cell",
"preset_env_base",
"rustc-hash 1.1.0",
"rustc-hash",
"semver 1.0.23",
"serde",
"serde_json",
@@ -3472,7 +3307,7 @@ dependencies = [
"indexmap",
"once_cell",
"phf",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"smallvec",
"swc_atoms",
@@ -3583,7 +3418,7 @@ dependencies = [
"indexmap",
"once_cell",
"petgraph",
"rustc-hash 1.1.0",
"rustc-hash",
"serde_json",
"swc_atoms",
"swc_common",
@@ -3604,7 +3439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718f1e24dd96cfb0b7ba8f8a4e61c98338cdac7a3f5f9f4a83951d776ac398bf"
dependencies = [
"either",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"smallvec",
"swc_atoms",
@@ -3666,7 +3501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55a1d8b627b6adc706ccd2a4a30a5413e9df91a9cff6569cb9d3b9f41c1bc8de"
dependencies = [
"indexmap",
"rustc-hash 1.1.0",
"rustc-hash",
"swc_atoms",
"swc_common",
"swc_ecma_ast",
@@ -3685,7 +3520,7 @@ dependencies = [
"indexmap",
"num_cpus",
"once_cell",
"rustc-hash 1.1.0",
"rustc-hash",
"ryu-js",
"swc_atoms",
"swc_common",
@@ -3742,7 +3577,7 @@ checksum = "3daff8d4379be2a99ab4b146e4dd631ef2415965dc4f1d33e988a737c5ccc39a"
dependencies = [
"indexmap",
"petgraph",
"rustc-hash 1.1.0",
"rustc-hash",
"swc_common",
]
@@ -3796,7 +3631,7 @@ checksum = "eda3e80e1ad638d3575bc07745a914af13dcb02215098659f864731078271f2c"
dependencies = [
"better_scoped_tls",
"once_cell",
"rustc-hash 1.1.0",
"rustc-hash",
"serde",
"serde_json",
]
@@ -4170,16 +4005,6 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "twox-hash"
version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if",
"static_assertions",
]
[[package]]
name = "typed-arena"
version = "2.0.2"
@@ -4278,28 +4103,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "value-log"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "701aa53f40cdebc413fd3a1e6637c118e6a8d36e40736206f374e3722f0ddf53"
dependencies = [
"byteorder",
"log",
"min-max-heap",
"path-absolutize",
"quick_cache",
"rustc-hash 2.0.0",
"tempfile",
"xxhash-rust",
]
[[package]]
name = "varint-rs"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23"
[[package]]
name = "vcpkg"
version = "0.2.15"
@@ -4571,12 +4374,6 @@ dependencies = [
"tap",
]
[[package]]
name = "xxhash-rust"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984"
[[package]]
name = "zerocopy"
version = "0.7.35"