From 9937b4cdfd6085b9d1751e90e954c7d21042dfdd Mon Sep 17 00:00:00 2001 From: zktony Date: Tue, 19 Mar 2024 19:47:34 +0700 Subject: [PATCH] Added changes for frontend --- pallets/thea-executor/src/lib.rs | 19 +++++++++++++++---- pallets/thea-message-handler/src/lib.rs | 5 +++++ pallets/thea/src/lib.rs | 5 +++++ primitives/thea/src/lib.rs | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pallets/thea-executor/src/lib.rs b/pallets/thea-executor/src/lib.rs index 51d92c6ef..2b6a5d6ca 100644 --- a/pallets/thea-executor/src/lib.rs +++ b/pallets/thea-executor/src/lib.rs @@ -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, u64, u8), } // Errors inform users that something went wrong. @@ -243,13 +245,22 @@ pub mod pallet { >::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::::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::::WithdrawalFailed(network_id, withdrawal)) + Self::deposit_event(Event::::WithdrawalFailed(network_id, withdrawals)) } network_len += 1; } diff --git a/pallets/thea-message-handler/src/lib.rs b/pallets/thea-message-handler/src/lib.rs index 777690e01..424a0cc07 100644 --- a/pallets/thea-message-handler/src/lib.rs +++ b/pallets/thea-message-handler/src/lib.rs @@ -338,4 +338,9 @@ impl thea_primitives::TheaOutgoingExecutor for Pallet { Ok(()) } + + fn get_outgoing_nonce(network: Network) -> u64 { + let nonce = >::get(); + nonce.saturating_add(1) + } } diff --git a/pallets/thea/src/lib.rs b/pallets/thea/src/lib.rs index 3f9c486dc..804b2aa40 100644 --- a/pallets/thea/src/lib.rs +++ b/pallets/thea/src/lib.rs @@ -880,4 +880,9 @@ impl thea_primitives::TheaOutgoingExecutor for Pallet { >::insert(network, payload.nonce, payload); Ok(()) } + + fn get_outgoing_nonce(network: Network) -> u64 { + let nonce = >::get(network); + nonce.saturating_add(1) + } } diff --git a/primitives/thea/src/lib.rs b/primitives/thea/src/lib.rs index 1b883ad73..c2c5e3e3c 100644 --- a/primitives/thea/src/lib.rs +++ b/primitives/thea/src/lib.rs @@ -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) -> DispatchResult; + fn get_outgoing_nonce(network: Network) -> u64; } impl TheaIncomingExecutor for () {