Skip to content

Commit 0fc7c39

Browse files
committed
feat: store registration timestamp as well
1 parent da7620b commit 0fc7c39

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

azns_registry/lib.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ mod azns_registry {
123123

124124
/// Mapping from name to addresses associated with it
125125
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)>,
128128
/// Metadata
129129
metadata: Mapping<String, Vec<(String, String)>, ManualKey<201>>,
130130
metadata_size_limit: Option<u32>,
@@ -226,7 +226,7 @@ mod azns_registry {
226226
name_checker,
227227
fee_calculator,
228228
name_to_address_dict: Mapping::default(),
229-
name_to_expiry: Mapping::default(),
229+
name_to_period: Mapping::default(),
230230
owner_to_names: Default::default(),
231231
metadata: Default::default(),
232232
address_to_primary_name: Default::default(),
@@ -574,9 +574,16 @@ mod azns_registry {
574574
self.get_address_dict_ref(&name).map(|x| x.resolved)
575575
}
576576

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+
577583
#[ink(message)]
578584
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)
580587
}
581588

582589
/// Gets all records
@@ -854,9 +861,11 @@ mod azns_registry {
854861
_ => (), // Name is available
855862
}
856863

864+
let registration = self.env().block_timestamp();
865+
857866
let address_dict = AddressDict::new(recipient.clone());
858867
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));
860869

861870
/* Update convenience mapping for owned names */
862871
self.add_name_to_owner(recipient, name);
@@ -890,7 +899,7 @@ mod azns_registry {
890899
};
891900

892901
self.name_to_address_dict.remove(name);
893-
self.name_to_expiry.remove(name);
902+
self.name_to_period.remove(name);
894903
self.metadata.remove(name);
895904

896905
self.remove_name_from_owner(&address_dict.owner, &name);
@@ -1159,9 +1168,13 @@ mod azns_registry {
11591168
.unwrap_or_default()
11601169
}
11611170

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+
11621175
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()),
11651178
None => Err(Error::NameDoesntExist),
11661179
}
11671180
}
@@ -1350,8 +1363,14 @@ mod azns_registry {
13501363
.map(|key| match key.as_str() {
13511364
"TLD" => self.tld.clone(),
13521365
"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+
},
13551374
_ => "".to_string(),
13561375
})
13571376
.collect()

0 commit comments

Comments
 (0)