-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shielding parentchain transfers (#1378)
* Adding in the balance transfer filters * clippy and fmt * taplo * adding polkadot js transfer script for various transfer tests and some logging * cleanup for pr * adding privacy sidechain shielding to indirect executor * Adding in privacy shielding with runtime crash * fix merge error * [stf] migrate deprecated `set_balance` to `force_set_balance` * renaming and refactor * reorganizing and refactor for better code seperation * bump api-client after master merge * cargo fmt * making indirect_executor refactored to avoid cycles * make itp-utils purely no-std * make itp-utils purely no-std * code fixes after itp-utils change * fix enclave build * [itp-utils] fix test compilation * Fix enclave build in shielding parentchain transfer branch (#1482) * make itp-utils purely no-std * make itp-utils purely no-std * code fixes after itp-utils change * fix enclave build * [itp-utils] fix test compilation * adding integration test * clippy taplo fmt * avoid clash between //Alice unshielding and //Alice vault for shielding. * WIP causing cyclic dependency * plenty of refactoring. now no_std clash remaining * mostly fixed the mess. now failing high-level when build * mock for indirect call executor tests * fixed cargo test * cleanups * fixes * cargo fix in root * taplo fmt * toml feature cleanup. no effect * revert bogus fix * taplo fmt * fix trait bound build errors * cleanup * get rid of extern crate core again * get rid of sgx_tstd in itp-types * add enhancement todo comment --------- Co-authored-by: Christian Langenbacher <[email protected]> Co-authored-by: clangenb <[email protected]> Co-authored-by: Alain Brenzikofer <[email protected]> Co-authored-by: brenzi <[email protected]>
- Loading branch information
1 parent
ea0042f
commit 4689acf
Showing
48 changed files
with
1,825 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
[package] | ||
name = "ita-parentchain-interface" | ||
version = "0.9.0" | ||
authors = ["Integritee AG <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# sgx dependencies | ||
sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } | ||
sgx_types = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" } | ||
|
||
# local dependencies | ||
ita-sgx-runtime = { path = "../sgx-runtime", default-features = false } | ||
ita-stf = { path = "../stf", default-features = false } | ||
itc-parentchain-indirect-calls-executor = { path = "../../core/parentchain/indirect-calls-executor", default-features = false } | ||
itp-api-client-types = { path = "../../core-primitives/node-api/api-client-types", default-features = false } | ||
itp-node-api = { path = "../../core-primitives/node-api", default-features = false } | ||
itp-ocall-api = { path = "../../core-primitives/ocall-api", default-features = false } | ||
itp-sgx-crypto = { path = "../../core-primitives/sgx/crypto", default-features = false } | ||
itp-sgx-runtime-primitives = { path = "../../core-primitives/sgx-runtime-primitives", default-features = false } | ||
itp-stf-executor = { path = "../../core-primitives/stf-executor", default-features = false } | ||
itp-stf-primitives = { path = "../../core-primitives/stf-primitives", default-features = false } | ||
itp-top-pool-author = { path = "../../core-primitives/top-pool-author", default-features = false } | ||
itp-types = { path = "../../core-primitives/types", default-features = false } | ||
itp-utils = { path = "../../core-primitives/utils", default-features = false } | ||
|
||
# sgx enabled external libraries | ||
futures_sgx = { package = "futures", git = "https://github.com/mesalock-linux/futures-rs-sgx", optional = true } | ||
thiserror_sgx = { package = "thiserror", git = "https://github.com/mesalock-linux/thiserror-sgx", tag = "sgx_1.1.3", optional = true } | ||
|
||
# std compatible external libraries (make sure these versions match with the sgx-enabled ones above) | ||
futures = { version = "0.3.8", optional = true } | ||
thiserror = { version = "1.0", optional = true } | ||
|
||
# no-std compatible libraries | ||
bs58 = { version = "0.4.0", default-features = false, features = ["alloc"] } | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } | ||
log = { version = "0.4", default-features = false } | ||
|
||
# substrate dep | ||
binary-merkle-tree = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } | ||
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } | ||
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } | ||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } | ||
|
||
[dev-dependencies] | ||
env_logger = "0.9.0" | ||
itp-node-api = { path = "../../core-primitives/node-api", features = ["mocks"] } | ||
itp-sgx-crypto = { path = "../../core-primitives/sgx/crypto", features = ["mocks"] } | ||
itp-stf-executor = { path = "../../core-primitives/stf-executor", features = ["mocks"] } | ||
itp-test = { path = "../../core-primitives/test" } | ||
itp-top-pool-author = { path = "../../core-primitives/top-pool-author", features = ["mocks"] } | ||
itc-parentchain-test = { path = "../../core/parentchain/test" } | ||
|
||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"bs58/std", | ||
"codec/std", | ||
"futures", | ||
"ita-sgx-runtime/std", | ||
"ita-stf/std", | ||
"itc-parentchain-indirect-calls-executor/std", | ||
"itp-api-client-types/std", | ||
"itp-node-api/std", | ||
"itp-ocall-api/std", | ||
"itp-sgx-crypto/std", | ||
"itp-sgx-runtime-primitives/std", | ||
"itp-stf-executor/std", | ||
"itp-stf-primitives/std", | ||
"itp-top-pool-author/std", | ||
"itp-types/std", | ||
"itp-utils/std", | ||
"log/std", | ||
#substrate | ||
"binary-merkle-tree/std", | ||
"sp-core/std", | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"thiserror", | ||
] | ||
sgx = [ | ||
"sgx_tstd", | ||
"futures_sgx", | ||
"ita-stf/sgx", | ||
"itc-parentchain-indirect-calls-executor/sgx", | ||
"itp-node-api/sgx", | ||
"itp-sgx-crypto/sgx", | ||
"itp-stf-executor/sgx", | ||
"itp-top-pool-author/sgx", | ||
"thiserror_sgx", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app-libs/parentchain-interface/src/integritee/event_filter.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2021 Integritee AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
//! Various way to filter Parentchain events | ||
|
||
use itc_parentchain_indirect_calls_executor::event_filter::ToEvents; | ||
use itp_api_client_types::Events; | ||
|
||
use itp_types::{ | ||
parentchain::{ | ||
BalanceTransfer, ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents, | ||
}, | ||
H256, | ||
}; | ||
use std::vec::Vec; | ||
|
||
#[derive(Clone)] | ||
pub struct FilterableEvents(pub Events<H256>); | ||
|
||
// todo: improve: https://github.com/integritee-network/worker/pull/1378#discussion_r1393933766 | ||
impl ToEvents<Events<H256>> for FilterableEvents { | ||
fn to_events(&self) -> &Events<H256> { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<Events<H256>> for FilterableEvents { | ||
fn from(ev: Events<H256>) -> Self { | ||
Self(ev) | ||
} | ||
} | ||
|
||
impl FilterEvents for FilterableEvents { | ||
type Error = itc_parentchain_indirect_calls_executor::Error; | ||
|
||
fn get_extrinsic_statuses(&self) -> core::result::Result<Vec<ExtrinsicStatus>, Self::Error> { | ||
Ok(self | ||
.to_events() | ||
.iter() | ||
.filter_map(|ev| { | ||
ev.and_then(|ev| { | ||
if (ev.as_event::<ExtrinsicSuccess>()?).is_some() { | ||
return Ok(Some(ExtrinsicStatus::Success)) | ||
} | ||
|
||
if (ev.as_event::<ExtrinsicFailed>()?).is_some() { | ||
return Ok(Some(ExtrinsicStatus::Failed)) | ||
} | ||
|
||
Ok(None) | ||
}) | ||
.ok() | ||
.flatten() | ||
}) | ||
.collect()) | ||
} | ||
|
||
fn get_transfer_events(&self) -> core::result::Result<Vec<BalanceTransfer>, Self::Error> { | ||
Ok(self | ||
.to_events() | ||
.iter() | ||
.flatten() // flatten filters out the nones | ||
.filter_map(|ev| match ev.as_event::<BalanceTransfer>() { | ||
Ok(maybe_event) => { | ||
if maybe_event.is_none() { | ||
log::warn!("Transfer event does not exist in parentchain metadata"); | ||
}; | ||
maybe_event | ||
}, | ||
Err(e) => { | ||
log::error!("Could not decode event: {:?}", e); | ||
None | ||
}, | ||
}) | ||
.collect()) | ||
} | ||
} |
Oops, something went wrong.