Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lazy_static with once_cell #418

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
# Macros
lazy_static = { version = "1", default-features = false }
once_cell = { version = "1", default-features = false }
serde = { version = "1", default-features = false, features = ["std", "derive"] }

# Encoders
Expand Down
11 changes: 5 additions & 6 deletions message-queue/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ mod binaries {
#[allow(clippy::type_complexity)]
mod clippy {
use super::*;
lazy_static::lazy_static! {
pub(crate) static ref KEYS: Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>> =
Arc::new(RwLock::new(HashMap::new()));
pub(crate) static ref QUEUES: Arc<RwLock<HashMap<(Service, Service), RwLock<Queue<Db>>>>> =
Arc::new(RwLock::new(HashMap::new()));
}
use once_cell::sync::Lazy;
pub(crate) static KEYS: Lazy<Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>>> =
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
pub(crate) static QUEUES: Lazy<Arc<RwLock<HashMap<(Service, Service), RwLock<Queue<Db>>>>>> =
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
}
pub(crate) use self::clippy::*;

Expand Down
2 changes: 1 addition & 1 deletion processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
# Macros
async-trait = { version = "0.1", default-features = false }
lazy_static = { version = "1", default-features = false }
once_cell = { version = "1", default-features = false }
zeroize = { version = "1", default-features = false, features = ["std"] }
thiserror = { version = "1", default-features = false }
serde = { version = "1", default-features = false, features = ["std", "derive"] }
Expand Down
8 changes: 4 additions & 4 deletions processor/src/networks/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use crate::{
Payment,
};

use once_cell::sync::Lazy;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct OutputId(pub [u8; 36]);
impl Default for OutputId {
Expand Down Expand Up @@ -259,10 +261,8 @@ impl BlockTrait<Bitcoin> for Block {
}

const KEY_DST: &[u8] = b"Serai Bitcoin Output Offset";
lazy_static::lazy_static! {
static ref BRANCH_OFFSET: Scalar = Secp256k1::hash_to_F(KEY_DST, b"branch");
static ref CHANGE_OFFSET: Scalar = Secp256k1::hash_to_F(KEY_DST, b"change");
}
static BRANCH_OFFSET: Lazy<Scalar> = Lazy::new(|| Secp256k1::hash_to_F(KEY_DST, b"branch"));
static CHANGE_OFFSET: Lazy<Scalar> = Lazy::new(|| Secp256k1::hash_to_F(KEY_DST, b"change"));

// Always construct the full scanner in order to ensure there's no collisions
fn scanner(
Expand Down
4 changes: 1 addition & 3 deletions processor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ mod addresses;
pub(crate) use addresses::test_addresses;

// Effective Once
lazy_static::lazy_static! {
static ref INIT_LOGGER: () = env_logger::init();
}
static INIT_LOGGER: once_cell::sync::Lazy<()> = once_cell::sync::Lazy::new(env_logger::init);

#[macro_export]
macro_rules! test_network {
Expand Down