@@ -437,15 +437,7 @@ impl<T: Trait> Did<T::AccountId, T::BlockNumber, <<T as Trait>::Time as Time>::M
437
437
) -> DispatchResult {
438
438
Self :: is_owner ( & identity, & who) ?;
439
439
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 ( ) {
449
441
Err ( Error :: < T > :: AttributeCreationFailed . into ( ) )
450
442
} else {
451
443
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
455
447
None => u32:: max_value ( ) . into ( ) ,
456
448
} ;
457
449
450
+ let mut nonce = Self :: nonce_of ( ( & identity, name. to_vec ( ) ) ) ;
451
+ let id = ( & identity, name, nonce) . using_encoded ( blake2_256) ;
458
452
let new_attribute = Attribute {
459
453
name : ( & name) . to_vec ( ) ,
460
454
value : ( & value) . to_vec ( ) ,
@@ -463,7 +457,6 @@ impl<T: Trait> Did<T::AccountId, T::BlockNumber, <<T as Trait>::Time as Time>::M
463
457
nonce,
464
458
} ;
465
459
466
- id = ( & identity, name, nonce) . using_encoded ( blake2_256) ;
467
460
// Prevent panic overflow
468
461
nonce = nonce. checked_add ( 1 ) . ok_or ( Error :: < T > :: Overflow ) ?;
469
462
<AttributeOf < T > >:: insert ( ( & identity, & id) , new_attribute) ;
0 commit comments