@@ -73,29 +73,39 @@ mod asset_tag_ext {
73
73
use bp:: secp256k1:: rand:: { thread_rng, RngCore } ;
74
74
use commit_verify:: { DigestExt , Sha256 } ;
75
75
use rgb:: AssetTag ;
76
+ use strict_encoding:: TypeName ;
76
77
77
78
use super :: * ;
78
79
79
80
pub trait AssetTagExt : Sized {
80
81
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)
82
83
}
83
84
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)
85
86
}
86
87
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)
88
89
}
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 ;
90
95
}
91
96
92
97
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 {
94
103
let rand = thread_rng ( ) . next_u64 ( ) ;
95
104
let timestamp = SystemTime :: now ( ) . elapsed ( ) . expect ( "system time error" ) ;
96
105
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 ( ) ) ;
99
109
hasher. input_raw ( & timestamp. as_nanos ( ) . to_le_bytes ( ) ) ;
100
110
hasher. input_raw ( & rand. to_le_bytes ( ) ) ;
101
111
AssetTag :: from ( hasher. finish ( ) )
0 commit comments