From d829b62abe098b1a07a31727c7b543d355cd6393 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 18 Nov 2023 13:34:31 +0100 Subject: [PATCH] iface: abstract AssetTag from specific interface --- src/interface/mod.rs | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 3b7b0910..252a9113 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -48,8 +48,6 @@ pub use rgb21::{rgb21, rgb21_stl, Rgb21, LIB_ID_RGB21, LIB_NAME_RGB21}; pub use rgb25::{rgb25, rgb25_stl, Rgb25, LIB_ID_RGB25, LIB_NAME_RGB25}; pub use suppl::{ContractSuppl, OwnedStateSuppl, SupplId, TickerSuppl, VelocityHint}; -use crate::stl::Ticker; - #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = crate::LIB_NAME_RGB_STD, tags = repr, into_u8, try_from_u8)] @@ -66,6 +64,7 @@ pub enum VerNo { V1 = 0, } +// TODO: Move to RGB Core mod asset_tag_ext { use std::time::SystemTime; @@ -73,39 +72,17 @@ mod asset_tag_ext { use bp::secp256k1::rand::{thread_rng, RngCore}; use commit_verify::{DigestExt, Sha256}; use rgb::AssetTag; - use strict_encoding::TypeName; - - use super::*; pub trait AssetTagExt: Sized { - fn new_rgb20(issuer_domain: &str, ticker: &Ticker) -> Self { - Self::new_custom("RGB20", issuer_domain, ticker) - } - fn new_rgb21(issuer_domain: &str, ticker: &Ticker) -> Self { - Self::new_custom("RGB21", issuer_domain, ticker) - } - fn new_rgb25(issuer_domain: &str, ticker: &Ticker) -> Self { - Self::new_custom("RGB25", issuer_domain, ticker) - } - fn new_custom( - iface_name: impl Into, - issuer_domain: impl AsRef, - ticker: impl AsRef, - ) -> Self; + fn new_random(contract_domain: impl AsRef) -> Self; } impl AssetTagExt for AssetTag { - fn new_custom( - iface_name: impl Into, - issuer_domain: impl AsRef, - ticker: impl AsRef, - ) -> Self { + fn new_random(contract_domain: impl AsRef) -> Self { let rand = thread_rng().next_u64(); let timestamp = SystemTime::now().elapsed().expect("system time error"); let mut hasher = Sha256::default(); - hasher.input_with_len::(iface_name.into().as_bytes()); - hasher.input_with_len::(issuer_domain.as_ref().as_bytes()); - hasher.input_with_len::(ticker.as_ref().as_bytes()); + hasher.input_with_len::(contract_domain.as_ref().as_bytes()); hasher.input_raw(×tamp.as_nanos().to_le_bytes()); hasher.input_raw(&rand.to_le_bytes()); AssetTag::from(hasher.finish())