Skip to content

Commit cf226f1

Browse files
Add deposit/withdraw events to EVM module (#5440)
* Add deposit/withdraw events * Remove balances trait
1 parent 208fd14 commit cf226f1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'vicinity, T: Trait> ApplyBackend for Backend<'vicinity, T> {
172172
}
173173

174174
for log in logs {
175-
Module::<T>::deposit_event(Event::Log(Log {
175+
Module::<T>::deposit_event(Event::<T>::Log(Log {
176176
address: log.address,
177177
topics: log.topics,
178178
data: log.data,

src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait {
127127
/// Currency type for deposit and withdraw.
128128
type Currency: Currency<Self::AccountId>;
129129
/// The overarching event type.
130-
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
130+
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
131131
/// Precompiles associated with this EVM engine.
132132
type Precompiles: Precompiles;
133133

@@ -147,11 +147,17 @@ decl_storage! {
147147

148148
decl_event! {
149149
/// EVM events
150-
pub enum Event {
150+
pub enum Event<T> where
151+
<T as frame_system::Trait>::AccountId,
152+
{
151153
/// Ethereum events from contracts.
152154
Log(Log),
153155
/// A contract has been created at given address.
154156
Created(H160),
157+
/// A deposit has been made at a given address.
158+
BalanceDeposit(AccountId, H160, U256),
159+
/// A withdrawal has been made from a given address.
160+
BalanceWithdraw(AccountId, H160, U256),
155161
}
156162
}
157163

@@ -202,6 +208,7 @@ decl_module! {
202208
Accounts::mutate(&address, |account| {
203209
account.balance += bvalue;
204210
});
211+
Module::<T>::deposit_event(Event::<T>::BalanceDeposit(sender, address, bvalue));
205212
}
206213

207214
/// Withdraw balance from EVM into currency/balances module.
@@ -225,6 +232,7 @@ decl_module! {
225232
Accounts::insert(&address, account);
226233

227234
T::Currency::resolve_creating(&sender, imbalance);
235+
Module::<T>::deposit_event(Event::<T>::BalanceWithdraw(sender, address, bvalue));
228236
}
229237

230238
/// Issue an EVM call operation. This is similar to a message call transaction in Ethereum.
@@ -289,7 +297,7 @@ decl_module! {
289297
},
290298
)?;
291299

292-
Module::<T>::deposit_event(Event::Created(create_address));
300+
Module::<T>::deposit_event(Event::<T>::Created(create_address));
293301
Ok(())
294302
}
295303

@@ -327,7 +335,7 @@ decl_module! {
327335
},
328336
)?;
329337

330-
Module::<T>::deposit_event(Event::Created(create_address));
338+
Module::<T>::deposit_event(Event::<T>::Created(create_address));
331339
Ok(())
332340
}
333341
}

0 commit comments

Comments
 (0)