fix: replace std::time with instant for wasm (#1060)

This commit is contained in:
gudnuf
2025-09-13 03:12:41 -07:00
committed by GitHub
parent aab85d2083
commit 2c9333449a
8 changed files with 11 additions and 18 deletions

View File

@@ -99,7 +99,7 @@ reqwest = { version = "0.12", default-features = false, features = [
"deflate",
]}
once_cell = "1.20.2"
instant = { version = "0.1", default-features = false }
web-time = "1.1.0"
rand = "0.9.1"
regex = "1"
home = "0.5.5"

View File

@@ -37,9 +37,9 @@ regex = { workspace = true, optional = true }
strum = { workspace = true, optional = true }
strum_macros = { workspace = true, optional = true }
zeroize = "1"
web-time.workspace = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { workspace = true, features = ["wasm-bindgen", "inaccurate"] }
uuid = { workspace = true, features = ["js"], optional = true }
[dev-dependencies]

View File

@@ -1,18 +1,10 @@
//! Cashu utils
#[cfg(not(target_arch = "wasm32"))]
use std::time::{SystemTime, UNIX_EPOCH};
use bitcoin::secp256k1::{rand, All, Secp256k1};
use once_cell::sync::Lazy;
pub mod hex;
#[cfg(target_arch = "wasm32")]
use instant::SystemTime;
#[cfg(target_arch = "wasm32")]
const UNIX_EPOCH: SystemTime = SystemTime::UNIX_EPOCH;
use bitcoin::secp256k1::{rand, All, Secp256k1};
use once_cell::sync::Lazy;
use web_time::{SystemTime, UNIX_EPOCH};
/// Secp256k1 global context
pub static SECP256K1: Lazy<Secp256k1<All>> = Lazy::new(|| {
@@ -46,7 +38,7 @@ pub enum CborError {
///
/// See <https://www.rfc-editor.org/rfc/rfc8949.html#name-diagnostic-notation>
pub fn serialize_to_cbor_diag<T: serde::Serialize>(data: &T) -> Result<String, CborError> {
let mut cbor_buffer = Vec::new();
let mut cbor_buffer = Vec::<u8>::new();
ciborium::ser::into_writer(data, &mut cbor_buffer)?;
let diag = cbor_diag::parse_bytes(&cbor_buffer)?;

View File

@@ -39,9 +39,9 @@ futures.workspace = true
anyhow.workspace = true
serde_json.workspace = true
serde_with.workspace = true
web-time.workspace = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { workspace = true, features = ["wasm-bindgen", "inaccurate"] }
uuid = { workspace = true, features = ["js"], optional = true }
[dev-dependencies]

View File

@@ -50,6 +50,7 @@ tokio-util.workspace = true
reqwest.workspace = true
bitcoin = "0.32.0"
clap = { workspace = true, features = ["derive"] }
web-time.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio.workspace = true
@@ -57,7 +58,6 @@ tokio.workspace = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { workspace = true, features = ["rt", "macros", "sync", "time"] }
getrandom = { version = "0.2", features = ["js"] }
instant = { workspace = true, features = ["wasm-bindgen", "inaccurate"] }
uuid = { workspace = true, features = ["js"] }
[dev-dependencies]

View File

@@ -45,6 +45,7 @@ uuid.workspace = true
jsonwebtoken = { workspace = true, optional = true }
trust-dns-resolver = { version = "0.23.2", optional = true }
cdk-prometheus = {workspace = true, optional = true}
web-time.workspace = true
# -Z minimal-versions
sync_wrapper = "0.1.2"
bech32 = "0.9.1"

View File

@@ -1,7 +1,6 @@
//! HTTP Mint client with pluggable transport
use std::collections::HashSet;
use std::sync::{Arc, RwLock as StdRwLock};
use std::time::{Duration, Instant};
use async_trait::async_trait;
use cdk_common::{nut19, MeltQuoteBolt12Request, MintQuoteBolt12Request, MintQuoteBolt12Response};
@@ -13,6 +12,7 @@ use serde::Serialize;
use tokio::sync::RwLock;
use tracing::instrument;
use url::Url;
use web_time::{Duration, Instant};
use super::transport::Transport;
use super::{Error, MintConnector};

View File

@@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use cdk_common::MintQuoteBolt12Response;
use tokio::sync::{mpsc, RwLock};
use tokio::time;
use web_time::Duration;
use super::WsSubscriptionBody;
use crate::nuts::nut17::Kind;