-
Notifications
You must be signed in to change notification settings - Fork 300
feat(tokens): OnDeposit, OnTransfer, OnSlash hooks #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -657,3 +657,34 @@ impl<AccountId> TransferAll<AccountId> for Tuple { | |
Ok(()) | ||
} | ||
} | ||
|
||
/// Hook to run before slashing an account. | ||
pub trait OnSlash<AccountId, CurrencyId, Balance> { | ||
fn on_slash(currency_id: CurrencyId, who: &AccountId, amount: Balance); | ||
} | ||
|
||
impl<AccountId, CurrencyId, Balance> OnSlash<AccountId, CurrencyId, Balance> for () { | ||
fn on_slash(_: CurrencyId, _: &AccountId, _: Balance) {} | ||
} | ||
|
||
/// Hook to run before depositing into an account. | ||
pub trait OnDeposit<AccountId, CurrencyId, Balance> { | ||
fn on_deposit(currency_id: CurrencyId, who: &AccountId, amount: Balance) -> DispatchResult; | ||
} | ||
|
||
impl<AccountId, CurrencyId, Balance> OnDeposit<AccountId, CurrencyId, Balance> for () { | ||
fn on_deposit(_: CurrencyId, _: &AccountId, _: Balance) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Hook to run before transferring from an account to another. | ||
pub trait OnTransfer<AccountId, CurrencyId, Balance> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you intent to allow OnTransfer to be able to cancel the transfer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally I wanted all of these hooks to be able to fail, in consequence cancelling the transfer / deposit / slash. The trait bound on |
||
fn on_transfer(currency_id: CurrencyId, from: &AccountId, to: &AccountId, amount: Balance) -> DispatchResult; | ||
} | ||
|
||
impl<AccountId, CurrencyId, Balance> OnTransfer<AccountId, CurrencyId, Balance> for () { | ||
fn on_transfer(_: CurrencyId, _: &AccountId, _: &AccountId, _: Balance) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this after the early return. on the case no event is emitted, no hook should be called.