Skip to content

Commit

Permalink
feat: P-860 add logging support for dynamic contract (#2848)
Browse files Browse the repository at this point in the history
* feat: P-860 add logging support for dynamic contract

* fix: change vc_logs to optional in RequestVCResult, default log response in http precompile contract

* remove default log response in http precompile contract

* fix: update ts definition for dynamic assertion

* fix clippy

* fix: change type of return_log to bool, using Precompiles instead of thread_local variable DYNAMIC_ASSERTION_LOGS, only include vc_logs in rpc response

* add the log to vc_logs in all json_utils precompile contracts, do not return vc_logs if stf is true when using CLI

* return vc_logs if stf is true

* add logs in dynamic contract A20

---------

Co-authored-by: higherordertech <higherordertech>
  • Loading branch information
higherordertech committed Jul 5, 2024
1 parent fc1994c commit f40d5f6
Show file tree
Hide file tree
Showing 35 changed files with 732 additions and 195 deletions.
32 changes: 32 additions & 0 deletions primitives/core/src/assertion/dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::H160;
use sp_runtime::{traits::ConstU32, BoundedVec};

pub type DynamicContractParams = BoundedVec<u8, ConstU32<1024>>;

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub struct DynamicParams {
// smart contract code identifier
pub smart_contract_id: H160,
// abi encoded smart contract params
pub smart_contract_params: Option<DynamicContractParams>,
// true to return contract log
pub return_log: bool,
}
8 changes: 5 additions & 3 deletions primitives/core/src/assertion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ use web3_nft::Web3NftType;
pub mod web3_token;
use web3_token::Web3TokenType;

use crate::{AccountId, DynamicParams, ParameterString};
pub mod dynamic;
use dynamic::DynamicParams;

use crate::{AccountId, ParameterString};

use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::H160;
use sp_std::{vec, vec::Vec};

#[rustfmt::skip]
Expand Down Expand Up @@ -138,7 +140,7 @@ pub enum Assertion {
NftHolder(Web3NftType),

#[codec(index = 27)]
Dynamic(H160, DynamicParams) // smart contract code identifier, abi encoded smart contract params
Dynamic(DynamicParams)
}

impl Assertion {
Expand Down
2 changes: 0 additions & 2 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ pub use types::*;

pub type ParameterString = BoundedVec<u8, ConstU32<64>>;

pub type DynamicParams = BoundedVec<u8, ConstU32<1024>>;

/// Common types of parachains.
mod types {
use sp_runtime::{
Expand Down
110 changes: 79 additions & 31 deletions tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tee-worker/app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ where
if let Some(key) = maybe_key {
Ok(TrustedCallResult::RequestVC(RequestVCResult {
vc_payload: aes_encrypt_default(&key, &vc_payload),
vc_logs: None,
pre_mutated_id_graph: aes_encrypt_default(&key, &mutated_id_graph.encode()),
pre_id_graph_hash: id_graph_hash,
}))
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/app-libs/stf/src/trusted_call_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub struct SetIdentityNetworksResult {
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
pub struct RequestVCResult {
pub vc_payload: AesOutput,
// Mainly used to returning logs in dynamic contract VC.
pub vc_logs: Option<AesOutput>,
// see comments in `lc-vc-task-receiver` why it's prefixed with `pre...`
// they should be referenced/used only when the client's local IDGraph is empty
pub pre_mutated_id_graph: AesOutput,
Expand Down
Loading

0 comments on commit f40d5f6

Please sign in to comment.