@@ -123,8 +123,8 @@ mod azns_registry {
123
123
124
124
/// Mapping from name to addresses associated with it
125
125
name_to_address_dict : Mapping < String , AddressDict , ManualKey < 200 > > ,
126
- /// Mapping from name to its expiry timestamp
127
- name_to_expiry : Mapping < String , u64 > ,
126
+ /// Mapping from name to its registration period ( timestamp)
127
+ name_to_period : Mapping < String , ( u64 , u64 ) > ,
128
128
/// Metadata
129
129
metadata : Mapping < String , Vec < ( String , String ) > , ManualKey < 201 > > ,
130
130
metadata_size_limit : Option < u32 > ,
@@ -226,7 +226,7 @@ mod azns_registry {
226
226
name_checker,
227
227
fee_calculator,
228
228
name_to_address_dict : Mapping :: default ( ) ,
229
- name_to_expiry : Mapping :: default ( ) ,
229
+ name_to_period : Mapping :: default ( ) ,
230
230
owner_to_names : Default :: default ( ) ,
231
231
metadata : Default :: default ( ) ,
232
232
address_to_primary_name : Default :: default ( ) ,
@@ -574,9 +574,16 @@ mod azns_registry {
574
574
self . get_address_dict_ref ( & name) . map ( |x| x. resolved )
575
575
}
576
576
577
+ #[ ink( message) ]
578
+ pub fn get_registration_date ( & self , name : String ) -> Result < u64 > {
579
+ self . get_registration_period_ref ( & name)
580
+ . map ( |( registration, _) | registration)
581
+ }
582
+
577
583
#[ ink( message) ]
578
584
pub fn get_expiry_date ( & self , name : String ) -> Result < u64 > {
579
- self . name_to_expiry . get ( & name) . ok_or ( Error :: NameDoesntExist )
585
+ self . get_registration_period_ref ( & name)
586
+ . map ( |( _, expiry) | expiry)
580
587
}
581
588
582
589
/// Gets all records
@@ -854,9 +861,11 @@ mod azns_registry {
854
861
_ => ( ) , // Name is available
855
862
}
856
863
864
+ let registration = self . env ( ) . block_timestamp ( ) ;
865
+
857
866
let address_dict = AddressDict :: new ( recipient. clone ( ) ) ;
858
867
self . name_to_address_dict . insert ( name, & address_dict) ;
859
- self . name_to_expiry . insert ( name, & expiry) ;
868
+ self . name_to_period . insert ( name, & ( registration , expiry) ) ;
860
869
861
870
/* Update convenience mapping for owned names */
862
871
self . add_name_to_owner ( recipient, name) ;
@@ -890,7 +899,7 @@ mod azns_registry {
890
899
} ;
891
900
892
901
self . name_to_address_dict . remove ( name) ;
893
- self . name_to_expiry . remove ( name) ;
902
+ self . name_to_period . remove ( name) ;
894
903
self . metadata . remove ( name) ;
895
904
896
905
self . remove_name_from_owner ( & address_dict. owner , & name) ;
@@ -1159,9 +1168,13 @@ mod azns_registry {
1159
1168
. unwrap_or_default ( )
1160
1169
}
1161
1170
1171
+ fn get_registration_period_ref ( & self , name : & str ) -> Result < ( u64 , u64 ) > {
1172
+ self . name_to_period . get ( name) . ok_or ( Error :: NameDoesntExist )
1173
+ }
1174
+
1162
1175
fn has_name_expired ( & self , name : & str ) -> Result < bool > {
1163
- match self . name_to_expiry . get ( name) {
1164
- Some ( expiry) => Ok ( expiry <= self . env ( ) . block_timestamp ( ) ) ,
1176
+ match self . name_to_period . get ( name) {
1177
+ Some ( ( _ , expiry) ) => Ok ( expiry <= self . env ( ) . block_timestamp ( ) ) ,
1165
1178
None => Err ( Error :: NameDoesntExist ) ,
1166
1179
}
1167
1180
}
@@ -1350,8 +1363,14 @@ mod azns_registry {
1350
1363
. map ( |key| match key. as_str ( ) {
1351
1364
"TLD" => self . tld . clone ( ) ,
1352
1365
"Length" => name. chars ( ) . count ( ) . to_string ( ) ,
1353
- "Registration" => "" . to_string ( ) ,
1354
- "Expiration" => "" . to_string ( ) ,
1366
+ "Registration" => match self . get_registration_period_ref ( & name) {
1367
+ Ok ( period) => period. 0 . to_string ( ) ,
1368
+ _ => String :: new ( ) ,
1369
+ } ,
1370
+ "Expiration" => match self . get_registration_period_ref ( & name) {
1371
+ Ok ( period) => period. 1 . to_string ( ) ,
1372
+ _ => String :: new ( ) ,
1373
+ } ,
1355
1374
_ => "" . to_string ( ) ,
1356
1375
} )
1357
1376
. collect ( )
0 commit comments