diff --git a/pallets/network-score/src/lib.rs b/pallets/network-score/src/lib.rs index d10dbdec..36a8687b 100644 --- a/pallets/network-score/src/lib.rs +++ b/pallets/network-score/src/lib.rs @@ -166,14 +166,19 @@ pub mod pallet { pub type EntityIdentifierOf = BoundedVec::MaxEncodedValueLength>; pub type EntityIdentityOf = BoundedVec::MaxEncodedValueLength>; pub type ProviderIdentifierOf = BoundedVec::MaxEncodedValueLength>; + pub type EntityNameOf = BoundedVec::MaxEncodedValueLength>; - pub type RatingInputEntryOf = - RatingInputEntry, RatingProviderIdOf, EntityTypeOf, RatingTypeOf>; + pub type RatingInputEntryOf = RatingInputEntry< + EntityIdentifierOf, + EntityNameOf, + RatingProviderIdOf, + RatingTypeOf, + >; pub type RatingEntryOf = RatingEntry< EntityIdentifierOf, + EntityNameOf, RatingProviderIdOf, - EntityTypeOf, RatingTypeOf, RatingEntryIdOf, RatingEntryHashOf, @@ -184,8 +189,6 @@ pub mod pallet { ::Moment, >; - // pub type AggregatedEntryOf = AggregatedEntry; - #[pallet::config] pub trait Config: frame_system::Config + pallet_chain_space::Config + identifier::Config + timestamp::Config @@ -377,19 +380,13 @@ pub mod pallet { Error::::InvalidRatingValue ); - ensure!( - entry.entity_type.is_valid_entity_type() && - entry.rating_type.is_valid_rating_type(), - Error::::InvalidEntryOrRatingType - ); - ensure!( !>::contains_key(&message_id, &provider), Error::::MessageIdAlreadyExists ); let provider_did = entry.provider_did.clone(); - let entity_uid = entry.entity_uid.clone(); + let entity_id = entry.entity_id.clone(); // Id Digest = concat (H(,(), // ( , @@ -397,7 +394,7 @@ pub mod pallet { let id_digest = ::Hashing::hash( &[ &digest.encode()[..], - &entity_uid.encode()[..], + &entity_id.encode()[..], &message_id.encode()[..], &space_id.encode()[..], &provider_did.encode()[..], @@ -418,7 +415,7 @@ pub mod pallet { Self::aggregate_score(&entry, EntryTypeOf::Credit)?; - let entity = entry.entity_uid.clone(); + let entity = entry.entity_id.clone(); let created_at = Self::get_current_time(); >::insert( @@ -516,7 +513,7 @@ pub mod pallet { ); let provider_did = rating_details.entry.provider_did.clone(); - let entity_uid = rating_details.entry.entity_uid.clone(); + let entity_id = rating_details.entry.entity_id.clone(); // Id Digest = concat (H(,(), // () , @@ -524,7 +521,7 @@ pub mod pallet { let id_digest = ::Hashing::hash( &[ &digest.encode()[..], - &entity_uid.encode()[..], + &entity_id.encode()[..], &message_id.encode()[..], &space_id.encode()[..], &provider_did.encode()[..], @@ -545,7 +542,7 @@ pub mod pallet { Self::aggregate_score(&rating_details.entry, EntryTypeOf::Debit)?; - let entity = rating_details.entry.entity_uid.clone(); + let entity = rating_details.entry.entity_id.clone(); let created_at = Self::get_current_time(); >::insert( @@ -648,19 +645,10 @@ pub mod pallet { Error::::InvalidRatingValue ); - ensure!( - entry.entity_type.is_valid_entity_type() && - entry.rating_type.is_valid_rating_type(), - Error::::InvalidEntryOrRatingType - ); - let rating_details = >::get(&debit_ref_id) .ok_or(Error::::ReferenceIdentifierNotFound)?; - ensure!( - entry.entity_uid == rating_details.entry.entity_uid, - Error::::EntityMismatch - ); + ensure!(entry.entity_id == rating_details.entry.entity_id, Error::::EntityMismatch); ensure!(space_id == rating_details.space, Error::::SpaceMismatch); let stored_entry_type: EntryTypeOf = rating_details.entry_type; @@ -675,7 +663,7 @@ pub mod pallet { ); let provider_did = entry.provider_did.clone(); - let entity_uid = entry.entity_uid.clone(); + let entity_uid = entry.entity_id.clone(); // Id Digest = concat (H(, (), // (), , // )) @@ -702,7 +690,7 @@ pub mod pallet { ); Self::aggregate_score(&entry, EntryTypeOf::Credit)?; - let entity = rating_details.entry.entity_uid.clone(); + let entity = rating_details.entry.entity_id.clone(); let reference_id_option = rating_details.reference_id; let created_at = Self::get_current_time(); @@ -771,8 +759,7 @@ impl Pallet { entry: &RatingInputEntryOf, rtype: EntryTypeOf, ) -> Result<(), pallet::Error> { - if let Some(mut aggregate) = - >::get(&entry.entity_uid, &entry.rating_type) + if let Some(mut aggregate) = >::get(&entry.entity_id, &entry.rating_type) { match rtype { EntryTypeOf::Credit => { @@ -789,7 +776,7 @@ impl Pallet { }, }; >::insert( - &entry.entity_uid, + &entry.entity_id, &entry.rating_type, AggregatedEntryOf { count_of_txn: aggregate.count_of_txn, @@ -801,9 +788,9 @@ impl Pallet { count_of_txn: entry.count_of_txn, total_encoded_rating: entry.total_encoded_rating, }; - >::insert(&entry.entity_uid, &entry.rating_type, new_score_entry); + >::insert(&entry.entity_id, &entry.rating_type, new_score_entry); } - Self::deposit_event(Event::AggregateScoreUpdated { entity: entry.entity_uid.clone() }); + Self::deposit_event(Event::AggregateScoreUpdated { entity: entry.entity_id.clone() }); Ok(()) } diff --git a/pallets/network-score/src/types.rs b/pallets/network-score/src/types.rs index 10fe703e..a3b521b4 100644 --- a/pallets/network-score/src/types.rs +++ b/pallets/network-score/src/types.rs @@ -33,17 +33,17 @@ pub struct EntityDetails { #[derive( Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen, )] -pub struct RatingInputEntry { - /// Unique Identifier (UID) for the entity being rated - pub entity_uid: EntityIdentifier, +pub struct RatingInputEntry { + /// Identifier for the entity being rated + pub entity_id: EntityIdentifier, + /// Name of the entity being rated + pub entity_name: EntityName, /// Unique Identifier (UID) for the rating provider - pub provider_uid: EntityIdentifier, + pub provider_id: EntityIdentifier, /// Count of raing transactions for the entry pub count_of_txn: u64, /// Cumulative sum of ratings for the entity pub total_encoded_rating: u64, - /// Type of the entity (seller/logistic) - pub entity_type: EntityTypeOf, /// Type of rating (overall/delivery) pub rating_type: RatingTypeOf, /// DID identifier of the provider @@ -56,24 +56,12 @@ pub enum RatingTypeOf { Delivery, } -#[derive(Encode, Decode, MaxEncodedLen, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] -pub enum EntityTypeOf { - Retail, - Logistic, -} - #[derive(Encode, Decode, MaxEncodedLen, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] pub enum EntryTypeOf { Credit, Debit, } -impl EntityTypeOf { - pub fn is_valid_entity_type(&self) -> bool { - matches!(self, Self::Retail | Self::Logistic) - } -} - impl RatingTypeOf { pub fn is_valid_rating_type(&self) -> bool { matches!(self, Self::Overall | Self::Delivery) @@ -85,8 +73,8 @@ impl RatingTypeOf { )] pub struct RatingEntry< EntityIdentifier, + EntityName, RatingProviderId, - EntityTypeOf, RatingTypeOf, RatingEntryId, RatingEntryHash, @@ -96,7 +84,7 @@ pub struct RatingEntry< EntryTypeOf, Moment, > { - pub entry: RatingInputEntry, + pub entry: RatingInputEntry, /// rating digest pub digest: RatingEntryHash, /// messsage identifier of the rating entry