@@ -66,7 +66,7 @@ use sp_std::{cmp, convert::Infallible, marker, prelude::*, vec::Vec};
66
66
67
67
use orml_traits:: {
68
68
arithmetic:: { self , Signed } ,
69
- currency:: TransferAll ,
69
+ currency:: { OnDeposit , OnSlash , OnTransfer , TransferAll } ,
70
70
BalanceStatus , GetByKey , Happened , LockIdentifier , MultiCurrency , MultiCurrencyExtended , MultiLockableCurrency ,
71
71
MultiReservableCurrency , NamedMultiReservableCurrency , OnDust ,
72
72
} ;
@@ -173,6 +173,8 @@ pub use module::*;
173
173
174
174
#[ frame_support:: pallet]
175
175
pub mod module {
176
+ use orml_traits:: currency:: { OnDeposit , OnSlash , OnTransfer } ;
177
+
176
178
use super :: * ;
177
179
178
180
#[ pallet:: config]
@@ -216,6 +218,15 @@ pub mod module {
216
218
/// Handler to burn or transfer account's dust
217
219
type OnDust : OnDust < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
218
220
221
+ /// Hook to run before slashing an account.
222
+ type OnSlash : OnSlash < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
223
+
224
+ /// Hook to run before depositing into an account.
225
+ type OnDeposit : OnDeposit < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
226
+
227
+ /// Hook to run before transferring from an account to another.
228
+ type OnTransfer : OnTransfer < Self :: AccountId , Self :: CurrencyId , Self :: Balance > ;
229
+
219
230
/// Handler for when an account was created
220
231
type OnNewTokenAccount : Happened < ( Self :: AccountId , Self :: CurrencyId ) > ;
221
232
@@ -890,6 +901,7 @@ impl<T: Config> Pallet<T> {
890
901
amount : T :: Balance ,
891
902
existence_requirement : ExistenceRequirement ,
892
903
) -> DispatchResult {
904
+ T :: OnTransfer :: on_transfer ( currency_id, from, to, amount) ?;
893
905
if amount. is_zero ( ) || from == to {
894
906
return Ok ( ( ) ) ;
895
907
}
@@ -1015,6 +1027,7 @@ impl<T: Config> Pallet<T> {
1015
1027
require_existed : bool ,
1016
1028
change_total_issuance : bool ,
1017
1029
) -> DispatchResult {
1030
+ T :: OnDeposit :: on_deposit ( currency_id, who, amount) ?;
1018
1031
if amount. is_zero ( ) {
1019
1032
return Ok ( ( ) ) ;
1020
1033
}
@@ -1110,6 +1123,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
1110
1123
/// reserved funds, however we err on the side of punishment if things
1111
1124
/// are inconsistent or `can_slash` wasn't used appropriately.
1112
1125
fn slash ( currency_id : Self :: CurrencyId , who : & T :: AccountId , amount : Self :: Balance ) -> Self :: Balance {
1126
+ T :: OnSlash :: on_slash ( currency_id, who, amount) ;
1113
1127
if amount. is_zero ( ) {
1114
1128
return amount;
1115
1129
}
@@ -1276,6 +1290,7 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
1276
1290
///
1277
1291
/// Is a no-op if the value to be slashed is zero.
1278
1292
fn slash_reserved ( currency_id : Self :: CurrencyId , who : & T :: AccountId , value : Self :: Balance ) -> Self :: Balance {
1293
+ T :: OnSlash :: on_slash ( currency_id, who, value) ;
1279
1294
if value. is_zero ( ) {
1280
1295
return value;
1281
1296
}
0 commit comments