From ebd35e574af514d0c296e527b7e3d047f2907297 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 10 Jul 2024 21:12:59 +0900 Subject: [PATCH] add the TxChannelUpgradeXxx methods to the Chain struct Signed-off-by: Masanori Yoshida --- pkg/relay/ethereum/tx.go | 98 ++++++++++++++++++++++++++++++++++++- pkg/relay/ethereum/types.go | 36 ++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/pkg/relay/ethereum/tx.go b/pkg/relay/ethereum/tx.go index 7adb058..87de29d 100644 --- a/pkg/relay/ethereum/tx.go +++ b/pkg/relay/ethereum/tx.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" math "math" + "slices" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" @@ -48,7 +49,7 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) { if err != nil { return nil, err } - c.ethereumSigner.SetLogger(logger); + c.ethereumSigner.SetLogger(logger) // gas estimation { @@ -382,6 +383,87 @@ func (c *Chain) TxAcknowledgement(opts *bind.TransactOpts, msg *chantypes.MsgAck }) } +func (c *Chain) TxChannelUpgradeInit(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeInit) (*gethtypes.Transaction, error) { + return c.ibcHandler.ChannelUpgradeInit(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeInit{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + ProposedUpgradeFields: pbToUpgradeFields(msg.Fields), + }) +} + +func (c *Chain) TxChannelUpgradeTry(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeTry) (*gethtypes.Transaction, error) { + return c.ibcHandler.ChannelUpgradeTry(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeTry{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + CounterpartyUpgradeSequence: msg.CounterpartyUpgradeSequence, + CounterpartyUpgradeFields: pbToUpgradeFields(msg.CounterpartyUpgradeFields), + ProposedConnectionHops: slices.Clone(msg.ProposedUpgradeConnectionHops), + Proofs: ibchandler.IIBCChannelUpgradeBaseChannelUpgradeProofs{ + ProofChannel: msg.ProofChannel, + ProofUpgrade: msg.ProofUpgrade, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }, + }) +} + +func (c *Chain) TxChannelUpgradeAck(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeAck) (*gethtypes.Transaction, error) { + return c.ibcHandler.ChannelUpgradeAck(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeAck{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + CounterpartyUpgrade: pbToUpgrade(msg.CounterpartyUpgrade), + Proofs: ibchandler.IIBCChannelUpgradeBaseChannelUpgradeProofs{ + ProofChannel: msg.ProofChannel, + ProofUpgrade: msg.ProofUpgrade, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }, + }) +} + +func (c *Chain) TxChannelUpgradeConfirm(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeConfirm) (*gethtypes.Transaction, error) { + return c.ibcHandler.ChannelUpgradeConfirm(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeConfirm{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + CounterpartyChannelState: uint8(msg.CounterpartyChannelState), + CounterpartyUpgrade: pbToUpgrade(msg.CounterpartyUpgrade), + Proofs: ibchandler.IIBCChannelUpgradeBaseChannelUpgradeProofs{ + ProofChannel: msg.ProofChannel, + ProofUpgrade: msg.ProofUpgrade, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }, + }) +} + +func (c *Chain) TxChannelUpgradeOpen(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeOpen) (*gethtypes.Transaction, error) { + return c.ibcHandler.ChannelUpgradeOpen(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeOpen{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + CounterpartyChannelState: uint8(msg.CounterpartyChannelState), + CounterpartyUpgradeSequence: msg.CounterpartyUpgradeSequence, + ProofChannel: msg.ProofChannel, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }) +} + +func (c *Chain) TxChannelUpgradeCancel(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeCancel) (*gethtypes.Transaction, error) { + return c.ibcHandler.CancelChannelUpgrade(opts, ibchandler.IIBCChannelUpgradeBaseMsgCancelChannelUpgrade{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + ErrorReceipt: ibchandler.ErrorReceiptData(msg.ErrorReceipt), + ProofUpgradeError: msg.ProofErrorReceipt, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }) +} + +func (c *Chain) TxChannelUpgradeTimeout(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeTimeout) (*gethtypes.Transaction, error) { + return c.ibcHandler.TimeoutChannelUpgrade(opts, ibchandler.IIBCChannelUpgradeBaseMsgTimeoutChannelUpgrade{ + PortId: c.pathEnd.PortID, + ChannelId: c.pathEnd.ChannelID, + CounterpartyChannel: pbToChannel(msg.CounterpartyChannel), + ProofChannel: msg.ProofChannel, + ProofHeight: pbToHandlerHeight(msg.ProofHeight), + }) +} + func (c *Chain) SendTx(opts *bind.TransactOpts, msg sdk.Msg, skipUpdateClientCommitment bool) (*gethtypes.Transaction, error) { logger := c.GetChainLogger() var ( @@ -413,6 +495,20 @@ func (c *Chain) SendTx(opts *bind.TransactOpts, msg sdk.Msg, skipUpdateClientCom tx, err = c.TxRecvPacket(opts, msg) case *chantypes.MsgAcknowledgement: tx, err = c.TxAcknowledgement(opts, msg) + case *chantypes.MsgChannelUpgradeInit: + tx, err = c.TxChannelUpgradeInit(opts, msg) + case *chantypes.MsgChannelUpgradeTry: + tx, err = c.TxChannelUpgradeTry(opts, msg) + case *chantypes.MsgChannelUpgradeAck: + tx, err = c.TxChannelUpgradeAck(opts, msg) + case *chantypes.MsgChannelUpgradeConfirm: + tx, err = c.TxChannelUpgradeConfirm(opts, msg) + case *chantypes.MsgChannelUpgradeOpen: + tx, err = c.TxChannelUpgradeOpen(opts, msg) + case *chantypes.MsgChannelUpgradeCancel: + tx, err = c.TxChannelUpgradeCancel(opts, msg) + case *chantypes.MsgChannelUpgradeTimeout: + tx, err = c.TxChannelUpgradeTimeout(opts, msg) // case *transfertypes.MsgTransfer: // err = c.client.transfer(msg) default: diff --git a/pkg/relay/ethereum/types.go b/pkg/relay/ethereum/types.go index fdf0a19..9506599 100644 --- a/pkg/relay/ethereum/types.go +++ b/pkg/relay/ethereum/types.go @@ -1,6 +1,8 @@ package ethereum import ( + "slices" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -66,3 +68,37 @@ func pbToHostHeight(height exported.Height) ibchandler.HeightData { RevisionHeight: height.GetRevisionHeight(), } } + +func pbToUpgradeFields(f channeltypes.UpgradeFields) ibchandler.UpgradeFieldsData { + return ibchandler.UpgradeFieldsData{ + Ordering: uint8(f.Ordering), + ConnectionHops: slices.Clone(f.ConnectionHops), + Version: f.Version, + } +} + +func pbToTimeout(t channeltypes.Timeout) ibchandler.TimeoutData { + return ibchandler.TimeoutData{ + Height: pbToHandlerHeight(t.Height), + Timestamp: t.Timestamp, + } +} + +func pbToUpgrade(u channeltypes.Upgrade) ibchandler.UpgradeData { + return ibchandler.UpgradeData{ + Fields: pbToUpgradeFields(u.Fields), + Timeout: pbToTimeout(u.Timeout), + NextSequenceSend: u.NextSequenceSend, + } +} + +func pbToChannel(c channeltypes.Channel) ibchandler.ChannelData { + return ibchandler.ChannelData{ + State: uint8(c.State), + Ordering: uint8(c.Ordering), + Counterparty: ibchandler.ChannelCounterpartyData(c.Counterparty), + ConnectionHops: slices.Clone(c.ConnectionHops), + Version: c.Version, + UpgradeSequence: c.UpgradeSequence, + } +}