484 lines
13 KiB
Go
484 lines
13 KiB
Go
package types
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
|
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
|
)
|
|
|
|
var _ sdk.Msg = &MsgChannelOpenInit{}
|
|
|
|
// NewMsgChannelOpenInit creates a new MsgChannelOpenInit
|
|
func NewMsgChannelOpenInit(
|
|
portID, channelID string, version string, channelOrder Order, connectionHops []string,
|
|
counterpartyPortID, counterpartyChannelID string, signer sdk.AccAddress,
|
|
) *MsgChannelOpenInit {
|
|
counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID)
|
|
channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version)
|
|
return &MsgChannelOpenInit{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
Channel: channel,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelOpenInit) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelOpenInit) Type() string {
|
|
return "channel_open_init"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelOpenInit) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
// Signer can be empty
|
|
return msg.Channel.ValidateBasic()
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelOpenInit) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelOpenInit) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgChannelOpenTry{}
|
|
|
|
// NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance
|
|
func NewMsgChannelOpenTry(
|
|
portID, channelID, version string, channelOrder Order, connectionHops []string,
|
|
counterpartyPortID, counterpartyChannelID, counterpartyVersion string,
|
|
proofInit []byte, proofHeight uint64, signer sdk.AccAddress,
|
|
) *MsgChannelOpenTry {
|
|
counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID)
|
|
channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version)
|
|
return &MsgChannelOpenTry{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
Channel: channel,
|
|
CounterpartyVersion: counterpartyVersion,
|
|
ProofInit: proofInit,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelOpenTry) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelOpenTry) Type() string {
|
|
return "channel_open_try"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelOpenTry) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
if len(msg.ProofInit) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
// Signer can be empty
|
|
return msg.Channel.ValidateBasic()
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelOpenTry) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgChannelOpenAck{}
|
|
|
|
// NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance
|
|
func NewMsgChannelOpenAck(
|
|
portID, channelID string, cpv string, proofTry []byte, proofHeight uint64,
|
|
signer sdk.AccAddress,
|
|
) *MsgChannelOpenAck {
|
|
return &MsgChannelOpenAck{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
CounterpartyVersion: cpv,
|
|
ProofTry: proofTry,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelOpenAck) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelOpenAck) Type() string {
|
|
return "channel_open_ack"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelOpenAck) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
if len(msg.ProofTry) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
// Signer can be empty
|
|
return nil
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelOpenAck) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgChannelOpenConfirm{}
|
|
|
|
// NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance
|
|
func NewMsgChannelOpenConfirm(
|
|
portID, channelID string, proofAck []byte, proofHeight uint64,
|
|
signer sdk.AccAddress,
|
|
) *MsgChannelOpenConfirm {
|
|
return &MsgChannelOpenConfirm{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
ProofAck: proofAck,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelOpenConfirm) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelOpenConfirm) Type() string {
|
|
return "channel_open_confirm"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelOpenConfirm) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
if len(msg.ProofAck) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
// Signer can be empty
|
|
return nil
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelOpenConfirm) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelOpenConfirm) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgChannelCloseInit{}
|
|
|
|
// NewMsgChannelCloseInit creates a new MsgChannelCloseInit instance
|
|
func NewMsgChannelCloseInit(
|
|
portID string, channelID string, signer sdk.AccAddress,
|
|
) *MsgChannelCloseInit {
|
|
return &MsgChannelCloseInit{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelCloseInit) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelCloseInit) Type() string {
|
|
return "channel_close_init"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelCloseInit) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
// Signer can be empty
|
|
return nil
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelCloseInit) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgChannelCloseConfirm{}
|
|
|
|
// NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance
|
|
func NewMsgChannelCloseConfirm(
|
|
portID, channelID string, proofInit []byte, proofHeight uint64,
|
|
signer sdk.AccAddress,
|
|
) *MsgChannelCloseConfirm {
|
|
return &MsgChannelCloseConfirm{
|
|
PortID: portID,
|
|
ChannelID: channelID,
|
|
ProofInit: proofInit,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgChannelCloseConfirm) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgChannelCloseConfirm) Type() string {
|
|
return "channel_close_confirm"
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgChannelCloseConfirm) ValidateBasic() error {
|
|
if err := host.PortIdentifierValidator(msg.PortID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid port ID")
|
|
}
|
|
if err := host.ChannelIdentifierValidator(msg.ChannelID); err != nil {
|
|
return sdkerrors.Wrap(err, "invalid channel ID")
|
|
}
|
|
if len(msg.ProofInit) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
// Signer can be empty
|
|
return nil
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgChannelCloseConfirm) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgRecvPacket{}
|
|
|
|
// NewMsgRecvPacket constructs new MsgRecvPacket
|
|
func NewMsgRecvPacket(
|
|
packet Packet, proof []byte, proofHeight uint64,
|
|
signer sdk.AccAddress,
|
|
) *MsgRecvPacket {
|
|
return &MsgRecvPacket{
|
|
Packet: packet,
|
|
Proof: proof,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgRecvPacket) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgRecvPacket) ValidateBasic() error {
|
|
if len(msg.Proof) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
if msg.Signer.Empty() {
|
|
return sdkerrors.ErrInvalidAddress
|
|
}
|
|
|
|
return msg.Packet.ValidateBasic()
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgRecvPacket) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetDataSignBytes returns the base64-encoded bytes used for the
|
|
// data field when signing the packet.
|
|
func (msg MsgRecvPacket) GetDataSignBytes() []byte {
|
|
s := "\"" + base64.StdEncoding.EncodeToString(msg.Packet.Data) + "\""
|
|
return []byte(s)
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgRecvPacket) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgRecvPacket) Type() string {
|
|
return "recv_packet"
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgTimeout{}
|
|
|
|
// NewMsgTimeout constructs new MsgTimeout
|
|
func NewMsgTimeout(
|
|
packet Packet, nextSequenceRecv uint64, proof []byte,
|
|
proofHeight uint64, signer sdk.AccAddress,
|
|
) *MsgTimeout {
|
|
return &MsgTimeout{
|
|
Packet: packet,
|
|
NextSequenceRecv: nextSequenceRecv,
|
|
Proof: proof,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgTimeout) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgTimeout) ValidateBasic() error {
|
|
if len(msg.Proof) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
if msg.Signer.Empty() {
|
|
return sdkerrors.ErrInvalidAddress
|
|
}
|
|
|
|
return msg.Packet.ValidateBasic()
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgTimeout) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgTimeout) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgTimeout) Type() string {
|
|
return "timeout_packet"
|
|
}
|
|
|
|
var _ sdk.Msg = &MsgAcknowledgement{}
|
|
|
|
// NewMsgAcknowledgement constructs a new MsgAcknowledgement
|
|
func NewMsgAcknowledgement(
|
|
packet Packet, ack []byte, proof []byte, proofHeight uint64, signer sdk.AccAddress) *MsgAcknowledgement {
|
|
return &MsgAcknowledgement{
|
|
Packet: packet,
|
|
Acknowledgement: ack,
|
|
Proof: proof,
|
|
ProofHeight: proofHeight,
|
|
Signer: signer,
|
|
}
|
|
}
|
|
|
|
// Route implements sdk.Msg
|
|
func (msg MsgAcknowledgement) Route() string {
|
|
return host.RouterKey
|
|
}
|
|
|
|
// ValidateBasic implements sdk.Msg
|
|
func (msg MsgAcknowledgement) ValidateBasic() error {
|
|
if len(msg.Proof) == 0 {
|
|
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
|
|
}
|
|
if msg.ProofHeight == 0 {
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0")
|
|
}
|
|
if msg.Signer.Empty() {
|
|
return sdkerrors.ErrInvalidAddress
|
|
}
|
|
|
|
return msg.Packet.ValidateBasic()
|
|
}
|
|
|
|
// GetSignBytes implements sdk.Msg
|
|
func (msg MsgAcknowledgement) GetSignBytes() []byte {
|
|
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
|
}
|
|
|
|
// GetSigners implements sdk.Msg
|
|
func (msg MsgAcknowledgement) GetSigners() []sdk.AccAddress {
|
|
return []sdk.AccAddress{msg.Signer}
|
|
}
|
|
|
|
// Type implements sdk.Msg
|
|
func (msg MsgAcknowledgement) Type() string {
|
|
return "acknowledge_packet"
|
|
}
|