mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-11-16 15:58:17 +00:00
cuprated: add constants
& statics
modules (#301)
Some checks failed
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
Deny / audit (push) Has been cancelled
Doc / build (push) Has been cancelled
Audit / audit (push) Has been cancelled
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Doc / deploy (push) Has been cancelled
Some checks failed
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
Deny / audit (push) Has been cancelled
Doc / build (push) Has been cancelled
Audit / audit (push) Has been cancelled
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Doc / deploy (push) Has been cancelled
* add modules * docs * test * rename * tabs -> spaces
This commit is contained in:
parent
a072d44a0d
commit
12bbadd749
6 changed files with 125 additions and 3 deletions
29
Cargo.lock
generated
29
Cargo.lock
generated
|
@ -383,6 +383,26 @@ version = "0.7.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format"
|
||||||
|
version = "0.2.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b"
|
||||||
|
dependencies = [
|
||||||
|
"const_format_proc_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format_proc_macros"
|
||||||
|
version = "0.2.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
|
@ -913,7 +933,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cuprated"
|
name = "cuprated"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -924,6 +944,7 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"const_format",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"crypto-bigint",
|
"crypto-bigint",
|
||||||
"cuprate-address-book",
|
"cuprate-address-book",
|
||||||
|
@ -2899,6 +2920,12 @@ dependencies = [
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
|
@ -59,6 +59,7 @@ clap = { version = "4.5.17", default-features = false }
|
||||||
chrono = { version = "0.4.38", default-features = false }
|
chrono = { version = "0.4.38", default-features = false }
|
||||||
crypto-bigint = { version = "0.5.5", default-features = false }
|
crypto-bigint = { version = "0.5.5", default-features = false }
|
||||||
crossbeam = { version = "0.8.4", default-features = false }
|
crossbeam = { version = "0.8.4", default-features = false }
|
||||||
|
const_format = { version = "0.2.33", default-features = false }
|
||||||
curve25519-dalek = { version = "4.1.3", default-features = false }
|
curve25519-dalek = { version = "4.1.3", default-features = false }
|
||||||
dashmap = { version = "5.5.3", default-features = false }
|
dashmap = { version = "5.5.3", default-features = false }
|
||||||
dirs = { version = "5.0.1", default-features = false }
|
dirs = { version = "5.0.1", default-features = false }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cuprated"
|
name = "cuprated"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The Cuprate Monero Rust node."
|
description = "The Cuprate Monero Rust node."
|
||||||
license = "AGPL-3.0-only"
|
license = "AGPL-3.0-only"
|
||||||
|
@ -42,11 +42,12 @@ borsh = { workspace = true }
|
||||||
bytemuck = { workspace = true }
|
bytemuck = { workspace = true }
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
cfg-if = { workspace = true }
|
cfg-if = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true, features = ["cargo"] }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
crypto-bigint = { workspace = true }
|
crypto-bigint = { workspace = true }
|
||||||
crossbeam = { workspace = true }
|
crossbeam = { workspace = true }
|
||||||
curve25519-dalek = { workspace = true }
|
curve25519-dalek = { workspace = true }
|
||||||
|
const_format = { workspace = true }
|
||||||
dashmap = { workspace = true }
|
dashmap = { workspace = true }
|
||||||
dirs = { workspace = true }
|
dirs = { workspace = true }
|
||||||
futures = { workspace = true }
|
futures = { workspace = true }
|
||||||
|
|
34
binaries/cuprated/src/constants.rs
Normal file
34
binaries/cuprated/src/constants.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
//! General constants used throughout `cuprated`.
|
||||||
|
|
||||||
|
use const_format::formatcp;
|
||||||
|
|
||||||
|
/// `cuprated`'s semantic version (`MAJOR.MINOR.PATCH`) as string.
|
||||||
|
pub const VERSION: &str = clap::crate_version!();
|
||||||
|
|
||||||
|
/// [`VERSION`] + the build type.
|
||||||
|
///
|
||||||
|
/// If a debug build, the suffix is `-debug`, else it is `-release`.
|
||||||
|
pub const VERSION_BUILD: &str = if cfg!(debug_assertions) {
|
||||||
|
formatcp!("{VERSION}-debug")
|
||||||
|
} else {
|
||||||
|
formatcp!("{VERSION}-release")
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn version() {
|
||||||
|
assert_eq!(VERSION, "0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn version_build() {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
assert_eq!(VERSION_BUILD, "0.0.1-debug");
|
||||||
|
} else {
|
||||||
|
assert_eq!(VERSION_BUILD, "0.0.1-release");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,10 +13,16 @@
|
||||||
|
|
||||||
mod blockchain;
|
mod blockchain;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod constants;
|
||||||
mod p2p;
|
mod p2p;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
|
mod statics;
|
||||||
mod txpool;
|
mod txpool;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// Initialize global static `LazyLock` data.
|
||||||
|
statics::init_lazylock_statics();
|
||||||
|
|
||||||
|
// TODO: everything else.
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
53
binaries/cuprated/src/statics.rs
Normal file
53
binaries/cuprated/src/statics.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
//! Global `static`s used throughout `cuprated`.
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
sync::{atomic::AtomicU64, LazyLock},
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Define all the `static`s that should be always be initialized early on.
|
||||||
|
///
|
||||||
|
/// This wraps all `static`s inside a `LazyLock` and generates
|
||||||
|
/// a [`init_lazylock_statics`] function that must/should be
|
||||||
|
/// used by `main()` early on.
|
||||||
|
macro_rules! define_init_lazylock_statics {
|
||||||
|
($(
|
||||||
|
$( #[$attr:meta] )*
|
||||||
|
$name:ident: $t:ty = $init_fn:expr;
|
||||||
|
)*) => {
|
||||||
|
/// Initialize global static `LazyLock` data.
|
||||||
|
pub fn init_lazylock_statics() {
|
||||||
|
$(
|
||||||
|
LazyLock::force(&$name);
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
$(#[$attr])*
|
||||||
|
pub static $name: LazyLock<$t> = LazyLock::new(|| $init_fn);
|
||||||
|
)*
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
define_init_lazylock_statics! {
|
||||||
|
/// The start time of `cuprated`.
|
||||||
|
START_INSTANT: SystemTime = SystemTime::now();
|
||||||
|
|
||||||
|
/// Start time of `cuprated` as a UNIX timestamp.
|
||||||
|
START_INSTANT_UNIX: u64 = START_INSTANT
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.expect("Failed to set `cuprated` startup time.")
|
||||||
|
.as_secs();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// Sanity check for startup UNIX time.
|
||||||
|
#[test]
|
||||||
|
fn start_instant_unix() {
|
||||||
|
// Fri Sep 27 01:07:13 AM UTC 2024
|
||||||
|
assert!(*START_INSTANT_UNIX > 1727399233);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue