-
Notifications
You must be signed in to change notification settings - Fork 61
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
0e3ef7a
commit 1388c7c
Showing
3 changed files
with
134 additions
and
134 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
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 |
---|---|---|
@@ -1,123 +1,123 @@ | ||
package interchainstaking | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" | ||
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" | ||
porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" | ||
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" | ||
|
||
"github.com/quicksilver-zone/quicksilver/utils" | ||
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper" | ||
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" | ||
) | ||
|
||
var _ porttypes.IBCModule = &TransferMiddleware{} | ||
|
||
// IBCModule implements the ICS26 interface for interchain accounts controller chains. | ||
type TransferMiddleware struct { | ||
app porttypes.IBCModule | ||
keeper *keeper.Keeper | ||
} | ||
|
||
// NewIBCModule creates a new IBCModule given the keeper. | ||
func NewTransferMiddleware(app porttypes.IBCModule, k *keeper.Keeper) TransferMiddleware { | ||
return TransferMiddleware{ | ||
app: app, | ||
keeper: k, | ||
} | ||
} | ||
|
||
// OnChanOpenInit implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanOpenInit( | ||
ctx sdk.Context, | ||
order channeltypes.Order, | ||
connectionHops []string, | ||
portID string, | ||
channelID string, | ||
chanCap *capabilitytypes.Capability, | ||
counterparty channeltypes.Counterparty, | ||
version string, | ||
) (string, error) { | ||
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) | ||
} | ||
|
||
// OnChanOpenTry implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanOpenTry( | ||
ctx sdk.Context, | ||
order channeltypes.Order, | ||
connectionHops []string, | ||
portID, channelID string, | ||
chanCap *capabilitytypes.Capability, | ||
counterparty channeltypes.Counterparty, | ||
counterpartyVersion string, | ||
) (version string, err error) { | ||
return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) | ||
} | ||
|
||
// OnChanOpenAck implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanOpenAck( | ||
ctx sdk.Context, | ||
portID, channelID string, | ||
counterpartyChannelID string, | ||
counterpartyVersion string, | ||
) error { | ||
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) | ||
} | ||
|
||
// OnChanOpenConfirm implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { | ||
return im.app.OnChanOpenConfirm(ctx, portID, channelID) | ||
} | ||
|
||
// OnChanCloseInit implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { | ||
return im.app.OnChanCloseInit(ctx, portID, channelID) | ||
} | ||
|
||
// OnChanCloseConfirm implements the IBCModule interface. | ||
func (im TransferMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { | ||
return im.app.OnChanCloseConfirm(ctx, portID, channelID) | ||
} | ||
|
||
// OnRecvPacket checks implements the IBCModule interface. | ||
func (im TransferMiddleware) OnRecvPacket( | ||
ctx sdk.Context, | ||
packet channeltypes.Packet, | ||
relayer sdk.AccAddress, | ||
) ibcexported.Acknowledgement { | ||
var data transfertypes.FungibleTokenPacketData | ||
if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { | ||
return channeltypes.NewErrorAcknowledgement(err) | ||
} | ||
|
||
_, found := im.keeper.GetZoneForWithdrawalAccount(ctx, data.Sender) | ||
if found { | ||
if data.Receiver == im.keeper.AccountKeeper.GetModuleAddress(types.ModuleName).String() { | ||
im.keeper.Logger(ctx).Info("msgTransfer to ics module account from withdrawal address") | ||
err := im.keeper.HandleMsgTransfer(ctx, data, utils.DeriveIbcDenom(packet.DestinationPort, packet.DestinationChannel, packet.SourcePort, packet.SourceChannel, data.Denom)) | ||
if err != nil { | ||
im.keeper.Logger(ctx).Error("unable to disperse rewards", "error", err.Error()) | ||
} | ||
} | ||
} | ||
|
||
return im.app.OnRecvPacket(ctx, packet, relayer) | ||
} | ||
|
||
// OnAcknowledgementPacket implements the IBCModule interface. | ||
func (im TransferMiddleware) OnAcknowledgementPacket( | ||
ctx sdk.Context, | ||
packet channeltypes.Packet, | ||
acknowledgement []byte, | ||
relayer sdk.AccAddress, | ||
) error { | ||
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) | ||
} | ||
|
||
// OnTimeoutPacket implements the IBCModule interface. | ||
func (im TransferMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { | ||
return im.app.OnTimeoutPacket(ctx, packet, relayer) | ||
} | ||
// import ( | ||
// sdk "github.com/cosmos/cosmos-sdk/types" | ||
// capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
|
||
// transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" | ||
// channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" | ||
// porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" | ||
// ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported" | ||
|
||
// "github.com/quicksilver-zone/quicksilver/utils" | ||
// "github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper" | ||
// "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" | ||
// ) | ||
|
||
// var _ porttypes.IBCModule = &TransferMiddleware{} | ||
|
||
// // IBCModule implements the ICS26 interface for interchain accounts controller chains. | ||
// type TransferMiddleware struct { | ||
// app porttypes.IBCModule | ||
// keeper *keeper.Keeper | ||
// } | ||
|
||
// // NewIBCModule creates a new IBCModule given the keeper. | ||
// func NewTransferMiddleware(app porttypes.IBCModule, k *keeper.Keeper) TransferMiddleware { | ||
// return TransferMiddleware{ | ||
// app: app, | ||
// keeper: k, | ||
// } | ||
// } | ||
|
||
// // OnChanOpenInit implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanOpenInit( | ||
// ctx sdk.Context, | ||
// order channeltypes.Order, | ||
// connectionHops []string, | ||
// portID string, | ||
// channelID string, | ||
// chanCap *capabilitytypes.Capability, | ||
// counterparty channeltypes.Counterparty, | ||
// version string, | ||
// ) (string, error) { | ||
// return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) | ||
// } | ||
|
||
// // OnChanOpenTry implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanOpenTry( | ||
// ctx sdk.Context, | ||
// order channeltypes.Order, | ||
// connectionHops []string, | ||
// portID, channelID string, | ||
// chanCap *capabilitytypes.Capability, | ||
// counterparty channeltypes.Counterparty, | ||
// counterpartyVersion string, | ||
// ) (version string, err error) { | ||
// return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion) | ||
// } | ||
|
||
// // OnChanOpenAck implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanOpenAck( | ||
// ctx sdk.Context, | ||
// portID, channelID string, | ||
// counterpartyChannelID string, | ||
// counterpartyVersion string, | ||
// ) error { | ||
// return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion) | ||
// } | ||
|
||
// // OnChanOpenConfirm implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error { | ||
// return im.app.OnChanOpenConfirm(ctx, portID, channelID) | ||
// } | ||
|
||
// // OnChanCloseInit implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error { | ||
// return im.app.OnChanCloseInit(ctx, portID, channelID) | ||
// } | ||
|
||
// // OnChanCloseConfirm implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error { | ||
// return im.app.OnChanCloseConfirm(ctx, portID, channelID) | ||
// } | ||
|
||
// // OnRecvPacket checks implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnRecvPacket( | ||
// ctx sdk.Context, | ||
// packet channeltypes.Packet, | ||
// relayer sdk.AccAddress, | ||
// ) ibcexported.Acknowledgement { | ||
// var data transfertypes.FungibleTokenPacketData | ||
// if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { | ||
// return channeltypes.NewErrorAcknowledgement(err) | ||
// } | ||
|
||
// _, found := im.keeper.GetZoneForWithdrawalAccount(ctx, data.Sender) | ||
// if found { | ||
// if data.Receiver == im.keeper.AccountKeeper.GetModuleAddress(types.ModuleName).String() { | ||
// im.keeper.Logger(ctx).Info("msgTransfer to ics module account from withdrawal address") | ||
// err := im.keeper.HandleMsgTransfer(ctx, data, utils.DeriveIbcDenom(packet.DestinationPort, packet.DestinationChannel, packet.SourcePort, packet.SourceChannel, data.Denom)) | ||
// if err != nil { | ||
// im.keeper.Logger(ctx).Error("unable to disperse rewards", "error", err.Error()) | ||
// } | ||
// } | ||
// } | ||
|
||
// return im.app.OnRecvPacket(ctx, packet, relayer) | ||
// } | ||
|
||
// // OnAcknowledgementPacket implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnAcknowledgementPacket( | ||
// ctx sdk.Context, | ||
// packet channeltypes.Packet, | ||
// acknowledgement []byte, | ||
// relayer sdk.AccAddress, | ||
// ) error { | ||
// return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) | ||
// } | ||
|
||
// // OnTimeoutPacket implements the IBCModule interface. | ||
// func (im TransferMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { | ||
// return im.app.OnTimeoutPacket(ctx, packet, relayer) | ||
// } |