Procházet zdrojové kódy

make liaison Option in data object

Mokhtar Naamani před 4 roky
rodič
revize
fad04b7e2c

+ 9 - 12
runtime-modules/storage/src/data_directory.rs

@@ -76,9 +76,6 @@ decl_error! {
         /// Content with this ID not found.
         CidNotFound,
 
-        /// Only the liaison for the content may modify its status.
-        LiaisonRequired,
-
         /// Cannot create content for inactive or missing data object type.
         DataObjectTypeMustBeActive,
 
@@ -117,7 +114,7 @@ decl_error! {
     }
 }
 
-/// The decision of the storage provider when it acts as liaison.
+/// The status of the content which can be updated by a storage provider.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
 pub enum LiaisonJudgement {
@@ -169,10 +166,10 @@ pub struct DataObjectInternal<
     /// Content size in bytes.
     pub size: u64,
 
-    /// Storage provider id of the liaison.
-    pub liaison: StorageProviderId,
+    /// Storage provider which first accepted the content.
+    pub liaison: Option<StorageProviderId>,
 
-    /// Storage provider as liaison judgment.
+    /// The liaison judgment.
     pub liaison_judgement: LiaisonJudgement,
 
     /// IPFS content id.
@@ -416,7 +413,7 @@ decl_module! {
         type Error = Error<T>;
 
         /// Adds the content to the system. The created DataObject
-        /// awaits liaison to accept or reject it.
+        /// awaits liaison to accept it.
         #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_content(
             origin,
@@ -641,7 +638,8 @@ decl_module! {
         }
 
         /// Storage provider accepts a content. Requires signed storage provider account and its id.
-        /// The LiaisonJudgement can be updated, but only by the liaison.
+        /// The LiaisonJudgement can only be updated once from Pending to Accepted.
+        /// Subsequent calls are a no-op.
         #[weight = 10_000_000] // TODO: adjust weight
         pub(crate) fn accept_content(
             origin,
@@ -656,7 +654,7 @@ decl_module! {
 
             if data.liaison_judgement == LiaisonJudgement::Pending {
                 // Set the liaison which is updating the judgement
-                data.liaison = storage_provider_id;
+                data.liaison = Some(storage_provider_id);
 
                 // Set the judgement
                 data.liaison_judgement = LiaisonJudgement::Accepted;
@@ -798,8 +796,7 @@ impl<T: Trait> Module<T> {
                 size: content.size,
                 added_at: common::current_block_time::<T>(),
                 owner: owner.clone(),
-                // It is irrelevant what liaison is set when judgement is pending
-                liaison: StorageProviderId::<T>::default(),
+                liaison: None,
                 liaison_judgement: LiaisonJudgement::Pending,
                 ipfs_content_id: content.ipfs_content_id,
             };

+ 1 - 1
runtime-modules/storage/src/tests/mock.rs

@@ -111,7 +111,7 @@ impl ContentIdExists<Test> for MockContent {
                     time: 1024,
                 },
                 owner: StorageObjectOwner::Member(1),
-                liaison: TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID,
+                liaison: Some(TEST_MOCK_LIAISON_STORAGE_PROVIDER_ID),
                 liaison_judgement: data_directory::LiaisonJudgement::Pending,
                 ipfs_content_id: vec![],
             }),

+ 3 - 2
types/augment-codec/augment-api-tx.ts

@@ -368,12 +368,13 @@ declare module '@polkadot/api/types/submittable' {
     dataDirectory: {
       /**
        * Storage provider accepts a content. Requires signed storage provider account and its id.
-       * The LiaisonJudgement can be updated, but only by the liaison.
+       * The LiaisonJudgement can only be updated once from Pending to Accepted.
+       * Subsequent calls are a no-op.
        **/
       acceptContent: AugmentedSubmittable<(storageProviderId: StorageProviderId | AnyNumber | Uint8Array, contentId: ContentId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       /**
        * Adds the content to the system. The created DataObject
-       * awaits liaison to accept or reject it.
+       * awaits liaison to accept it.
        **/
       addContent: AugmentedSubmittable<(owner: ObjectOwner | { Member: any } | { Channel: any } | { DAO: any } | { Council: any } | { WorkingGroup: any } | string | Uint8Array, content: Vec<ContentParameters> | (ContentParameters | { content_id?: any; type_id?: any; ipfs_content_id?: any } | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
       /**

+ 1 - 1
types/augment/all/defs.json

@@ -493,7 +493,7 @@
         "added_at": "BlockAndTime",
         "type_id": "DataObjectTypeId",
         "size": "u64",
-        "liaison": "StorageProviderId",
+        "liaison": "Option<StorageProviderId>",
         "liaison_judgement": "LiaisonJudgement",
         "ipfs_content_id": "Text"
     },

+ 1 - 1
types/augment/all/types.ts

@@ -346,7 +346,7 @@ export interface DataObject extends Struct {
   readonly owner: StorageObjectOwner;
   readonly added_at: BlockAndTime;
   readonly type_id: DataObjectTypeId;
-  readonly liaison: StorageProviderId;
+  readonly liaison: Option<StorageProviderId>;
   readonly liaison_judgement: LiaisonJudgement;
   readonly ipfs_content_id: Text;
 }

+ 3 - 2
types/augment/augment-api-tx.ts

@@ -368,12 +368,13 @@ declare module '@polkadot/api/types/submittable' {
     dataDirectory: {
       /**
        * Storage provider accepts a content. Requires signed storage provider account and its id.
-       * The LiaisonJudgement can be updated, but only by the liaison.
+       * The LiaisonJudgement can only be updated once from Pending to Accepted.
+       * Subsequent calls are a no-op.
        **/
       acceptContent: AugmentedSubmittable<(storageProviderId: StorageProviderId | AnyNumber | Uint8Array, contentId: ContentId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
       /**
        * Adds the content to the system. The created DataObject
-       * awaits liaison to accept or reject it.
+       * awaits liaison to accept it.
        **/
       addContent: AugmentedSubmittable<(owner: ObjectOwner | { Member: any } | { Channel: any } | { DAO: any } | { Council: any } | { WorkingGroup: any } | string | Uint8Array, content: Vec<ContentParameters> | (ContentParameters | { content_id?: any; type_id?: any; ipfs_content_id?: any } | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
       /**

+ 2 - 2
types/src/storage.ts

@@ -1,4 +1,4 @@
-import { BTreeMap, u64, bool, Text, Null, Bytes } from '@polkadot/types'
+import { BTreeMap, u64, bool, Text, Null, Bytes, Option } from '@polkadot/types'
 import { BlockAndTime, JoyEnum, JoyStructDecorated, Hash, ChannelId, DAOId, WorkingGroup } from './common'
 import { MemberId } from './members'
 import { StorageProviderId } from './working-group' // this should be in discovery really
@@ -61,7 +61,7 @@ export class DataObject extends JoyStructDecorated({
   added_at: BlockAndTime,
   type_id: DataObjectTypeId,
   size: u64,
-  liaison: StorageProviderId,
+  liaison: Option.with(StorageProviderId),
   liaison_judgement: LiaisonJudgement,
   ipfs_content_id: Text,
 }) {