-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add a BeforeSend hook to the bank module #278
Conversation
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.
I'm wondering if we don;t need to call SetHooks
in app.go?
Don't we only need to call SetHooks if we're setting some hooks? There's nothing in the cosmos-sdk repo that makes use of these hooks. In the upstream osmosis, we will add some |
x/bank/keeper/keeper.go
Outdated
@@ -231,6 +239,14 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd | |||
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String()) | |||
} | |||
|
|||
// if there are hooks, call the BeforeSend hook | |||
if k.hooks != nil { |
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.
Lets please add these hooks != nil check in the hooks struct itself, and not in this logic.
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.
Unless this is the standard for the rest of bank. If so, lets make a github issue for it to be fixed
Yeah no need to set hooks, as long as theres nil guards in the hooks structs |
How can we add nil guards to the hook structs if what we're checking if the hook struct itself is nil? Other modules solve it by adding keeper functions for each hook, wrapping them and checking if hooks exist https://github.com/osmosis-labs/cosmos-sdk/blob/osmosis-main/x/staking/keeper/hooks.go Imo, this is uglier and "more boilerplate-y", but I can update to that to be standard with the rest of the sdk. |
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.
Looks great overall, I like the approach for testing with the mock.
I think having a separate case with a valid amount for all methods would be good
Co-authored-by: Roman <[email protected]>
Why would we package the calling of the before send hook with subUnlockedCoins? These seem to be two very different functions. The BeforeSend hook needs to have a recipient address, and feels weird to be passing that into a function focused on subtracting coins |
|
Co-authored-by: Roman <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
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.
LGTM once linter and tests are happy
* in progress * add bank hooks: * Remove stale comments * add nil guards * add hooks function * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * add tests * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk <[email protected]> * lint Co-authored-by: Roman <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
* in progress * add bank hooks: * Remove stale comments * add nil guards * add hooks function * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * add tests * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk <[email protected]> * lint Co-authored-by: Roman <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
* in progress * add bank hooks: * Remove stale comments * add nil guards * add hooks function * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * add tests * Apply suggestions from code review Co-authored-by: Roman <[email protected]> * Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk <[email protected]> * lint Co-authored-by: Roman <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Description
This PR adds a hook point to before all sends in the bank module.
It makes sure to trigger the hook in the following Bank keeper functions:
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change