-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Include BeforeSendCoins and AfterSendCoins Hooks in the bank module #14701
Comments
@ValarDragon did you guys end up using something similar in your SDK fork? Is that still useful? |
I have no opposition to this personally and am on board to include it! But I must say that this and what staking does with hooks is sort of duct tape and doesn't scale well. Ideally, in the future, we can have a more robust and flexible system where modules subscribe and listen for certain typed events and act on them accordingly. |
@alexanderbez +1 on the more modular interface. We should engineer a notification based system. i.e the Bank module emits a "CoinsSent" notification that other modules can subscribe to. From my past life: https://developer.apple.com/documentation/DISPATCH |
@neverDefined is working to built transfer hooks for our tokenized vaults on Berachain, hence the motivation for this SDK change. |
Edit: Sorry. This ended up being longer than I expected. I made a few shorter comments below for specific concerns discussed in this comment. Related: #14224 That one goes one step further though, allowing the hook to alter the destination address. At Provenance, in our fork of the SDK, we utilized something similar for the In all these cases, any time funds are transferred, we want some checks made first. That includes (but isn't limited to) use of the So far, the info needed for these checks is the sender, receiver, and amount being transferred. And the output is the receiver and an error: // A SendRestrictionFn can restrict sends and/or provide a new receiver address.
type SendRestrictionFn func(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) (newToAddr sdk.AccAddress, err error) I previously created an issue to discuss the quarantine and sanction modules: #14124. It's not exactly what we ended up going with at Provenance though. Our fork is based off #12601 (not in If If there's a need to have different hooks before and after a transfer, |
Why have separate before/after hooks? One hook is simpler than two. The only state difference is balances. With one hook, the other balances can easily be calculated, though. So separate hooks aren't actually needed in that case. Most transfers happen inside a What transfers happen outside a |
The |
One of our use cases needs the A no-op for it would look like this: func BeforeSendCoins(ctx sdk.Context, sender, receiver sdk.AccAddress, amt sdk.Coins) (newToAddr sdk.AccAddress, err error) {
return receiver, nil
} |
Okay I am really enjoying this |
Is this issue still open? Can I work on it @neverDefined |
There's already this PR: #14224 which effectively adds a |
Summary
Similar to the staking keeper, the bank keeper can benefit a lot by having hooks that other modules can register on send coins events. For developers that don't need it, its optional and doest require much overhead, and for developers that need this feature there is no better option than having it in the sdk itself instead of having to maintain a fork.
Problem Definition
What problems may be addressed by introducing this feature?
Allows developers to still use the
SendKeeper
to invoke transactions before and after a sendCoins event. Similar to staking modulesAfterValidatorCreated
andBeforeValidatorModified
.What benefits does the SDK stand to gain by including this feature?
Are there any disadvantages of including this feature? -->
Proposal
The text was updated successfully, but these errors were encountered: