@@ -32,6 +32,7 @@ use cord_uri::{EntryTypeOf, EventStamp, Identifier, RegistryIdentifierCheck, Ss5
3232use frame_support:: dispatch:: DispatchResult ;
3333use frame_support:: BoundedVec ;
3434use frame_system:: pallet_prelude:: BlockNumberFor ;
35+ use frame_support:: traits:: ConstU32 ;
3536use frame_system:: WeightInfo ;
3637use pallet_profile:: ProfileIdOf ;
3738
@@ -50,6 +51,9 @@ pub type RegistryIdentifierOf = Ss58Identifier;
5051pub type HashOf < T > = <T as frame_system:: Config >:: Hash ;
5152pub ( crate ) type CordAccountOf < T > = <T as frame_system:: Config >:: AccountId ;
5253
54+ pub type DocIdOf = BoundedVec < u8 , ConstU32 < 64 > > ;
55+ pub type DocNodeIdOf = BoundedVec < u8 , ConstU32 < 64 > > ;
56+
5357#[ frame_support:: pallet]
5458pub mod pallet {
5559 use super :: * ;
@@ -90,7 +94,7 @@ pub mod pallet {
9094 _ ,
9195 Blake2_128Concat ,
9296 RegistryIdentifierOf ,
93- RegistryDetails < HashOf < T > , Status > ,
97+ RegistryDetails < HashOf < T > , Status , DocIdOf , DocNodeIdOf > ,
9498 OptionQuery ,
9599 > ;
96100
@@ -124,6 +128,11 @@ pub mod pallet {
124128 creator : CordAccountOf < T > ,
125129 profile_id : ProfileIdOf
126130 } ,
131+ RegistryStoreCreated {
132+ registry : RegistryIdentifierOf ,
133+ creator : CordAccountOf < T > ,
134+ profile_id : ProfileIdOf
135+ } ,
127136 RegistryUpdated {
128137 registry : RegistryIdentifierOf ,
129138 authority : CordAccountOf < T > ,
@@ -274,18 +283,14 @@ pub mod pallet {
274283
275284 /// Creates a new registry.
276285 ///
277- /// Initializes a new registry with the provided transaction hash and optional metadata
278- /// (document ID, author, node ID). The creator must have a valid profile. The registry is
279- /// created via the `registry::create_registry` function, assigned a unique SS58 identifier,
280- /// and marked as active.
286+ /// Initializes a new registry with the provided transaction hash and a optional blob.
287+ /// The creator must have a valid profile. The registry is created via the `registry::create_registry`
288+ /// function, assigned a unique SS58 identifier, and marked as active.
281289 ///
282290 /// # Arguments
283291 /// * `origin` - The signed account creating the registry.
284292 /// * `tx_hash` - The hash of the registry’s content.
285293 /// * `_blob` - Optional data associated with the registry.
286- /// * `doc_id` - Optional document identifier.
287- /// * `doc_author_id` - Optional account ID of the document author.
288- /// * `doc_node_id` - Optional document node identifier.
289294 ///
290295 /// # Errors
291296 /// * `InvalidIdentifierLength` - If the generated registry ID is invalid.
@@ -302,9 +307,6 @@ pub mod pallet {
302307 origin : OriginFor < T > ,
303308 tx_hash : HashOf < T > ,
304309 _blob : Option < RegistryBlobOf < T > > ,
305- doc_id : Option < Vec < u8 > > ,
306- doc_author_id : Option < CordAccountOf < T > > ,
307- doc_node_id : Option < Vec < u8 > > ,
308310 ) -> DispatchResult {
309311 let creator = ensure_signed ( origin) ?;
310312
@@ -313,16 +315,69 @@ pub mod pallet {
313315 )
314316 . map_err ( <pallet_profile:: Error < T > >:: from) ?;
315317
316- let doc_author_profile_id = if let Some ( author) = doc_author_id. clone ( ) {
317- Some (
318- pallet_profile:: Pallet :: < T > :: get_profile_id ( & author)
319- . map_err ( <pallet_profile:: Error < T > >:: from) ?
320- )
321- } else {
322- None
323- } ;
324-
325318 let registry_id = registry:: create_registry :: < T > (
319+ tx_hash,
320+ profile_id. clone ( ) ,
321+ ) ?;
322+
323+ Self :: deposit_event (
324+ Event :: RegistryCreated {
325+ registry : registry_id,
326+ creator, profile_id,
327+ }
328+ ) ;
329+
330+ Ok ( ( ) )
331+ }
332+
333+
334+ /// Creates a new registry store with cyra based credentials.
335+ ///
336+ /// Initializes a new registry store with the provided transaction hash and optional metadata
337+ /// (document ID, author, node ID). The creator must have a valid profile. The registry is
338+ /// created via the `registry::create_registry_store` function, assigned a unique SS58 identifier,
339+ /// and marked as active.
340+ ///
341+ /// The key difference between create and create-store is that create-store is to map the registry
342+ /// data present in Cyra into Cord.
343+ ///
344+ /// # Arguments
345+ /// * `origin` - The signed account creating the registry.
346+ /// * `tx_hash` - The hash of the registry’s content.
347+ /// * `_blob` - Data associated with the registry.
348+ /// * `doc_id` - Document identifier.
349+ /// * `doc_author_id` - Account ID of the document author.
350+ /// * `doc_node_id` - Document node identifier.
351+ ///
352+ /// # Errors
353+ /// * `InvalidIdentifierLength` - If the generated registry ID is invalid.
354+ /// * `RegistryAlreadyExists` - If a registry with the same ID exists.
355+ /// * `pallet_profile::Error` - If the creator’s or author’s profile is invalid.
356+ ///
357+ /// # Events
358+ /// * `RegistryStoreCreated` - Emitted with `registry`, `creator`, `profile_id`.
359+ ///
360+ /// ```
361+ #[ pallet:: call_index( 3 ) ]
362+ #[ pallet:: weight( { 10_000 } ) ]
363+ pub fn create_store (
364+ origin : OriginFor < T > ,
365+ tx_hash : HashOf < T > ,
366+ doc_id : Vec < u8 > ,
367+ doc_author_id : CordAccountOf < T > ,
368+ doc_node_id : Vec < u8 > ,
369+ ) -> DispatchResult {
370+ let creator = ensure_signed ( origin) ?;
371+
372+ let profile_id = pallet_profile:: Pallet :: < T > :: get_profile_id (
373+ & creator
374+ )
375+ . map_err ( <pallet_profile:: Error < T > >:: from) ?;
376+
377+ let doc_author_profile_id = pallet_profile:: Pallet :: < T > :: get_profile_id ( & doc_author_id)
378+ . map_err ( <pallet_profile:: Error < T > >:: from) ?;
379+
380+ let registry_id = registry:: create_registry_store :: < T > (
326381 tx_hash,
327382 doc_id,
328383 doc_author_profile_id,
@@ -331,7 +386,7 @@ pub mod pallet {
331386 ) ?;
332387
333388 Self :: deposit_event (
334- Event :: RegistryCreated {
389+ Event :: RegistryStoreCreated {
335390 registry : registry_id,
336391 creator, profile_id,
337392 }
@@ -360,7 +415,7 @@ pub mod pallet {
360415 /// * `RegistryArchived` - Emitted with `registry`, `authority`, `authority_profile_id`.
361416 ///
362417 /// ```
363- #[ pallet:: call_index( 3 ) ]
418+ #[ pallet:: call_index( 4 ) ]
364419 #[ pallet:: weight( { 10_000 } ) ]
365420 pub fn archive (
366421 origin : OriginFor < T > ,
@@ -404,7 +459,7 @@ pub mod pallet {
404459 /// * `RegistryRestored` - Emitted with `registry`, `authority`, `authority_profile_id`.
405460 ///
406461 /// ```
407- #[ pallet:: call_index( 4 ) ]
462+ #[ pallet:: call_index( 5 ) ]
408463 #[ pallet:: weight( { 10_000 } ) ]
409464 pub fn restore (
410465 origin : OriginFor < T > ,
@@ -448,7 +503,7 @@ pub mod pallet {
448503 /// * `RegistryUpdated` - Emitted with `registry`, `authority` (new author), `authority_profile_id`.
449504 ///
450505 /// ```
451- #[ pallet:: call_index( 5 ) ]
506+ #[ pallet:: call_index( 6 ) ]
452507 #[ pallet:: weight( { 10_000 } ) ]
453508 pub fn update_author (
454509 origin : OriginFor < T > ,
@@ -502,7 +557,7 @@ pub mod pallet {
502557 /// * `RegistryUpdated` - Emitted with `registry`, `authority` (new creator), `authority_profile_id`.
503558 ///
504559 /// ```
505- #[ pallet:: call_index( 6 ) ]
560+ #[ pallet:: call_index( 7 ) ]
506561 #[ pallet:: weight( { 10_000 } ) ]
507562 pub fn update_creator (
508563 origin : OriginFor < T > ,
@@ -556,7 +611,7 @@ pub mod pallet {
556611 /// * `RegistryUpdated` - Emitted with `registry`, `authority`, `authority_profile_id`.
557612 ///
558613 /// ```
559- #[ pallet:: call_index( 7 ) ]
614+ #[ pallet:: call_index( 8 ) ]
560615 #[ pallet:: weight( { 10_000 } ) ]
561616 pub fn update_registry_hash (
562617 origin : OriginFor < T > ,
0 commit comments