Browse Source

Transaction extrinsic: Hold entities id, created in operation in Vec container instead of BtreeMap

iorveth 4 years ago
parent
commit
9d0312aadf

+ 4 - 4
runtime-modules/content-directory/src/lib.rs

@@ -1460,11 +1460,11 @@ decl_module! {
         pub fn transaction(origin, actor: Actor<T>, operations: Vec<OperationType<T>>) -> dispatch::Result {
             Self::ensure_number_of_operations_during_atomic_batching_limit_not_reached(&operations)?;
             // 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();
+            // keyed by the index of the operation, in the operations vector.
+            let mut entity_created_in_operation = vec![];
             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() {
+            for operation_type in operations.into_iter() {
                 let origin = T::Origin::from(raw_origin.clone());
                 let actor = actor.clone();
                 match operation_type {
@@ -1472,7 +1472,7 @@ decl_module! {
                         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);
+                        entity_created_in_operation.push(entity_id);
                     },
                     OperationType::UpdatePropertyValues(update_property_values_operation) => {
                         let entity_id = operations::parametrized_entity_to_entity_id(

+ 5 - 5
runtime-modules/content-directory/src/operations.rs

@@ -59,7 +59,7 @@ pub enum OperationType<T: Trait> {
 }
 
 pub fn parametrized_entity_to_entity_id<T: Trait>(
-    created_entities: &BTreeMap<usize, T::EntityId>,
+    created_entities: &Vec<T::EntityId>,
     entity: ParameterizedEntity<T>,
 ) -> Result<T::EntityId, &'static str> {
     match entity {
@@ -67,14 +67,14 @@ pub fn parametrized_entity_to_entity_id<T: Trait>(
         ParameterizedEntity::InternalEntityJustAdded(op_index_u32) => {
             let op_index = op_index_u32 as usize;
             Ok(*created_entities
-                .get(&op_index)
+                .get(op_index)
                 .ok_or("EntityNotCreatedByOperation")?)
         }
     }
 }
 
 pub fn parametrized_property_values_to_property_values<T: Trait>(
-    created_entities: &BTreeMap<usize, T::EntityId>,
+    created_entities: &Vec<T::EntityId>,
     parametrized_property_values: Vec<ParametrizedClassPropertyValue<T>>,
 ) -> Result<BTreeMap<PropertyId, PropertyValue<T>>, &'static str> {
     let mut class_property_values = BTreeMap::new();
@@ -88,7 +88,7 @@ pub fn parametrized_property_values_to_property_values<T: Trait>(
                 // Verify that referenced entity was indeed created created
                 let op_index = entity_created_in_operation_index as usize;
                 let entity_id = created_entities
-                    .get(&op_index)
+                    .get(op_index)
                     .ok_or("EntityNotCreatedByOperation")?;
                 PropertyValue::Single(SinglePropertyValue::new(Value::Reference(*entity_id)))
             }
@@ -103,7 +103,7 @@ pub fn parametrized_property_values_to_property_values<T: Trait>(
                         ) => {
                             let op_index = entity_created_in_operation_index as usize;
                             let entity_id = created_entities
-                                .get(&op_index)
+                                .get(op_index)
                                 .ok_or("EntityNotCreatedByOperation")?;
                             entities.push(*entity_id);
                         }

+ 1 - 0
runtime-modules/content-directory/src/schema.rs

@@ -324,6 +324,7 @@ impl<T: Trait> VecPropertyValue<T> {
             VecValue::Text(vec) => *vec = vec![],
             VecValue::Reference(vec) => *vec = vec![],
         }
+
         self.increment_nonce();
     }