Skip to content

Commit

Permalink
Added changes for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
zktony committed Mar 19, 2024
1 parent db7ae33 commit 9937b4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pallets/thea-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ pub mod pallet {
WithdrawalFeeSet(u8, u128),
/// Native Token Burn event
NativeTokenBurned(T::AccountId, u128),
/// Withdrawal Sent (Network, Withdrawal Id,Batch Outgoing Nonce, Withdrawal Index)
WithdrawalSent(Network, Vec<u8>, u64, u8),
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -243,13 +245,22 @@ pub mod pallet {
<ReadyWithdrawals<T>>::iter_prefix(block_no.saturating_sub(1u8.into()));
let mut withdrawal_len = 0;
let mut network_len = 0;
for (network_id, withdrawal) in pending_withdrawals {
withdrawal_len += withdrawal.len();
for (network_id, withdrawals) in pending_withdrawals {
withdrawal_len += withdrawals.len();
let batch_nonce = T::Executor::get_outgoing_nonce(network_id);
for (index, withdrawal) in withdrawals.iter().enumerate() {
Self::deposit_event(Event::<T>::WithdrawalSent(
network_id,
withdrawal.id.clone(),
batch_nonce,
index as u8,
));
}
// This is fine as this trait is not supposed to fail
if T::Executor::execute_withdrawals(network_id, withdrawal.clone().encode())
if T::Executor::execute_withdrawals(network_id, withdrawals.clone().encode())
.is_err()
{
Self::deposit_event(Event::<T>::WithdrawalFailed(network_id, withdrawal))
Self::deposit_event(Event::<T>::WithdrawalFailed(network_id, withdrawals))
}
network_len += 1;
}
Expand Down
5 changes: 5 additions & 0 deletions pallets/thea-message-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,9 @@ impl<T: Config> thea_primitives::TheaOutgoingExecutor for Pallet<T> {

Ok(())
}

fn get_outgoing_nonce(network: Network) -> u64 {
let nonce = <OutgoingNonce<T>>::get();
nonce.saturating_add(1)
}
}
5 changes: 5 additions & 0 deletions pallets/thea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,4 +880,9 @@ impl<T: Config> thea_primitives::TheaOutgoingExecutor for Pallet<T> {
<OutgoingMessages<T>>::insert(network, payload.nonce, payload);
Ok(())
}

fn get_outgoing_nonce(network: Network) -> u64 {
let nonce = <OutgoingNonce<T>>::get(network);
nonce.saturating_add(1)
}
}
1 change: 1 addition & 0 deletions primitives/thea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub trait TheaIncomingExecutor {
/// Thea outgoing message executor abstraction which should be implemented by the "Thea" pallet.
pub trait TheaOutgoingExecutor {
fn execute_withdrawals(network: Network, withdrawals: Vec<u8>) -> DispatchResult;
fn get_outgoing_nonce(network: Network) -> u64;
}

impl TheaIncomingExecutor for () {
Expand Down

0 comments on commit 9937b4c

Please sign in to comment.