ソースを参照

Adjust broken transaction extrinsic

iorveth 4 年 前
コミット
0e3aab25e3

+ 2 - 0
runtime-modules/content-directory/src/errors.rs

@@ -103,3 +103,5 @@ pub const ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED: &str =
 pub const ERROR_NUMBER_OF_CURATORS_PER_GROUP_LIMIT_REACHED: &str =
     "Max number of curators per group limit reached";
 pub const ERROR_CURATOR_IS_NOT_ACTIVE: &str = "Curator group is not active";
+pub const ERROR_ORIGIN_CANNOT_BE_MADE_INTO_RAW_ORIGIN: &str =
+    "Origin cannot be made into raw origin";

+ 33 - 30
runtime-modules/content-directory/src/lib.rs

@@ -32,7 +32,7 @@ type MaxNumber = u32;
 /// Type, representing vector of vectors of all referenced entitity id`s
 type EntitiesRcVec<T> = Vec<Vec<<T as Trait>::EntityId>>;
 
-pub trait Trait: system::Trait + ActorAuthenticator + Debug {
+pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
     /// Nonce type is used to avoid data race update conditions, when performing property value vector operations
     type Nonce: Parameter
         + Member
@@ -1269,35 +1269,38 @@ decl_module! {
             Ok(())
         }
 
-        // pub fn transaction(origin, operations: Vec<Operation<T::Credential, T>>) -> dispatch::Result {
-        //     // This map holds the T::EntityId of the entity created as a result of executing a CreateEntity Operation
-        //     // keyed by the indexed of the operation, in the operations vector.
-        //     let mut entity_created_in_operation: BTreeMap<usize, T::EntityId> = BTreeMap::new();
-
-        //     let raw_origin = Self::ensure_root_or_signed(origin)?;
-
-        //     for (op_index, operation) in operations.into_iter().enumerate() {
-        //         match operation.operation_type {
-        //             OperationType::CreateEntity(create_entity_operation) => {
-        //                 let entity_id = Self::do_create_entity(&raw_origin, operation.with_credential, create_entity_operation.class_id)?;
-        //                 entity_created_in_operation.insert(op_index, entity_id);
-        //             },
-        //             OperationType::UpdatePropertyValues(update_property_values_operation) => {
-        //                 let entity_id = operations::parametrized_entity_to_entity_id(&entity_created_in_operation, update_property_values_operation.entity_id)?;
-        //                 let property_values = operations::parametrized_property_values_to_property_values(&entity_created_in_operation, update_property_values_operation.new_parametrized_property_values)?;
-        //                 Self::do_update_entity_property_values(&raw_origin, operation.with_credential, operation.as_entity_maintainer, entity_id, property_values)?;
-        //             },
-        //             OperationType::AddSchemaSupportToEntity(add_schema_support_to_entity_operation) => {
-        //                 let entity_id = operations::parametrized_entity_to_entity_id(&entity_created_in_operation, add_schema_support_to_entity_operation.entity_id)?;
-        //                 let schema_id = add_schema_support_to_entity_operation.schema_id;
-        //                 let property_values = operations::parametrized_property_values_to_property_values(&entity_created_in_operation, add_schema_support_to_entity_operation.parametrized_property_values)?;
-        //                 Self::do_add_schema_support_to_entity(&raw_origin, operation.with_credential, operation.as_entity_maintainer, entity_id, schema_id, property_values)?;
-        //             }
-        //         }
-        //     }
-
-        //     Ok(())
-        // }
+        pub fn transaction(origin, actor: Actor<T>, operations: Vec<OperationType<T>>) -> dispatch::Result {
+            // This map holds the T::EntityId of the entity created as a result of executing a CreateEntity Operation
+            // keyed by the indexed of the operation, in the operations vector.
+            let mut entity_created_in_operation: BTreeMap<usize, T::EntityId> = BTreeMap::new();
+            let raw_origin = origin.into().map_err(|_| ERROR_ORIGIN_CANNOT_BE_MADE_INTO_RAW_ORIGIN)?;
+
+            for (op_index, operation_type) in operations.into_iter().enumerate() {
+                let origin = T::Origin::from(raw_origin.clone());
+                let actor = actor.clone();
+                match operation_type {
+                    OperationType::CreateEntity(create_entity_operation) => {
+                        Self::create_entity(origin, create_entity_operation.class_id, actor)?;
+                        // entity id of newly created entity
+                        let entity_id = Self::next_entity_id() - T::EntityId::one();
+                        entity_created_in_operation.insert(op_index, entity_id);
+                    },
+                    OperationType::UpdatePropertyValues(update_property_values_operation) => {
+                        let entity_id = operations::parametrized_entity_to_entity_id(&entity_created_in_operation, update_property_values_operation.entity_id)?;
+                        let property_values = operations::parametrized_property_values_to_property_values(&entity_created_in_operation, update_property_values_operation.new_parametrized_property_values)?;
+                        Self::update_entity_property_values(origin, actor, entity_id, property_values)?;
+                    },
+                    OperationType::AddSchemaSupportToEntity(add_schema_support_to_entity_operation) => {
+                        let entity_id = operations::parametrized_entity_to_entity_id(&entity_created_in_operation, add_schema_support_to_entity_operation.entity_id)?;
+                        let schema_id = add_schema_support_to_entity_operation.schema_id;
+                        let property_values = operations::parametrized_property_values_to_property_values(&entity_created_in_operation, add_schema_support_to_entity_operation.parametrized_property_values)?;
+                        Self::add_schema_support_to_entity(origin, actor, entity_id, schema_id, property_values)?;
+                    }
+                }
+            }
+
+            Ok(())
+        }
     }
 }
 

+ 0 - 7
runtime-modules/content-directory/src/operations.rs

@@ -58,13 +58,6 @@ pub enum OperationType<T: Trait> {
     AddSchemaSupportToEntity(AddSchemaSupportToEntityOperation<T>),
 }
 
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
-pub struct Operation<Credential, T: Trait> {
-    pub with_credential: Option<Credential>,
-    pub as_entity_maintainer: bool,
-    pub operation_type: OperationType<T>,
-}
-
 pub fn parametrized_entity_to_entity_id<T: Trait>(
     created_entities: &BTreeMap<usize, T::EntityId>,
     entity: ParameterizedEntity<T>,