From 1ed6bb3177da08fdbcae2ad047e97c0e8444b4eb Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 7 Feb 2025 12:41:37 +0100 Subject: [PATCH] listen to ForeignAssets.Transferred events on target_b --- Cargo.lock | 9 +- app-libs/parentchain-interface/Cargo.toml | 1 + .../src/integritee/event_filter.rs | 9 +- .../src/integritee/event_handler.rs | 5 +- app-libs/parentchain-interface/src/lib.rs | 1 + .../src/target_a/event_filter.rs | 9 +- .../src/target_a/event_handler.rs | 5 +- .../src/target_b/event_filter.rs | 9 +- .../src/target_b/event_handler.rs | 72 +++++-- app-libs/sgx-runtime/src/lib.rs | 9 +- .../sgx-runtime-primitives/src/types.rs | 2 + core-primitives/types/src/lib.rs | 1 + core-primitives/types/src/parentchain.rs | 49 ++++- core-primitives/types/src/xcm.rs | 193 ++++++++++++++++++ .../indirect-calls-executor/src/mock.rs | 11 +- enclave-runtime/Cargo.lock | 9 +- 16 files changed, 347 insertions(+), 47 deletions(-) create mode 100644 core-primitives/types/src/xcm.rs diff --git a/Cargo.lock b/Cargo.lock index 58f26e8139..201b5f80c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2227,6 +2227,12 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "hmac" version = "0.8.1" @@ -2788,6 +2794,7 @@ version = "0.9.0" dependencies = [ "bs58", "env_logger 0.9.3", + "hex-literal 0.4.1", "ita-sgx-runtime", "ita-stf", "itc-parentchain", @@ -6862,7 +6869,7 @@ dependencies = [ "der 0.6.1", "frame-support", "hex", - "hex-literal", + "hex-literal 0.3.4", "log 0.4.22", "parity-scale-codec", "ring 0.16.20", diff --git a/app-libs/parentchain-interface/Cargo.toml b/app-libs/parentchain-interface/Cargo.toml index 2ac630a82a..cc5cecf557 100644 --- a/app-libs/parentchain-interface/Cargo.toml +++ b/app-libs/parentchain-interface/Cargo.toml @@ -24,6 +24,7 @@ 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 } regex = { optional = true, version = "1.9.5" } +hex-literal = "0.4.1" substrate-api-client = { default-features = false, git = "https://github.com/encointer/substrate-api-client.git", branch = "v0.9.42-tag-v0.14.0-retracted-check-metadata-hash" } diff --git a/app-libs/parentchain-interface/src/integritee/event_filter.rs b/app-libs/parentchain-interface/src/integritee/event_filter.rs index d403a93948..ba724a3356 100644 --- a/app-libs/parentchain-interface/src/integritee/event_filter.rs +++ b/app-libs/parentchain-interface/src/integritee/event_filter.rs @@ -19,10 +19,9 @@ use itc_parentchain_indirect_calls_executor::event_filter::ToEvents; use itp_api_client_types::Events; +use crate::StaticEvent; use itp_types::{ - parentchain::{ - BalanceTransfer, ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents, - }, + parentchain::{ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents}, H256, }; use std::vec::Vec; @@ -68,12 +67,12 @@ impl FilterEvents for FilterableEvents { .collect()) } - fn get_transfer_events(&self) -> core::result::Result, Self::Error> { + fn get_events(&self) -> core::result::Result, Self::Error> { Ok(self .to_events() .iter() .flatten() // flatten filters out the nones - .filter_map(|ev| match ev.as_event::() { + .filter_map(|ev| match ev.as_event::() { Ok(maybe_event) => maybe_event, Err(e) => { log::error!("Could not decode event: {:?}", e); diff --git a/app-libs/parentchain-interface/src/integritee/event_handler.rs b/app-libs/parentchain-interface/src/integritee/event_handler.rs index 57ec9557f9..b38ed9b8e8 100644 --- a/app-libs/parentchain-interface/src/integritee/event_handler.rs +++ b/app-libs/parentchain-interface/src/integritee/event_handler.rs @@ -22,7 +22,8 @@ use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; use itp_types::parentchain::{ - AccountId, FilterEvents, HandleParentchainEvents, ParentchainError, ParentchainId, + AccountId, BalanceTransfer, FilterEvents, HandleParentchainEvents, ParentchainError, + ParentchainId, }; use itp_utils::hex::hex_encode; use log::*; @@ -65,7 +66,7 @@ where events: impl FilterEvents, vault_account: &AccountId, ) -> Result<(), Error> { - let filter_events = events.get_transfer_events(); + let filter_events = events.get_events::(); trace!( "filtering transfer events to shard vault account: {}", hex_encode(vault_account.encode().as_slice()) diff --git a/app-libs/parentchain-interface/src/lib.rs b/app-libs/parentchain-interface/src/lib.rs index ac33abd913..3fbd2727be 100644 --- a/app-libs/parentchain-interface/src/lib.rs +++ b/app-libs/parentchain-interface/src/lib.rs @@ -18,6 +18,7 @@ #![cfg_attr(all(not(target_env = "sgx"), not(feature = "std")), no_std)] #![cfg_attr(target_env = "sgx", feature(rustc_private))] +extern crate alloc; #[cfg(all(not(feature = "std"), feature = "sgx"))] extern crate sgx_tstd as std; diff --git a/app-libs/parentchain-interface/src/target_a/event_filter.rs b/app-libs/parentchain-interface/src/target_a/event_filter.rs index 6e049fe740..b6fb62a41d 100644 --- a/app-libs/parentchain-interface/src/target_a/event_filter.rs +++ b/app-libs/parentchain-interface/src/target_a/event_filter.rs @@ -19,10 +19,9 @@ use itc_parentchain_indirect_calls_executor::event_filter::ToEvents; use itp_api_client_types::Events; +use crate::StaticEvent; use itp_types::{ - parentchain::{ - BalanceTransfer, ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents, - }, + parentchain::{ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents}, H256, }; use std::vec::Vec; @@ -67,12 +66,12 @@ impl FilterEvents for FilterableEvents { .collect()) } - fn get_transfer_events(&self) -> core::result::Result, Self::Error> { + fn get_events(&self) -> core::result::Result, Self::Error> { Ok(self .to_events() .iter() .flatten() // flatten filters out the nones - .filter_map(|ev| match ev.as_event::() { + .filter_map(|ev| match ev.as_event::() { Ok(maybe_event) => maybe_event, Err(e) => { log::error!("Could not decode event: {:?}", e); diff --git a/app-libs/parentchain-interface/src/target_a/event_handler.rs b/app-libs/parentchain-interface/src/target_a/event_handler.rs index c9da4ae377..c93439fb42 100644 --- a/app-libs/parentchain-interface/src/target_a/event_handler.rs +++ b/app-libs/parentchain-interface/src/target_a/event_handler.rs @@ -22,7 +22,8 @@ use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; use itp_types::parentchain::{ - AccountId, FilterEvents, HandleParentchainEvents, ParentchainError, ParentchainId, + AccountId, BalanceTransfer, FilterEvents, HandleParentchainEvents, ParentchainError, + ParentchainId, }; use itp_utils::hex::hex_encode; use log::*; @@ -65,7 +66,7 @@ where events: impl FilterEvents, vault_account: &AccountId, ) -> Result<(), Error> { - let filter_events = events.get_transfer_events(); + let filter_events = events.get_events::(); trace!( "[TargetA] filtering transfer events to shard vault account: {}", hex_encode(vault_account.encode().as_slice()) diff --git a/app-libs/parentchain-interface/src/target_b/event_filter.rs b/app-libs/parentchain-interface/src/target_b/event_filter.rs index 6e049fe740..b6fb62a41d 100644 --- a/app-libs/parentchain-interface/src/target_b/event_filter.rs +++ b/app-libs/parentchain-interface/src/target_b/event_filter.rs @@ -19,10 +19,9 @@ use itc_parentchain_indirect_calls_executor::event_filter::ToEvents; use itp_api_client_types::Events; +use crate::StaticEvent; use itp_types::{ - parentchain::{ - BalanceTransfer, ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents, - }, + parentchain::{ExtrinsicFailed, ExtrinsicStatus, ExtrinsicSuccess, FilterEvents}, H256, }; use std::vec::Vec; @@ -67,12 +66,12 @@ impl FilterEvents for FilterableEvents { .collect()) } - fn get_transfer_events(&self) -> core::result::Result, Self::Error> { + fn get_events(&self) -> core::result::Result, Self::Error> { Ok(self .to_events() .iter() .flatten() // flatten filters out the nones - .filter_map(|ev| match ev.as_event::() { + .filter_map(|ev| match ev.as_event::() { Ok(maybe_event) => maybe_event, Err(e) => { log::error!("Could not decode event: {:?}", e); diff --git a/app-libs/parentchain-interface/src/target_b/event_handler.rs b/app-libs/parentchain-interface/src/target_b/event_handler.rs index ace4fedc7a..7e55b4cca3 100644 --- a/app-libs/parentchain-interface/src/target_b/event_handler.rs +++ b/app-libs/parentchain-interface/src/target_b/event_handler.rs @@ -15,12 +15,22 @@ */ use codec::Encode; -use ita_sgx_runtime::Balance; +use hex_literal::hex; +use ita_sgx_runtime::{AssetId, Balance}; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; -use itp_types::parentchain::{ - AccountId, FilterEvents, HandleParentchainEvents, ParentchainError, ParentchainId, +use itp_types::{ + parentchain::{ + AccountId, BalanceTransfer, FilterEvents, ForeignAssetsTransferred, + HandleParentchainEvents, ParentchainError, ParentchainId, + }, + xcm::{ + Junction::{AccountKey20, GlobalConsensus}, + Junctions::X2, + Location, + NetworkId::Ethereum, + }, }; use itp_utils::hex::hex_encode; use log::*; @@ -63,21 +73,59 @@ where events: impl FilterEvents, vault_account: &AccountId, ) -> Result<(), Error> { - let filter_events = events.get_transfer_events(); trace!( - "[TargetB] filtering transfer events to shard vault account: {}", + "[TargetB] filtering balance transfer events to shard vault account: {}", hex_encode(vault_account.encode().as_slice()) ); + let filter_events = events.get_events::(); if let Ok(events) = filter_events { events - .iter() - .filter(|&event| event.to == *vault_account) - .try_for_each(|event| { - info!("[TargetB] found transfer event to shard vault account: {} will shield to {}", event.amount, hex_encode(event.from.encode().as_ref())); - Self::shield_funds(executor, &event.from, event.amount) - }) - .map_err(|_| ParentchainError::ShieldFundsFailure)?; + .iter() + .filter(|&event| event.to == *vault_account) + .try_for_each(|event| { + info!("[TargetB] found balance transfer event to shard vault account: {} will shield to {}", event.amount, hex_encode(event.from.encode().as_ref())); + Self::shield_funds(executor, &event.from, event.amount) + }) + .map_err(|_| ParentchainError::ShieldFundsFailure)?; } + trace!( + "[TargetB] filtering foreign assets transferred events to shard vault account: {}", + hex_encode(vault_account.encode().as_slice()) + ); + let filter_asset_events = events.get_events::(); + if let Ok(events) = filter_asset_events { + events + .iter() + .filter(|&event| event.to == *vault_account) + .try_for_each(|event| { + let stf_asset_id = location_to_sgx_runtime_asset_id(&event.asset_id); + info!("[TargetB] found foreign assets ({:?}) transferred event to shard vault account: {} will shield to {}", stf_asset_id, event.amount, hex_encode(event.from.encode().as_ref())); + + //Self::shield_assets(executor, location_to_sgx_runtime_asset_id(&event.asset_id), &event.from, event.amount) + Ok(()) + }) + .map_err(|_: Error| ParentchainError::ShieldFundsFailure)?; + } + Ok(()) } } + +const USDC_E_CONTRACT_ADDRESS: [u8; 20] = hex!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"); + +fn location_to_sgx_runtime_asset_id(location: &Location) -> Option { + if location.parents == 2 { + if let X2(junctions) = &location.interior { + match junctions.as_slice() { + [GlobalConsensus(Ethereum { chain_id: 1 }), AccountKey20 { key: contract, network: None }] + if *contract == USDC_E_CONTRACT_ADDRESS => + Some(1), + _ => None, + } + } else { + None + } + } else { + None + } +} diff --git a/app-libs/sgx-runtime/src/lib.rs b/app-libs/sgx-runtime/src/lib.rs index 2fd4a756b7..19f5a31a75 100644 --- a/app-libs/sgx-runtime/src/lib.rs +++ b/app-libs/sgx-runtime/src/lib.rs @@ -54,7 +54,8 @@ use sp_version::RuntimeVersion; pub use itp_sgx_runtime_primitives::{ constants::SLOT_DURATION, types::{ - AccountData, AccountId, Address, Balance, BlockNumber, Hash, Header, Index, Signature, + AccountData, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header, Index, + Signature, }, }; @@ -71,7 +72,7 @@ pub use frame_support::{ StorageValue, }; use frame_support::{ - traits::{AsEnsureOriginWithArg, ConstU128, ConstU64, ConstU8, EitherOfDiverse}, + traits::{AsEnsureOriginWithArg, ConstU128, ConstU8, EitherOfDiverse}, PalletId, }; use frame_system::{EnsureRoot, EnsureSignedBy}; @@ -341,8 +342,8 @@ impl pallet_session_proxy::Config for Runtime { impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = u64; - type AssetId = u32; - type AssetIdParameter = codec::Compact; + type AssetId = AssetId; + type AssetIdParameter = codec::Compact; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; diff --git a/core-primitives/sgx-runtime-primitives/src/types.rs b/core-primitives/sgx-runtime-primitives/src/types.rs index 035ae982b8..83362d107d 100644 --- a/core-primitives/sgx-runtime-primitives/src/types.rs +++ b/core-primitives/sgx-runtime-primitives/src/types.rs @@ -60,6 +60,8 @@ pub type DigestItem = generic::DigestItem; /// A type to hold UTC unix epoch [ms] pub type Moment = u64; +pub type AssetId = u32; + pub type Block = BlockG; pub type SignedBlock = SignedBlockG; pub type BlockHash = sp_core::H256; diff --git a/core-primitives/types/src/lib.rs b/core-primitives/types/src/lib.rs index 1417414714..b1b3bf8a8e 100644 --- a/core-primitives/types/src/lib.rs +++ b/core-primitives/types/src/lib.rs @@ -25,6 +25,7 @@ use sp_std::vec::Vec; pub mod parentchain; pub mod storage; +pub mod xcm; /// Substrate runtimes provide no string type. Hence, for arbitrary data of varying length the /// `Vec` is used. In the polkadot-js the typedef `Text` is used to automatically diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index fc65172d3d..1e83b5caf8 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -15,7 +15,7 @@ */ -use crate::{OpaqueCall, PalletString, ShardIdentifier}; +use crate::{xcm::Location, OpaqueCall, PalletString, ShardIdentifier}; use alloc::{format, vec::Vec}; use codec::{Decode, Encode}; use core::fmt::Debug; @@ -37,6 +37,7 @@ use substrate_api_client::{ }; use teeracle_primitives::ExchangeRate; use teerex_primitives::{SgxAttestationMethod, SgxStatus}; + pub type StorageProof = Vec>; // Basic Types. @@ -100,7 +101,9 @@ pub trait FilterEvents { type Error: From + core::fmt::Debug; fn get_extrinsic_statuses(&self) -> core::result::Result, Self::Error>; - fn get_transfer_events(&self) -> core::result::Result, Self::Error>; + fn get_events( + &self, + ) -> core::result::Result, Self::Error>; } #[derive(Encode, Decode, Debug)] @@ -156,11 +159,53 @@ impl core::fmt::Display for BalanceTransfer { } } +impl Default for BalanceTransfer { + fn default() -> Self { + BalanceTransfer { from: [0u8; 32].into(), to: [0u8; 32].into(), amount: 0 } + } +} + impl StaticEvent for BalanceTransfer { const PALLET: &'static str = "Balances"; const EVENT: &'static str = "Transfer"; } +#[derive(Encode, Decode, Debug)] +pub struct ForeignAssetsTransferred { + pub asset_id: Location, + pub from: AccountId, + pub to: AccountId, + pub amount: Balance, +} + +impl core::fmt::Display for ForeignAssetsTransferred { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + let message = format!( + "ForeignAssetsTransferred :: asset: {:?}, from: {}, to: {}, amount: {}", + &self.asset_id, + account_id_to_string::(&self.from), + account_id_to_string::(&self.to), + self.amount + ); + write!(f, "{}", message) + } +} + +impl Default for ForeignAssetsTransferred { + fn default() -> Self { + ForeignAssetsTransferred { + asset_id: Default::default(), + from: [0u8; 32].into(), + to: [0u8; 32].into(), + amount: 0, + } + } +} +impl StaticEvent for ForeignAssetsTransferred { + const PALLET: &'static str = "ForeignAssets"; + const EVENT: &'static str = "Transferred"; +} + #[derive(Encode, Decode, Debug)] pub struct AddedSgxEnclave { pub registered_by: AccountId, diff --git a/core-primitives/types/src/xcm.rs b/core-primitives/types/src/xcm.rs new file mode 100644 index 0000000000..dc0340836a --- /dev/null +++ b/core-primitives/types/src/xcm.rs @@ -0,0 +1,193 @@ +// this is a backport of XCMv4 types + +use codec::{Decode, Encode}; +use sp_std::sync::Arc; + +/// XCMv4 Junctions +#[derive(Encode, Decode, Debug)] +pub struct Location { + /// The number of parent junctions at the beginning of this `Location`. + pub parents: u8, + /// The interior (i.e. non-parent) junctions that this `Location` contains. + pub interior: Junctions, +} + +impl Default for Location { + fn default() -> Self { + Self { parents: 0, interior: Junctions::Here } + } +} + +#[derive(Encode, Decode, Debug)] +/// XCMv4 Junctions +pub enum Junctions { + /// The interpreting consensus system. + Here, + /// A relative path comprising 1 junction. + X1(Arc<[Junction; 1]>), + /// A relative path comprising 2 junctions. + X2(Arc<[Junction; 2]>), + /// A relative path comprising 3 junctions. + X3(Arc<[Junction; 3]>), + /// A relative path comprising 4 junctions. + X4(Arc<[Junction; 4]>), + /// A relative path comprising 5 junctions. + X5(Arc<[Junction; 5]>), + /// A relative path comprising 6 junctions. + X6(Arc<[Junction; 6]>), + /// A relative path comprising 7 junctions. + X7(Arc<[Junction; 7]>), + /// A relative path comprising 8 junctions. + X8(Arc<[Junction; 8]>), +} + +/// XCMv4 Junction +#[derive(Encode, Decode, Debug)] +pub enum Junction { + /// An indexed parachain belonging to and operated by the context. + /// + /// Generally used when the context is a Polkadot Relay-chain. + Parachain(#[codec(compact)] u32), + /// A 32-byte identifier for an account of a specific network that is respected as a sovereign + /// endpoint within the context. + /// + /// Generally used when the context is a Substrate-based chain. + AccountId32 { network: Option, id: [u8; 32] }, + /// An 8-byte index for an account of a specific network that is respected as a sovereign + /// endpoint within the context. + /// + /// May be used when the context is a Frame-based chain and includes e.g. an indices pallet. + AccountIndex64 { + network: Option, + #[codec(compact)] + index: u64, + }, + /// A 20-byte identifier for an account of a specific network that is respected as a sovereign + /// endpoint within the context. + /// + /// May be used when the context is an Ethereum or Bitcoin chain or smart-contract. + AccountKey20 { network: Option, key: [u8; 20] }, + /// An instanced, indexed pallet that forms a constituent part of the context. + /// + /// Generally used when the context is a Frame-based chain. + // TODO XCMv4 inner should be `Compact`. + PalletInstance(u8), + /// A non-descript index within the context location. + /// + /// Usage will vary widely owing to its generality. + /// + /// NOTE: Try to avoid using this and instead use a more specific item. + GeneralIndex(#[codec(compact)] u128), + /// A nondescript array datum, 32 bytes, acting as a key within the context + /// location. + /// + /// Usage will vary widely owing to its generality. + /// + /// NOTE: Try to avoid using this and instead use a more specific item. + // Note this is implemented as an array with a length rather than using `BoundedVec` owing to + // the bound for `Copy`. + GeneralKey { length: u8, data: [u8; 32] }, + /// The unambiguous child. + /// + /// Not currently used except as a fallback when deriving context. + OnlyChild, + /// A pluralistic body existing within consensus. + /// + /// Typical to be used to represent a governance origin of a chain, but could in principle be + /// used to represent things such as multisigs also. + Plurality { id: BodyId, part: BodyPart }, + /// A global network capable of externalizing its own consensus. This is not generally + /// meaningful outside of the universal level. + GlobalConsensus(NetworkId), +} + +#[derive(Encode, Decode, Debug)] +pub enum NetworkId { + /// Network specified by the first 32 bytes of its genesis block. + ByGenesis([u8; 32]), + /// Network defined by the first 32-bytes of the hash and number of some block it contains. + ByFork { block_number: u64, block_hash: [u8; 32] }, + /// The Polkadot mainnet Relay-chain. + Polkadot, + /// The Kusama canary-net Relay-chain. + Kusama, + /// The Westend testnet Relay-chain. + Westend, + /// The Rococo testnet Relay-chain. + Rococo, + /// The Wococo testnet Relay-chain. + Wococo, + /// An Ethereum network specified by its chain ID. + Ethereum { + /// The EIP-155 chain ID. + #[codec(compact)] + chain_id: u64, + }, + /// The Bitcoin network, including hard-forks supported by Bitcoin Core development team. + BitcoinCore, + /// The Bitcoin network, including hard-forks supported by Bitcoin Cash developers. + BitcoinCash, + /// The Polkadot Bulletin chain. + PolkadotBulletin, +} + +#[derive(Encode, Decode, Debug)] +pub enum BodyId { + /// The only body in its context. + Unit, + /// A named body. + Moniker([u8; 4]), + /// An indexed body. + Index(#[codec(compact)] u32), + /// The unambiguous executive body (for Polkadot, this would be the Polkadot council). + Executive, + /// The unambiguous technical body (for Polkadot, this would be the Technical Committee). + Technical, + /// The unambiguous legislative body (for Polkadot, this could be considered the opinion of a + /// majority of lock-voters). + Legislative, + /// The unambiguous judicial body (this doesn't exist on Polkadot, but if it were to get a + /// "grand oracle", it may be considered as that). + Judicial, + /// The unambiguous defense body (for Polkadot, an opinion on the topic given via a public + /// referendum on the `staking_admin` track). + Defense, + /// The unambiguous administration body (for Polkadot, an opinion on the topic given via a + /// public referendum on the `general_admin` track). + Administration, + /// The unambiguous treasury body (for Polkadot, an opinion on the topic given via a public + /// referendum on the `treasurer` track). + Treasury, +} + +#[derive(Encode, Decode, Debug)] +pub enum BodyPart { + /// The body's declaration, under whatever means it decides. + Voice, + /// A given number of members of the body. + Members { + #[codec(compact)] + count: u32, + }, + /// A given number of members of the body, out of some larger caucus. + Fraction { + #[codec(compact)] + nom: u32, + #[codec(compact)] + denom: u32, + }, + /// No less than the given proportion of members of the body. + AtLeastProportion { + #[codec(compact)] + nom: u32, + #[codec(compact)] + denom: u32, + }, + /// More than the given proportion of members of the body. + MoreThanProportion { + #[codec(compact)] + nom: u32, + #[codec(compact)] + denom: u32, + }, +} diff --git a/core/parentchain/indirect-calls-executor/src/mock.rs b/core/parentchain/indirect-calls-executor/src/mock.rs index bb7ad5a8db..cf19d4ca6e 100644 --- a/core/parentchain/indirect-calls-executor/src/mock.rs +++ b/core/parentchain/indirect-calls-executor/src/mock.rs @@ -14,7 +14,7 @@ use itp_sgx_runtime_primitives::types::{AccountId, Balance}; use itp_stf_primitives::{traits::IndirectExecutor, types::Signature}; use itp_test::mock::stf_mock::{GetterMock, TrustedCallMock, TrustedCallSignedMock}; use itp_types::{ - parentchain::{BalanceTransfer, ExtrinsicStatus, FilterEvents, HandleParentchainEvents}, + parentchain::{ExtrinsicStatus, FilterEvents, HandleParentchainEvents}, Address, Request, ShardIdentifier, H256, }; use log::*; @@ -167,13 +167,8 @@ impl FilterEvents for MockEvents { Ok(Vec::from([ExtrinsicStatus::Success])) } - fn get_transfer_events(&self) -> core::result::Result, Self::Error> { - let transfer = BalanceTransfer { - to: [0u8; 32].into(), - from: [0u8; 32].into(), - amount: Balance::default(), - }; - Ok(Vec::from([transfer])) + fn get_events(&self) -> core::result::Result, Self::Error> { + Ok(Vec::from([Default::default()])) } } diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index 0e4d4c2d25..582cf22c42 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -1492,6 +1492,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "hmac" version = "0.12.1" @@ -1668,6 +1674,7 @@ name = "ita-parentchain-interface" version = "0.9.0" dependencies = [ "bs58", + "hex-literal", "ita-sgx-runtime", "ita-stf", "itc-parentchain", @@ -4774,7 +4781,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "digest 0.10.7", "static_assertions", ]