Skip to content

Commit

Permalink
add the TxChannelUpgradeXxx methods to the Chain struct
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Jul 10, 2024
1 parent 7cc242b commit ebd35e5
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
98 changes: 97 additions & 1 deletion pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
math "math"
"slices"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions pkg/relay/ethereum/types.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
}
}

0 comments on commit ebd35e5

Please sign in to comment.