Skip to content

Commit aeec368

Browse files
committed
fix: AssetTag compatible with wasm target
1 parent 729c652 commit aeec368

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ secp256k1-zkp = { version = "0.9.2", features = ["rand", "rand-std", "global-con
3333
baid58 = "~0.4.4"
3434
mime = "~0.3.17"
3535
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
36+
chrono = "0.4.31"
3637

3738
[features]
3839
default = []

src/contract/fungible.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ use core::ops::Deref;
3737
use core::str::FromStr;
3838
use std::io;
3939
use std::io::Write;
40-
use std::time::SystemTime;
4140

4241
use amplify::confinement::U8;
4342
use amplify::hex::ToHex;
4443
// We do not import particular modules to keep aware with namespace prefixes
4544
// that we do not use the standard secp256k1zkp library
4645
use amplify::{hex, Array, Bytes32, Wrapper};
4746
use bp::secp256k1::rand::thread_rng;
47+
use chrono::Local;
4848
use commit_verify::{
4949
CommitEncode, CommitVerify, CommitmentProtocol, Conceal, DigestExt, Sha256, UntaggedProtocol,
5050
};
@@ -76,11 +76,13 @@ pub struct AssetTag(
7676
impl AssetTag {
7777
pub fn new_random(contract_domain: impl AsRef<str>, assignment_type: AssignmentType) -> Self {
7878
let rand = thread_rng().next_u64();
79-
let timestamp = SystemTime::now().elapsed().expect("system time error");
79+
let timestamp = Local::now()
80+
.timestamp_nanos_opt()
81+
.expect("local time error");
8082
let mut hasher = Sha256::default();
8183
hasher.input_with_len::<U8>(contract_domain.as_ref().as_bytes());
8284
hasher.input_raw(&assignment_type.to_le_bytes());
83-
hasher.input_raw(&timestamp.as_nanos().to_le_bytes());
85+
hasher.input_raw(&timestamp.to_le_bytes());
8486
hasher.input_raw(&rand.to_le_bytes());
8587
AssetTag::from(hasher.finish())
8688
}

0 commit comments

Comments
 (0)