Skip to content

Commit 95f70fc

Browse files
committed
iface: refactor AssetTag custom constructor
1 parent 1cc293c commit 95f70fc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/interface/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,39 @@ mod asset_tag_ext {
7373
use bp::secp256k1::rand::{thread_rng, RngCore};
7474
use commit_verify::{DigestExt, Sha256};
7575
use rgb::AssetTag;
76+
use strict_encoding::TypeName;
7677

7778
use super::*;
7879

7980
pub trait AssetTagExt: Sized {
8081
fn new_rgb20(issuer_domain: &str, ticker: &Ticker) -> Self {
81-
Self::new_custom("RGB20", &format!("{issuer_domain}/{ticker}"))
82+
Self::new_custom("RGB20", issuer_domain, ticker)
8283
}
8384
fn new_rgb21(issuer_domain: &str, ticker: &Ticker) -> Self {
84-
Self::new_custom("RGB21", &format!("{issuer_domain}/{ticker}"))
85+
Self::new_custom("RGB21", issuer_domain, ticker)
8586
}
8687
fn new_rgb25(issuer_domain: &str, ticker: &Ticker) -> Self {
87-
Self::new_custom("RGB25", &format!("{issuer_domain}/{ticker}"))
88+
Self::new_custom("RGB25", issuer_domain, ticker)
8889
}
89-
fn new_custom(iface_name: &str, data: &str) -> Self;
90+
fn new_custom(
91+
iface_name: impl Into<TypeName>,
92+
issuer_domain: impl AsRef<str>,
93+
ticker: impl AsRef<str>,
94+
) -> Self;
9095
}
9196

9297
impl AssetTagExt for AssetTag {
93-
fn new_custom(iface_name: &str, data: &str) -> Self {
98+
fn new_custom(
99+
iface_name: impl Into<TypeName>,
100+
issuer_domain: impl AsRef<str>,
101+
ticker: impl AsRef<str>,
102+
) -> Self {
94103
let rand = thread_rng().next_u64();
95104
let timestamp = SystemTime::now().elapsed().expect("system time error");
96105
let mut hasher = Sha256::default();
97-
hasher.input_with_len::<U8>(iface_name.as_bytes());
98-
hasher.input_with_len::<U8>(data.as_bytes());
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());
99109
hasher.input_raw(&timestamp.as_nanos().to_le_bytes());
100110
hasher.input_raw(&rand.to_le_bytes());
101111
AssetTag::from(hasher.finish())

0 commit comments

Comments
 (0)