Skip to content

Commit

Permalink
remove parachain dependency on tee (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
kziemianek committed Jan 26, 2024
1 parent e6cfa16 commit 8737753
Show file tree
Hide file tree
Showing 48 changed files with 365 additions and 248 deletions.
71 changes: 56 additions & 15 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ members = [
'precompiles/*',
'primitives/common',
'primitives/core',
'primitives/core/proc-macros',
'primitives/core/macros',
'primitives/hex',
'primitives/sidechain',
'primitives/teeracle',
'primitives/teerex',
Expand Down
4 changes: 2 additions & 2 deletions primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }

itp-utils = { path = "../../tee-worker/core-primitives/utils", default-features = false }
litentry-hex-utils = { path = "../hex", default-features = false }
litentry-macros = { path = "macros" }
litentry-proc-macros = { path = "proc-macros" }

[features]
default = ["std"]
Expand All @@ -35,6 +36,5 @@ std = [
"sp-std/std",
"sp-io/std",
"ring/std",
"itp-utils/std",
"pallet-evm/std",
]
8 changes: 0 additions & 8 deletions primitives/core/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ description = 'Proc-macros used by Litentry crates.'
name = "litentry-macros"
version = "0.9.12"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = { version = "1" }
quote = { version = "1" }
syn = { version = "2", features = ["full", "visit-mut"] }
93 changes: 18 additions & 75 deletions primitives/core/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,24 @@
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

#![allow(clippy::tabs_in_doc_comments)]

use proc_macro::TokenStream;
use reuse::handle_reuse;
use syn::{parse_macro_input, Error};

mod reuse;

/**
This macro is used to reuse implementations when the rust's trait system cannot gracefully express the abstraction.
This works similar with `#[cfg(..)]` that sets the target only appear on the specified cases.
# Usage:
```
use litentry_macros::reuse;
#[reuse(x, y)] . // Define the cases that the following implementation expands for each one
mod __ { // Leave mod name with double discards, which is to be replaced by the cases
#[x] // This item would only appear on case `x`
fn u() {
__
}
#[y] // This item would only appear on case `y`
fn v(a: String) {
println!("hello world!")
}
#[x] // Specifying multiple cases indicates that the item would appear on all of them
#[y] .// This behaviour is designed to be different from `#[cfg(..)]`
fn a() -> i32 {
#[x] // This statement would only appear on case `x`
let p = 1;
#[y] // This statement would only appear on case `y`
let p = 2;
p + 1
}
fn g<#[x] 'a, #[y] T>(#[x] a: i32, #[y] a: u32) {}
}
```
Expands to:
```
mod x {
fn a() -> i32 {
let p = 1;
p + 1
}
fn u() {
println!("hello world!");
}
fn g<'a>(a: i32) {}
}
mod y {
fn a() -> i32 {
let p = 2;
p + 1
}
fn v(a: String) {
println!("hello world!");
}
fn g<T>(a: u32) {}
#![cfg_attr(not(feature = "std"), no_std)]

#[macro_export]
macro_rules! if_production_or {
($prod_variant:expr, $non_prod_variant:expr) => {
if cfg!(feature = "production") {
$prod_variant
} else {
$non_prod_variant
}
};
}

```
*/
#[proc_macro_attribute]
pub fn reuse(args: TokenStream, input: TokenStream) -> TokenStream {
handle_reuse(parse_macro_input!(args), parse_macro_input!(input))
.unwrap_or_else(Error::into_compile_error)
.into()
#[macro_export]
macro_rules! if_not_production {
($expression:expr) => {
if cfg!(not(feature = "production")) {
$expression
}
};
}
15 changes: 15 additions & 0 deletions primitives/core/proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
authors = ['Trust Computing GmbH <info@litentry.com>']
description = 'Proc-macros used by Litentry crates.'
name = "litentry-proc-macros"
version = "0.9.12"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
cargo_toml = "0.16.3"
proc-macro2 = { version = "1" }
quote = { version = "1" }
syn = { version = "2", features = ["full", "visit-mut"] }
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,86 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

#![allow(clippy::tabs_in_doc_comments)]

use cargo_toml::{Dependency, Manifest};
use proc_macro::TokenStream;
use quote::quote;
use reuse::handle_reuse;
use std::fs;
use syn::{parse_macro_input, Error};

mod reuse;

/**
This macro is used to reuse implementations when the rust's trait system cannot gracefully express the abstraction.
This works similar with `#[cfg(..)]` that sets the target only appear on the specified cases.
# Usage:
```
use litentry_proc_macros::reuse;
#[reuse(x, y)] . // Define the cases that the following implementation expands for each one
mod __ { // Leave mod name with double discards, which is to be replaced by the cases
#[x] // This item would only appear on case `x`
fn u() {
__
}
#[y] // This item would only appear on case `y`
fn v(a: String) {
println!("hello world!")
}
#[x] // Specifying multiple cases indicates that the item would appear on all of them
#[y] .// This behaviour is designed to be different from `#[cfg(..)]`
fn a() -> i32 {
#[x] // This statement would only appear on case `x`
let p = 1;
#[y] // This statement would only appear on case `y`
let p = 2;
p + 1
}
fn g<#[x] 'a, #[y] T>(#[x] a: i32, #[y] a: u32) {}
}
```
Expands to:
```
mod x {
fn a() -> i32 {
let p = 1;
p + 1
}
fn u() {
println!("hello world!");
}
fn g<'a>(a: i32) {}
}
mod y {
fn a() -> i32 {
let p = 2;
p + 1
}
fn v(a: String) {
println!("hello world!");
}
fn g<T>(a: u32) {}
}
```
*/
#[proc_macro_attribute]
pub fn reuse(args: TokenStream, input: TokenStream) -> TokenStream {
handle_reuse(parse_macro_input!(args), parse_macro_input!(input))
.unwrap_or_else(Error::into_compile_error)
.into()
}

#[proc_macro]
pub fn local_modules(_item: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -46,7 +122,8 @@ fn read_module_names(path: &str, relative_to: &str, module_names: &mut Vec<Strin
// skip package if it is unnamed or it was already visited
if !package.name.is_empty() && !module_names.contains(&module_name) {
module_names.push(module_name);
// go through all dependencies and visit the ones that has `path`, which means they are local
// go through all dependencies and visit the ones that has `path`, which means they are
// local
manifest.dependencies.values().for_each(|dep| {
if let Dependency::Detailed(details) = dep {
if let Some(path) = &details.path {
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions primitives/core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ use crate::{
use alloc::{format, str, string::String};
use codec::{Decode, Encode, Error, Input, MaxEncodedLen};
use core::fmt::{Debug, Formatter};
use itp_utils::{
hex::{decode_hex, hex_encode},
if_production_or,
};
use litentry_hex_utils::{decode_hex, hex_encode};
use litentry_macros::if_production_or;
use pallet_evm::{AddressMapping, HashedAddressMapping as GenericHashedAddressMapping};
use scale_info::{meta_type, Type, TypeDefSequence, TypeInfo};
use sp_core::{
Expand Down
Loading

0 comments on commit 8737753

Please sign in to comment.