From 68fc67044e4a23c1ef41b264f67f56b864410369 Mon Sep 17 00:00:00 2001 From: Francisco Silva Date: Wed, 30 Oct 2024 16:50:37 +0100 Subject: [PATCH] Adding create_account_store trusted call (#3152) --- .../identity/app-libs/stf/src/trusted_call.rs | 8 +++ .../core/native-task/receiver/src/lib.rs | 61 ++++++++++++------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/tee-worker/identity/app-libs/stf/src/trusted_call.rs b/tee-worker/identity/app-libs/stf/src/trusted_call.rs index 3b4a1763b0..809100a46c 100644 --- a/tee-worker/identity/app-libs/stf/src/trusted_call.rs +++ b/tee-worker/identity/app-libs/stf/src/trusted_call.rs @@ -141,6 +141,8 @@ pub enum TrustedCall { clean_id_graphs(Identity), #[codec(index = 26)] request_intent(Identity, Intent), + #[codec(index = 27)] + create_account_store(Identity), // original integritee trusted calls, starting from index 50 #[codec(index = 50)] @@ -232,6 +234,7 @@ impl TrustedCall { #[cfg(feature = "development")] Self::clean_id_graphs(sender_identity) => sender_identity, Self::request_intent(sender_identity, ..) => sender_identity, + Self::create_account_store(sender_identity) => sender_identity, } } @@ -246,6 +249,7 @@ impl TrustedCall { Self::activate_identity(..) => "activate_identity", Self::maybe_create_id_graph(..) => "maybe_create_id_graph", Self::request_intent(..) => "request_intent", + Self::create_account_store(..) => "create_account_store", _ => "unsupported_trusted_call", } } @@ -904,6 +908,10 @@ where error!("please use author_submitNativeRequest instead"); Ok(TrustedCallResult::Empty) }, + TrustedCall::create_account_store(..) => { + error!("please use author_submitNativeRequest instead"); + Ok(TrustedCallResult::Empty) + }, } } diff --git a/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs b/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs index 14dd419862..2af3952570 100644 --- a/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs +++ b/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs @@ -187,12 +187,24 @@ fn handle_trusted_call< }, }; - let (who, intent_call) = match call { + let create_dispatch_as_omni_account_call = |member_identity_hash: H256, call: OpaqueCall| { + OpaqueCall::from_tuple(&compose_call!( + &metadata, + "OmniAccount", + "dispatch_as_omni_account", + member_identity_hash, + call + )) + }; + + let opaque_call = match call { TrustedCall::request_intent(who, intent) => match intent { - Intent::SystemRemark(remark) => - (who, OpaqueCall::from_tuple(&compose_call!(&metadata, "System", "remark", remark))), - Intent::TransferNative(transfer) => ( - who, + Intent::SystemRemark(remark) => create_dispatch_as_omni_account_call( + who.hash(), + OpaqueCall::from_tuple(&compose_call!(&metadata, "System", "remark", remark)), + ), + Intent::TransferNative(transfer) => create_dispatch_as_omni_account_call( + who.hash(), OpaqueCall::from_tuple(&compose_call!( &metadata, "Balances", @@ -201,15 +213,26 @@ fn handle_trusted_call< transfer.value )), ), - Intent::CallEthereum(_) | Intent::TransferEthereum(_) => ( - who, - OpaqueCall::from_tuple(&compose_call!( - &metadata, - "OmniAccount", - "request_intent", - intent - )), - ), + Intent::CallEthereum(_) | Intent::TransferEthereum(_) => + create_dispatch_as_omni_account_call( + who.hash(), + OpaqueCall::from_tuple(&compose_call!( + &metadata, + "OmniAccount", + "request_intent", + intent + )), + ), + }, + TrustedCall::create_account_store(who) => { + let create_account_store_call = OpaqueCall::from_tuple(&compose_call!( + &metadata, + "OmniAccount", + "create_account_store", + who + )); + + create_account_store_call }, _ => { log::warn!("Received unsupported call: {:?}", call); @@ -220,15 +243,7 @@ fn handle_trusted_call< }, }; - let omni_account_call = OpaqueCall::from_tuple(&compose_call!( - &metadata, - "OmniAccount", - "dispatch_as_omni_account", - who.hash(), - intent_call - )); - - let extrinsic = match context.extrinsic_factory.create_extrinsics(&[omni_account_call], None) { + let extrinsic = match context.extrinsic_factory.create_extrinsics(&[opaque_call], None) { Ok(extrinsic) => extrinsic, Err(e) => { log::error!("Failed to create extrinsic: {:?}", e);