diff --git a/Cargo.lock b/Cargo.lock index 274138f0..09d17247 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,6 +605,7 @@ dependencies = [ "amplify", "baid58", "bp-core", + "chrono", "commit_verify", "getrandom", "mime", diff --git a/Cargo.toml b/Cargo.toml index 158a3d67..7b3d4593 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ secp256k1-zkp = { version = "0.9.2", features = ["rand", "rand-std", "global-con baid58 = "~0.4.4" mime = "~0.3.17" serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true } +chrono = "0.4.31" [features] default = [] diff --git a/src/contract/fungible.rs b/src/contract/fungible.rs index 83847f2c..80cae4f5 100644 --- a/src/contract/fungible.rs +++ b/src/contract/fungible.rs @@ -37,7 +37,6 @@ use core::ops::Deref; use core::str::FromStr; use std::io; use std::io::Write; -use std::time::SystemTime; use amplify::confinement::U8; use amplify::hex::ToHex; @@ -45,6 +44,7 @@ use amplify::hex::ToHex; // that we do not use the standard secp256k1zkp library use amplify::{hex, Array, Bytes32, Wrapper}; use bp::secp256k1::rand::thread_rng; +use chrono::Local; use commit_verify::{ CommitEncode, CommitVerify, CommitmentProtocol, Conceal, DigestExt, Sha256, UntaggedProtocol, }; @@ -76,11 +76,13 @@ pub struct AssetTag( impl AssetTag { pub fn new_random(contract_domain: impl AsRef, assignment_type: AssignmentType) -> Self { let rand = thread_rng().next_u64(); - let timestamp = SystemTime::now().elapsed().expect("system time error"); + let timestamp = Local::now() + .timestamp_nanos_opt() + .expect("local time error"); let mut hasher = Sha256::default(); hasher.input_with_len::(contract_domain.as_ref().as_bytes()); hasher.input_raw(&assignment_type.to_le_bytes()); - hasher.input_raw(×tamp.as_nanos().to_le_bytes()); + hasher.input_raw(×tamp.to_le_bytes()); hasher.input_raw(&rand.to_le_bytes()); AssetTag::from(hasher.finish()) }