Skip to content

Commit f736afe

Browse files
authored
Improve attribute check (#14)
1 parent 32043e7 commit f736afe

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/lib.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,7 @@ impl<T: Trait> Did<T::AccountId, T::BlockNumber, <<T as Trait>::Time as Time>::M
437437
) -> DispatchResult {
438438
Self::is_owner(&identity, &who)?;
439439

440-
let mut nonce = Self::nonce_of((&identity, name.to_vec()));
441-
// Used for first time attribute creation
442-
let lookup_nonce = match nonce {
443-
0u64 => 0u64,
444-
_ => nonce - 1u64,
445-
};
446-
let mut id = (&identity, name, lookup_nonce).using_encoded(blake2_256);
447-
448-
if <AttributeOf<T>>::contains_key((&identity, &id)) {
440+
if Self::attribute_and_id(identity, name).is_some() {
449441
Err(Error::<T>::AttributeCreationFailed.into())
450442
} else {
451443
let now_timestamp = T::Time::now();
@@ -455,6 +447,8 @@ impl<T: Trait> Did<T::AccountId, T::BlockNumber, <<T as Trait>::Time as Time>::M
455447
None => u32::max_value().into(),
456448
};
457449

450+
let mut nonce = Self::nonce_of((&identity, name.to_vec()));
451+
let id = (&identity, name, nonce).using_encoded(blake2_256);
458452
let new_attribute = Attribute {
459453
name: (&name).to_vec(),
460454
value: (&value).to_vec(),
@@ -463,7 +457,6 @@ impl<T: Trait> Did<T::AccountId, T::BlockNumber, <<T as Trait>::Time as Time>::M
463457
nonce,
464458
};
465459

466-
id = (&identity, name, nonce).using_encoded(blake2_256);
467460
// Prevent panic overflow
468461
nonce = nonce.checked_add(1).ok_or(Error::<T>::Overflow)?;
469462
<AttributeOf<T>>::insert((&identity, &id), new_attribute);

0 commit comments

Comments
 (0)