-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply codebase update to bc worker (#2587)
* update bitacross to upstream 9a3b032 * fix --------- Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com>
- Loading branch information
1 parent
ecc010d
commit e7423ae
Showing
128 changed files
with
4,004 additions
and
9,549 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
bitacross-worker/app-libs/parentchain-interface/src/event_subscriber.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,60 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
use itp_api_client_types::ParentchainApi; | ||
use itp_types::parentchain::{BalanceTransfer, ParentchainId}; | ||
use substrate_api_client::SubscribeEvents; | ||
|
||
pub fn subscribe_to_parentchain_events(api: &ParentchainApi, parentchain_id: ParentchainId) { | ||
println!("[L1Event:{}] Subscribing to selected events", parentchain_id); | ||
let mut subscription = api.subscribe_events().unwrap(); | ||
loop { | ||
let events = subscription.next_events_from_metadata().unwrap().unwrap(); | ||
|
||
for event in events.iter() { | ||
let event = event.unwrap(); | ||
match event.pallet_name() { | ||
"System" => continue, | ||
"ParaInclusion" => continue, | ||
"MessageQueue" => continue, | ||
"TransactionPayment" => continue, | ||
"Treasury" => continue, | ||
"Balances" => match event.variant_name() { | ||
"Deposit" => continue, | ||
"Withdraw" => continue, | ||
"Transfer" => | ||
if let Ok(Some(ev)) = event.as_event::<BalanceTransfer>() { | ||
println!("[L1Event:{}] {:?}", parentchain_id, ev); | ||
}, | ||
_ => println!( | ||
"[L1Event:{}] {}::{}", | ||
parentchain_id, | ||
event.pallet_name(), | ||
event.variant_name() | ||
), | ||
}, | ||
// TODO(Litentry): add important teebag events? | ||
_ => println!( | ||
"[L1Event:{}] {}::{}", | ||
parentchain_id, | ||
event.pallet_name(), | ||
event.variant_name() | ||
), | ||
} | ||
} | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/timestamp_set.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,63 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems 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. | ||
*/ | ||
|
||
use crate::{Litentry, ParentchainInstance, TargetA, TargetB}; | ||
use codec::{Compact, Decode, Encode}; | ||
use core::{any::TypeId, marker::PhantomData}; | ||
use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; | ||
use itc_parentchain_indirect_calls_executor::{ | ||
error::{Error, Result}, | ||
IndirectDispatch, | ||
}; | ||
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; | ||
use itp_types::{parentchain::ParentchainId, Moment}; | ||
use log::info; | ||
|
||
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)] | ||
pub struct TimestampSetArgs<I: ParentchainInstance> { | ||
now: Compact<Moment>, | ||
_phantom: PhantomData<I>, | ||
} | ||
|
||
impl<Executor: IndirectExecutor<TrustedCallSigned, Error>, I: ParentchainInstance + 'static> | ||
IndirectDispatch<Executor, TrustedCallSigned> for TimestampSetArgs<I> | ||
{ | ||
type Args = (); | ||
fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { | ||
info!("Found TimestampSet extrinsic in block: now = {:?}", self.now); | ||
let enclave_account_id = executor.get_enclave_account()?; | ||
let parentchain_id = if TypeId::of::<I>() == TypeId::of::<Litentry>() { | ||
ParentchainId::Litentry | ||
} else if TypeId::of::<I>() == TypeId::of::<TargetA>() { | ||
ParentchainId::TargetA | ||
} else if TypeId::of::<I>() == TypeId::of::<TargetB>() { | ||
ParentchainId::TargetB | ||
} else { | ||
return Err(Error::Other("unknown parentchain instance".into())) | ||
}; | ||
let trusted_call = | ||
TrustedCall::timestamp_set(enclave_account_id.into(), self.now.0, parentchain_id); | ||
let shard = executor.get_default_shard(); | ||
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?; | ||
let trusted_operation = | ||
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call); | ||
|
||
let encrypted_trusted_call = executor.encrypt(&trusted_operation.encode())?; | ||
executor.submit_trusted_call(shard, encrypted_trusted_call); | ||
Ok(()) | ||
} | ||
} |
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
Oops, something went wrong.