forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
637038c
commit e76d986
Showing
4 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/ibc-go/v2/modules/apps/transfer/types" | ||
) | ||
|
||
var _ types.TransferHooks = Keeper{} | ||
|
||
func (k Keeper) AfterSendTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender sdk.AccAddress, | ||
receiver string, | ||
isSource bool) { | ||
if k.hooks != nil { | ||
k.hooks.AfterSendTransfer(ctx, sourcePort, sourceChannel, token, sender, receiver, isSource) | ||
} | ||
} | ||
|
||
func (k Keeper) AfterRecvTransfer( | ||
ctx sdk.Context, | ||
destPort, destChannel string, | ||
token sdk.Coin, | ||
receiver string, | ||
isSource bool) { | ||
if k.hooks != nil { | ||
k.hooks.AfterRecvTransfer(ctx, destPort, destChannel, token, receiver, isSource) | ||
} | ||
} | ||
|
||
func (k Keeper) AfterRefundTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender string, | ||
isSource bool) { | ||
if k.hooks != nil { | ||
k.hooks.AfterRefundTransfer(ctx, sourcePort, sourceChannel, token, sender, isSource) | ||
} | ||
} | ||
|
||
func (k *Keeper) SetHooks(sh types.TransferHooks) *Keeper { | ||
if k.hooks != nil { | ||
panic("cannot set hooks twice") | ||
} | ||
|
||
k.hooks = sh | ||
|
||
return k | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type TransferHooks interface { | ||
AfterSendTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender sdk.AccAddress, | ||
receiver string, | ||
isSource bool) | ||
AfterRecvTransfer( | ||
ctx sdk.Context, | ||
destPort, destChannel string, | ||
token sdk.Coin, | ||
receiver string, | ||
isSource bool) | ||
AfterRefundTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender string, | ||
isSource bool) | ||
} | ||
|
||
type MultiTransferHooks []TransferHooks | ||
|
||
func NewMultiTransferHooks(hooks ...TransferHooks) MultiTransferHooks { | ||
return hooks | ||
} | ||
|
||
func (mths MultiTransferHooks) AfterSendTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender sdk.AccAddress, | ||
receiver string, | ||
isSource bool) { | ||
for i := range mths { | ||
mths[i].AfterSendTransfer(ctx, sourcePort, sourceChannel, token, sender, receiver, isSource) | ||
} | ||
} | ||
|
||
func (mths MultiTransferHooks) AfterRecvTransfer( | ||
ctx sdk.Context, | ||
destPort, destChannel string, | ||
token sdk.Coin, | ||
receiver string, | ||
isSource bool) { | ||
for i := range mths { | ||
mths[i].AfterRecvTransfer(ctx, destPort, destChannel, token, receiver, isSource) | ||
} | ||
} | ||
|
||
func (mths MultiTransferHooks) AfterRefundTransfer( | ||
ctx sdk.Context, | ||
sourcePort, sourceChannel string, | ||
token sdk.Coin, | ||
sender string, | ||
isSource bool) { | ||
for i := range mths { | ||
mths[i].AfterRefundTransfer(ctx, sourcePort, sourceChannel, token, sender, isSource) | ||
} | ||
} |