@@ -206,12 +206,21 @@ pub mod module {
206
206
#[ pallet:: event]
207
207
#[ pallet:: generate_deposit( pub ( crate ) fn deposit_event) ]
208
208
pub enum Event < T : Config > {
209
- /// Token transfer success. \[currency_id, from, to, amount\]
210
- Transferred ( T :: CurrencyId , T :: AccountId , T :: AccountId , T :: Balance ) ,
209
+ /// An account was created with some free balance. \[currency_id,
210
+ /// account, free_balance\]
211
+ Endowed ( T :: CurrencyId , T :: AccountId , T :: Balance ) ,
211
212
/// An account was removed whose balance was non-zero but below
212
- /// ExistentialDeposit, resulting in an outright loss. \[account,
213
- /// currency_id, amount\]
214
- DustLost ( T :: AccountId , T :: CurrencyId , T :: Balance ) ,
213
+ /// ExistentialDeposit, resulting in an outright loss. \[currency_id,
214
+ /// account, balance\]
215
+ DustLost ( T :: CurrencyId , T :: AccountId , T :: Balance ) ,
216
+ /// Transfer succeeded. \[currency_id, from, to, value\]
217
+ Transfer ( T :: CurrencyId , T :: AccountId , T :: AccountId , T :: Balance ) ,
218
+ /// Some balance was reserved (moved from free to reserved).
219
+ /// \[currency_id, who, value\]
220
+ Reserved ( T :: CurrencyId , T :: AccountId , T :: Balance ) ,
221
+ /// Some balance was unreserved (moved from reserved to free).
222
+ /// \[currency_id, who, value\]
223
+ Unreserved ( T :: CurrencyId , T :: AccountId , T :: Balance ) ,
215
224
}
216
225
217
226
/// The total issuance of a token type.
@@ -321,7 +330,7 @@ pub mod module {
321
330
let to = T :: Lookup :: lookup ( dest) ?;
322
331
<Self as MultiCurrency < _ > >:: transfer ( currency_id, & from, & to, amount) ?;
323
332
324
- Self :: deposit_event ( Event :: Transferred ( currency_id, from, to, amount) ) ;
333
+ Self :: deposit_event ( Event :: Transfer ( currency_id, from, to, amount) ) ;
325
334
Ok ( ( ) . into ( ) )
326
335
}
327
336
@@ -340,7 +349,7 @@ pub mod module {
340
349
let balance = <Self as MultiCurrency < T :: AccountId > >:: free_balance ( currency_id, & from) ;
341
350
<Self as MultiCurrency < T :: AccountId > >:: transfer ( currency_id, & from, & to, balance) ?;
342
351
343
- Self :: deposit_event ( Event :: Transferred ( currency_id, from, to, balance) ) ;
352
+ Self :: deposit_event ( Event :: Transfer ( currency_id, from, to, balance) ) ;
344
353
Ok ( ( ) . into ( ) )
345
354
}
346
355
}
@@ -358,41 +367,47 @@ impl<T: Config> Pallet<T> {
358
367
f : impl FnOnce ( & mut AccountData < T :: Balance > , bool ) -> sp_std:: result:: Result < R , E > ,
359
368
) -> sp_std:: result:: Result < R , E > {
360
369
Accounts :: < T > :: try_mutate_exists ( who, currency_id, |maybe_account| {
361
- let existed = maybe_account. is_some ( ) ;
370
+ let is_new = maybe_account. is_some ( ) ;
362
371
let mut account = maybe_account. take ( ) . unwrap_or_default ( ) ;
363
- f ( & mut account, existed) . map ( move |result| {
364
- let mut handle_dust: Option < T :: Balance > = None ;
372
+ f ( & mut account, is_new) . map ( move |result| {
373
+ let maybe_endowed = if is_new { Some ( account. free ) } else { None } ;
374
+
375
+ let mut maybe_dust: Option < T :: Balance > = None ;
365
376
let total = account. total ( ) ;
366
377
* maybe_account = if total. is_zero ( ) {
367
378
None
368
379
} else {
369
380
// if non_zero total is below existential deposit and the account is not a
370
381
// module account, should handle the dust.
371
382
if total < T :: ExistentialDeposits :: get ( & currency_id) && !Self :: is_module_account_id ( who) {
372
- handle_dust = Some ( total) ;
383
+ maybe_dust = Some ( total) ;
373
384
}
374
385
Some ( account)
375
386
} ;
376
387
377
- ( existed , maybe_account. is_some ( ) , handle_dust , result)
388
+ ( maybe_endowed , maybe_account. is_some ( ) , maybe_dust , result)
378
389
} )
379
390
} )
380
- . map ( |( existed , exists, handle_dust , result) | {
381
- if existed && !exists {
391
+ . map ( |( maybe_endowed , exists, maybe_dust , result) | {
392
+ if maybe_endowed . is_some ( ) && !exists {
382
393
// If existed before, decrease account provider.
383
- // Ignore the result, because if it failed means that these’s remain consumers,
384
- // and the account storage in frame_system shouldn't be repeaded .
394
+ // Ignore the result, because if it failed then there are remaining consumers,
395
+ // and the account storage in frame_system shouldn't be reaped .
385
396
let _ = frame_system:: Pallet :: < T > :: dec_providers ( who) ;
386
- } else if !existed && exists {
397
+ } else if maybe_endowed . is_none ( ) && exists {
387
398
// if new, increase account provider
388
399
frame_system:: Pallet :: < T > :: inc_providers ( who) ;
389
400
}
390
401
391
- if let Some ( dust_amount) = handle_dust {
402
+ if let Some ( endowed) = maybe_endowed {
403
+ Self :: deposit_event ( Event :: Endowed ( currency_id, who. clone ( ) , endowed) ) ;
404
+ }
405
+
406
+ if let Some ( dust_amount) = maybe_dust {
392
407
// `OnDust` maybe get/set storage `Accounts` of `who`, trigger handler here
393
408
// to avoid some unexpected errors.
394
409
T :: OnDust :: on_dust ( who, currency_id, dust_amount) ;
395
- Self :: deposit_event ( Event :: DustLost ( who. clone ( ) , currency_id , dust_amount) ) ;
410
+ Self :: deposit_event ( Event :: DustLost ( currency_id , who. clone ( ) , dust_amount) ) ;
396
411
}
397
412
398
413
result
@@ -757,6 +772,8 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
757
772
// Cannot overflow becuase total issuance is using the same balance type and
758
773
// this doesn't increase total issuance
759
774
Self :: set_reserved_balance ( currency_id, who, account. reserved + value) ;
775
+
776
+ Self :: deposit_event ( Event :: Reserved ( currency_id, who. clone ( ) , value) ) ;
760
777
Ok ( ( ) )
761
778
}
762
779
@@ -774,6 +791,7 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
774
791
Self :: set_reserved_balance ( currency_id, who, account. reserved - actual) ;
775
792
Self :: set_free_balance ( currency_id, who, account. free + actual) ;
776
793
794
+ Self :: deposit_event ( Event :: Unreserved ( currency_id, who. clone ( ) , actual. clone ( ) ) ) ;
777
795
value - actual
778
796
}
779
797
0 commit comments