|
@@ -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(())
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|