From 65664a29625c43c9d9f6750fc620299eab912948 Mon Sep 17 00:00:00 2001 From: Someone Else Date: Tue, 7 Feb 2023 22:45:30 +0100 Subject: [PATCH] repo be like --- Cargo.lock | 645 +++++++++++++++++++++++++++++ src/blockchain_db/mod.rs | 464 +++++++++++++++++++++ src/blocks/main.rs | 3 + src/cryptonote_basic/difficulty.rs | 1 + src/cryptonote_basic/mod.rs | 1 + src/cryptonote_protocol/enums.rs | 9 + src/cryptonote_protocol/mod.rs | 1 + src/main.rs | 8 + 8 files changed, 1132 insertions(+) create mode 100644 Cargo.lock create mode 100644 src/blockchain_db/mod.rs create mode 100644 src/blocks/main.rs create mode 100644 src/cryptonote_basic/difficulty.rs create mode 100644 src/cryptonote_basic/mod.rs create mode 100644 src/cryptonote_protocol/enums.rs create mode 100644 src/cryptonote_protocol/mod.rs create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..21e90a0d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,645 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "base58-monero" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d079cdf47e1ca75554200bb2f30bff5a5af16964cac4a566b18de9a5d48db2b" +dependencies = [ + "thiserror", +] + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bytemuck" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "cuprate" +version = "0.1.0" +dependencies = [ + "heed", + "monero", + "serde", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +dependencies = [ + "byteorder", + "digest", + "rand_core 0.5.1", + "serde", + "subtle", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "doxygen-rs" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff670ea0c9bbb8414e7efa6e23ebde2b8f520a7eef78273a3918cf1903e7505" +dependencies = [ + "phf", +] + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heed" +version = "0.20.0-alpha.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a4868f289367555634a24254fc552c728b765d11f4411a28fe4e5e7bfb3498" +dependencies = [ + "bytemuck", + "byteorder", + "heed-traits", + "heed-types", + "libc", + "lmdb-master-sys", + "once_cell", + "page_size", + "serde", + "synchronoise", + "url", +] + +[[package]] +name = "heed-traits" +version = "0.20.0-alpha.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00cf93d01e9a00a575c3698f594aebdf7d25c4e08a91b18ef81b804ee3c2acd5" + +[[package]] +name = "heed-types" +version = "0.20.0-alpha.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718efb3af4d2157d591ccdaf4d5028c47d482a591bc144aeb1982906e760ac92" +dependencies = [ + "bincode", + "bytemuck", + "byteorder", + "heed-traits", + "serde", + "serde_json", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "lmdb-master-sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629c123f5321b48fa4f8f4d3b868165b748d9ba79c7103fb58e3a94f736bcedd" +dependencies = [ + "cc", + "doxygen-rs", + "libc", + "pkg-config", +] + +[[package]] +name = "monero" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a8965a7510c5d9389e2086e406c292d6bbecac099eef195be55a2d2043448b9" +dependencies = [ + "base58-monero", + "curve25519-dalek", + "fixed-hash", + "hex", + "hex-literal", + "sealed", + "serde", + "serde-big-array", + "thiserror", + "tiny-keccak", +] + +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "page_size" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b7663cbd190cfd818d08efa8497f6cd383076688c49a391ef7c0d03cd12b561" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "phf" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92aacdc5f16768709a569e913f7451034034178b05bdc8acda226659a3dccc66" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.8", +] + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "sealed" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b5e421024b5e5edfbaa8e60ecf90bda9dbffc602dbb230e6028763f85f0c68c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-big-array" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3323f09a748af288c3dc2474ea6803ee81f118321775bffa3ac8f7e65c5e90e7" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "siphasher" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synchronoise" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dbc01390fc626ce8d1cffe3376ded2b72a11bb70e1c75f404a210e4daa4def2" +dependencies = [ + "crossbeam-queue", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-bidi" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "zeroize" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" diff --git a/src/blockchain_db/mod.rs b/src/blockchain_db/mod.rs new file mode 100644 index 00000000..496094f2 --- /dev/null +++ b/src/blockchain_db/mod.rs @@ -0,0 +1,464 @@ +use monero::{Hash, Transaction}; + +use crate::{cryptonote_protocol::enums::{RelayMethod}, cryptonote_basic::difficulty::difficulty_type, blockchain_db::{}}; +use std::error::Error; + +const MONERO_DEFAULT_LOG_CATEGORY: &str = "blockchain.db"; + +type Blobldata = Vec; +type TxOutIndex = (monero::cryptonote::hash::Hash, u64); + +pub(in super) enum RelayCategory { + broadcasted, //< Public txes received via block/fluff + relayable, //< Every tx not marked `relay_method::none` + legacy, //< `relay_category::broadcasted` + `relay_method::none` for rpc relay requests or historical reasons + all //< Everything in the db +} + +fn matches_category(relay_method: RelayMethod, relay_category: RelayCategory) -> bool { + todo!() +} + +/** + * @brief a struct containing output metadata + */ +pub struct output_data_t { + pubkey: monero::util::key::PublicKey, //< the output's public key (for spend verification) + unlock_time: u64, //< the output's unlock time (or height) + height: u64, //< the height of the block which created the output + commitment: monero::util::ringct::Key, //< the output's amount commitment (for spend verification) +} + +pub struct tx_data_t { + tx_id: u64, + unlock_time: u64, + block_id: u64, +} + +pub struct alt_block_data_t { + height: u64, + cumulative_weight: u64, + cumulative_difficulty_low: u64, + cumulative_difficulty_high: u64, + already_generated_coins: u64, +} + +pub struct txpool_tx_meta_t { + max_used_block_id: monero::cryptonote::hash::Hash, + last_failed_id: monero::cryptonote::hash::Hash, + weight: u64, + fee: u64, + max_used_block_height: u64, + last_failed_height: u64, + receive_time: u64, + last_relayed_time: u64, //< If received over i2p/tor, randomized forward time. If Dandelion++stem, randomized embargo time. Otherwise, last relayed timestamp + // 112 bytes + kept_by_block: u8, + relayed: u8, + do_not_relay: u8, + double_spend_seen: u8, + pruned: u8, + is_local: u8, + dandelionpp_stem: u8, + is_forwarding: u8, + bf_padding: u8, + + padding: [u8; 76], +} + +impl txpool_tx_meta_t { + fn set_relay_method(relay_method: RelayMethod) { + + } + + fn upgrade_relay_method(relay_method: RelayMethod) -> bool { + todo!() + } + + /// See `relay_category` description + fn matches(category: RelayCategory) -> bool { + return matches_category(todo!(), category) + } +} + + + + +/// TODO : String -> Vec they are cryptonote::blobdata + +#[derive(Debug)] +pub enum DB_FAILURES { + DB_ERROR, + DB_EXCEPTION, + BLOCK_DNE, + OUTPUT_DNE, + TX_DNE, + ARITHEMTIC_COUNT, +} + +pub(in super) trait BlockchainDB { + + // supposed to be private + + fn add_block() -> Result<(), DB_FAILURES>; + + fn remove_block() -> Result<(), DB_FAILURES>; + + fn add_transaction_data() -> Result; + + fn remove_transaction_data() -> Result<(),DB_FAILURES>; + + fn add_output() -> Result; + + fn add_tx_amount_output_indices() -> Result<(), DB_FAILURES>; + + fn add_spent_key() -> Result<(), DB_FAILURES>; + + fn remove_spent_key() -> Result<(),DB_FAILURES>; + + fn pop_block(); + + fn remove_transaction(); + + // uint64_t num_calls = 0; //!< a performance metric + // uint64_t time_blk_hash = 0; //!< a performance metric + // uint64_t time_add_block1 = 0; //!< a performance metric + // uint64_t time_add_transaction = 0; //!< a performance metric + + // supposed to be protected + + fn add_transaction(); + + // mutable uint64_t time_tx_exists = 0; //!< a performance metric + // uint64_t time_commit1 = 0; //!< a performance metric + // bool m_auto_remove_logs = true; //!< whether or not to automatically remove old logs + + // HardFork* m_hardfork; | protected: int *m_hardfork + + // supposed to be public + + // a constructor maybe + fn a_constructor_maybe() -> Self where Self: Sized; + + // a destructor maybe + fn well_i_really_dont_know_here(); + + fn init_options(); + + fn reset_stats(); + + fn show_stats(); + + fn open() -> Result<(),DB_FAILURES>; + + fn is_open() -> bool; + + fn close() -> Result<(),DB_FAILURES>; + + fn sync() -> Result<(),DB_FAILURES>; + + fn safesyncmode(onoff: &'static bool) -> Result<(),DB_FAILURES>; + + fn reset() -> Result<(),DB_FAILURES>; + + + + + // Primarly used by unit tests + fn get_filenames() -> Vec; + + fn get_db_name() -> String; + + // Reset the database (used only fore core tests, functional tests, etc) + fn remove_data_file(folder: &'static String) -> bool; // may not be static + + fn lock() -> Result; + + fn unlock() -> Result; + + + + fn batch_start(batch_num_blocks: u64, batch_bytes: u64) -> Result; + + fn batch_abort() -> Result<(),DB_FAILURES>; + + fn set_batch_transactions() -> Result<(),DB_FAILURES>; + + fn block_wtxn_start(); + fn block_wtxn_stop(); + fn block_wtxn_abort(); + + fn block_rtxn_start(); + fn block_rtxn_stop(); + fn block_rtxn_abort(); + + fn set_hard_fork(); // (HardFork* hf) + + fn add_block_public() -> Result; + + fn block_exists(h: monero::cryptonote::hash::Hash, height: u64) -> bool; + + fn get_block_blob(h: monero::cryptonote::hash::Hash) -> Result; // cryptonote::blobdata which is String underhood + + fn get_block(h: monero::cryptonote::hash::Hash) -> Result; // Result and block is int + + fn get_block_height(h: monero::cryptonote::hash::Hash) -> Result; + + fn get_block_header(h: monero::cryptonote::hash::Hash) -> Result; + + fn get_block_blob_from_height(height: u64) -> Result; + + fn get_block_from_height(height: u64) -> Result; + + fn get_block_timestamp(height: u64) -> Result; + + fn get_block_cumulative_rct_outputs(heights: Vec) -> Result,DB_FAILURES>; + + fn get_top_block_timestamp() -> Result; + + fn get_block_weight(weight: u64) -> Result; + + fn get_block_weights(start_height: u64, count: usize) -> Result,DB_FAILURES>; + + fn get_block_cumulative_difficulty(height: u64) -> Result; + + fn get_block_difficulty(height: u64) -> Result; + + fn correct_block_cumulative_difficulties(start_height: u64, new_cumulative_difficulties: Vec) -> Result<(),DB_FAILURES>; + + fn get_block_already_generated_coins(height: u64) -> Result; + + fn get_block_long_term_weight(height: u64) -> Result; + + fn get_long_term_block_weights(height: u64, count: usize) -> Result,DB_FAILURES>; // Shouldn't have DB_FAILURES + + fn get_block_hash_from_height(height: u64) -> Result; + + fn get_blocks_range(h1: u64, h2: u64) -> Result, DB_FAILURES>; + + fn get_hashes_range(h1: u64, h2: u64) -> Result,DB_FAILURES>; + + fn top_block_hash(block_height: u64) -> monero::cryptonote::hash::Hash; + + fn get_top_block() -> monero::Block; + + fn height() -> u64; + + // TODO idk never done a todo in my life + // Gonna use this as an excuse to split this hell one more time + //. a dot. because dot. is cool. + + fn pop_block_public(blk: &mut monero::Block, txs: Vec); + + // fn tx_exists(h: monero::cryptonote::hash::Hash, tx_id: Option) -> Result<(),()>; // Maybe error should be DB_FAILURES, not specified in docs + + // started renaming + + // issues. They want to use mut reference to edit the hash if it exist or not. | arg is return and return in Result + // Confirmed. These are indirect functions that take return their results through mutable references and report success with a boolean. + // Seems important to refactor this + + //fn tx_exist(h: monero::cryptonote::hash::Hash, tx: monero::Transaction) -> bool; + + fn tx_pruned_exist(h: monero::cryptonote::hash::Hash, tx: monero::Transaction) -> bool; + + //fn get_tx_blob(h: monero::cryptonote::hash::Hash, tx: String) -> bool; + + //fn get_pruned_tx_blob(h: monero::cryptonote::hash::Hash, tx: &mut String) -> bool; + + fn get_blocks_from(start_height: u64, min_block_count: usize, max_block_count: usize, max_tx_count: usize, max_size: usize, blocks: &mut Vec<((String, monero::cryptonote::hash::Hash), Vec<(monero::cryptonote::hash::Hash, String)>)>, pruned: bool, skip_coinbase: bool, get_miner_tx_hash: bool) -> bool; + + fn get_prunable_tx_hash(tx_hash: &monero::cryptonote::hash::Hash, prunable_hash: &mut monero::cryptonote::hash::Hash) -> bool; + + fn get_tx_count() -> u64; + + fn get_tx_list(hlist: &Vec) -> Vec; + + fn get_tx_block_height(h: monero::cryptonote::hash::Hash) -> Result; + + fn get_num_outputs(amount: &u64) -> u64; + + // Should be hidden but it isn't???? + fn get_indexing_base() -> u64 { return 0;} + + + + // FINNALY SOME BLOCKCHAIN_DB.H STUFF OUT THERE!!! + + fn get_output_key(amount: &u64, index: &u64, include_commitmemt: bool) -> Result; + + fn get_output_tx_and_index_from_global(index: &u64) -> TxOutIndex; + + fn get_output_tx_and_index(amount: &u64, index: &u64,) -> TxOutIndex; + + fn get_output_tx_and_index_void(amount: &u64, offsets: &Vec, indices: &Vec); + + fn get_output_key_void(amounts: &Vec, offsets: &Vec, outputs: &Vec, allow_partial: bool); // wtf is std::span|epee::span. I see no difference with a Rust vector, also allow_partial is be default false + + // LMAO WTF IS CAN_THREAD_BULK_INDICES + + fn get_tx_amount_output_indices(tx_id: u64, n_txes: usize) -> Vec>; + + fn has_key_image(img: &monero::blockdata::transaction::KeyImage) -> bool; + + fn add_txpool_tx(txid: &monero::cryptonote::hash::Hash, blob: &Vec, details: &txpool_tx_meta_t); + + fn update_txpool_tx(txid: &monero::Hash, details: &txpool_tx_meta_t); + + fn get_txpool_tx_count(tx_category: RelayCategory) -> u64; + + fn txpool_has_tx(txid: &monero::Hash, tx_category: &RelayCategory) -> bool; + + fn remove_txpool_tx(txid: &monero::Hash); + + fn get_txpool_tx_meta(txid: &monero::Hash, meta: &txpool_tx_meta_t) -> bool; + + fn get_txpool_tx_blob(txid: &monero::Hash, bd: &mut Vec, tx_category: RelayCategory) -> bool; + + fn get_txpool_tx_blob_but_blob(txid: &monero::Hash, tx_category: RelayCategory) -> Vec; + + fn txpool_tx_matches_category(tx_hash: &monero::Hash, category: RelayCategory) -> bool; + + fn prune_outputs(amount: u64); + + // Wtf no more arguments + + fn get_blockchain_pruning_seed() -> u32; + + fn update_pruning() -> bool; + + fn check_pruning() -> bool; + + fn get_max_block_size() -> u64; + + fn add_max_block_size() -> u64; + + + + fn add_alt_block(blkid: &monero::Hash, data: &alt_block_data_t, blob: &Vec); + + fn get_alt_block(blkid: &monero::Hash, data: *mut alt_block_data_t, blob: *mut Vec) -> bool; + + fn remove_alt_block(blkid: &monero::Hash); + + fn get_alt_block_count() -> u64; + + fn drop_alt_blocks(); + + fn for_all_txpool_txes(wat: fn(wat1: &monero::Hash, wat2: &txpool_tx_meta_t, wat3: &String) -> bool, include_blob: bool, category: RelayCategory) -> Result; + + fn for_all_keys_images(wat: fn(ki: &monero::blockdata::transaction::KeyImage) -> bool) -> Result; + + fn for_blocks_range(h1: &u64, h2: &u64, wat: fn(u: u64, h: &monero::Hash, blk: &monero::Block) -> bool) -> Result; // u: u64 should be mut u: u64 + + fn for_all_transactions(wat: fn(h: &monero::Hash, tx: &monero::Transaction) -> bool, pruned: bool) -> Result; + + fn for_all_outputs(); + + fn for_all_alt_blocks(); + + fn set_hard_fork_version(); + + fn get_hard_fork_version(); + + fn check_hard_fork_info(); + + fn drop_hard_fork_info(); + + fn get_output_histogram(); + + fn get_output_distribution(); + + fn is_read_only(); + + fn get_database_size(); + + fn fixup(); + + fn set_auto_remove_logs(); + + // some note to help me + + // get_*_tx group : get_tx, get_pruned_tx. they are duplicate + + // Confirmed part that don't need to be redfined or smthg + + // -----------------------------| Transactions |----------------------------------------- + + /// `tx_exists` check if a transaction exist with the given hash. + /// + /// Return `true` if the transaction exist, `false` otherwise. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters : + /// `h` is the given hash of transaction to check. + /// `tx_id` is an optional mutable reference to get the transaction id out of the found transaction. + fn tx_exists(h: &monero::Hash, tx_id: &mut Option) -> Result; + + /// `get_tx_unlock_time` fetch a transaction's unlock time/height + /// + /// Should return the unlock time/height in u64. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters: + /// `h`: is the given hash of the transaction to check. + fn get_tx_unlock_time(h: &Hash) -> Result; + + /// `get_tx` fetches the transaction with the given hash. + /// + /// Should return the transaction. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters: + /// `h`: is the given hash of transaction to fetch. + fn get_tx(h: &Hash) -> Result; + + /// `get_pruned_tx` fetches the transaction base with the given hash. + /// + /// Should return the transaction. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters: + /// `h`: is the given hash of transaction to fetch + fn get_pruned_tx(h: &Hash) -> Result; + + /// `get_tx_blob` fetches the transaction blob with the given hash. + /// + /// Should return the transaction blob. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters: + /// `h`: is the given hash of the transaction to fetch. + fn get_tx_blob(h: &Hash) -> Result; + + /// `get_pruned_tx_blob` fetches the pruned transaction blob with the given hash. + /// + /// Should return the transaction blob. In case of failure, a DB_FAILURES will be return. + /// + /// Parameters: + /// `h`: is the given hash of the transaction to fetch. + fn get_pruned_tx_blob(h: &Hash) -> Result; + + /// `get_prunable_tx_blob` fetches the prunable transaction blob with the given hash. + /// + /// Should return the transaction blob, In case of failure, a DB_FAILURES, will be return. + /// + /// Parameters: + /// `h`: is the given hash of the transaction to fetch. + fn get_prunable_tx_blob(h: &Hash) -> Result; + + /// `get_pruned_tx_blobs_from` fetches a number of pruned transaction blob from the given hash, in canonical blockchain order. + /// + /// Should return the pruned transactions stored from the one with the given hash. In case of failure, a DB_FAILURES will be return. + /// Precisly, an ARITHMETIC_COUNT error will be returned if the first transaction does not exist or their are fewer transactions than the count. + /// + /// Parameters: + /// `h`: is the given hash of the first transaction/ + /// `count`: is the number of transaction to fetch in canoncial blockchain order. + fn get_pruned_tx_blobs_from(h: &Hash, count: usize) -> Result,DB_FAILURES>; + + + + + // bool m_open; + // mutable epee::critical_section m_synchronization_lock; //!< A lock, currently for when BlockchainLMDB needs to resize the backing db file +} + + + + diff --git a/src/blocks/main.rs b/src/blocks/main.rs new file mode 100644 index 00000000..ff750b7f --- /dev/null +++ b/src/blocks/main.rs @@ -0,0 +1,3 @@ +pub mod blocks { + +} \ No newline at end of file diff --git a/src/cryptonote_basic/difficulty.rs b/src/cryptonote_basic/difficulty.rs new file mode 100644 index 00000000..4da29ffe --- /dev/null +++ b/src/cryptonote_basic/difficulty.rs @@ -0,0 +1 @@ +pub type difficulty_type = u128; \ No newline at end of file diff --git a/src/cryptonote_basic/mod.rs b/src/cryptonote_basic/mod.rs new file mode 100644 index 00000000..ad16d813 --- /dev/null +++ b/src/cryptonote_basic/mod.rs @@ -0,0 +1 @@ +pub mod difficulty; \ No newline at end of file diff --git a/src/cryptonote_protocol/enums.rs b/src/cryptonote_protocol/enums.rs new file mode 100644 index 00000000..3826eac8 --- /dev/null +++ b/src/cryptonote_protocol/enums.rs @@ -0,0 +1,9 @@ +/// Methods tracking how a tx was received and relayed +pub enum RelayMethod { + none, //< Received via RPC with `do_not_relay` set + local, //< Received via RPC; trying to send over i2p/tor, etc. + forward, //< Received over i2p/tor; timer delayed before ipv4/6 public broadcast + stem, //< Received/send over network using Dandelion++ stem + fluff, //< Received/sent over network using Dandelion++ fluff + block, //< Received in block, takes precedence over others +} \ No newline at end of file diff --git a/src/cryptonote_protocol/mod.rs b/src/cryptonote_protocol/mod.rs new file mode 100644 index 00000000..35b3598e --- /dev/null +++ b/src/cryptonote_protocol/mod.rs @@ -0,0 +1 @@ +pub mod enums; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 00000000..30fabe7c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,8 @@ +pub mod blockchain_db; +pub mod cryptonote_protocol; +pub mod cryptonote_basic; + + +fn main() { + println!("Hello, world!"); +}