Skip to content

Commit 8ce111c

Browse files
committed
iface: abstract AssetTag from specific interface
1 parent 95f70fc commit 8ce111c

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

src/interface/mod.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ pub use rgb21::{rgb21, rgb21_stl, Rgb21, LIB_ID_RGB21, LIB_NAME_RGB21};
4848
pub use rgb25::{rgb25, rgb25_stl, Rgb25, LIB_ID_RGB25, LIB_NAME_RGB25};
4949
pub use suppl::{ContractSuppl, OwnedStateSuppl, SupplId, TickerSuppl, VelocityHint};
5050

51-
use crate::stl::Ticker;
52-
5351
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)]
5452
#[derive(StrictType, StrictEncode, StrictDecode)]
5553
#[strict_type(lib = crate::LIB_NAME_RGB_STD, tags = repr, into_u8, try_from_u8)]
@@ -66,46 +64,26 @@ pub enum VerNo {
6664
V1 = 0,
6765
}
6866

67+
// TODO: Move to RGB Core
6968
mod asset_tag_ext {
7069
use std::time::SystemTime;
7170

7271
use amplify::confinement::U8;
7372
use bp::secp256k1::rand::{thread_rng, RngCore};
7473
use commit_verify::{DigestExt, Sha256};
75-
use rgb::AssetTag;
76-
use strict_encoding::TypeName;
77-
78-
use super::*;
74+
use rgb::{AssetTag, AssignmentType};
7975

8076
pub trait AssetTagExt: Sized {
81-
fn new_rgb20(issuer_domain: &str, ticker: &Ticker) -> Self {
82-
Self::new_custom("RGB20", issuer_domain, ticker)
83-
}
84-
fn new_rgb21(issuer_domain: &str, ticker: &Ticker) -> Self {
85-
Self::new_custom("RGB21", issuer_domain, ticker)
86-
}
87-
fn new_rgb25(issuer_domain: &str, ticker: &Ticker) -> Self {
88-
Self::new_custom("RGB25", issuer_domain, ticker)
89-
}
90-
fn new_custom(
91-
iface_name: impl Into<TypeName>,
92-
issuer_domain: impl AsRef<str>,
93-
ticker: impl AsRef<str>,
94-
) -> Self;
77+
fn new_random(contract_domain: impl AsRef<str>, assignment_type: AssignmentType) -> Self;
9578
}
9679

9780
impl AssetTagExt for AssetTag {
98-
fn new_custom(
99-
iface_name: impl Into<TypeName>,
100-
issuer_domain: impl AsRef<str>,
101-
ticker: impl AsRef<str>,
102-
) -> Self {
81+
fn new_random(contract_domain: impl AsRef<str>, assignment_type: AssignmentType) -> Self {
10382
let rand = thread_rng().next_u64();
10483
let timestamp = SystemTime::now().elapsed().expect("system time error");
10584
let mut hasher = Sha256::default();
106-
hasher.input_with_len::<U8>(iface_name.into().as_bytes());
107-
hasher.input_with_len::<U8>(issuer_domain.as_ref().as_bytes());
108-
hasher.input_with_len::<U8>(ticker.as_ref().as_bytes());
85+
hasher.input_with_len::<U8>(contract_domain.as_ref().as_bytes());
86+
hasher.input_raw(&assignment_type.to_le_bytes());
10987
hasher.input_raw(&timestamp.as_nanos().to_le_bytes());
11088
hasher.input_raw(&rand.to_le_bytes());
11189
AssetTag::from(hasher.finish())

0 commit comments

Comments
 (0)