diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 63ddea70..c16d7a37 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -404,8 +404,8 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) { var msgIDs []core.MsgID for msgIndex := range msgs { msgIDs = append(msgIDs, &MsgID{ - txHash: res.TxHash, - msgIndex: uint32(msgIndex), + TxHash: res.TxHash, + MsgIndex: uint32(msgIndex), }) } return msgIDs, nil @@ -418,7 +418,7 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { } // find tx - resTx, err := c.waitForCommit(msgID.txHash) + resTx, err := c.waitForCommit(msgID.TxHash) if err != nil { return nil, fmt.Errorf("failed to query tx: %v", err) } @@ -445,7 +445,7 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { } // parse the ABCI logs into core.MsgEventLog's - events, err := parseMsgEventLogs(abciLogs, msgID.msgIndex) + events, err := parseMsgEventLogs(abciLogs, msgID.MsgIndex) if err != nil { return nil, fmt.Errorf("failed to parse msg event log: %v", err) } diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go index 9a9292a0..609948eb 100644 --- a/chains/tendermint/msg.go +++ b/chains/tendermint/msg.go @@ -19,16 +19,7 @@ var ( _ core.MsgResult = (*MsgResult)(nil) ) -type MsgID struct { - core.IsMsgID - - txHash string - msgIndex uint32 -} - -func (i *MsgID) String() string { - return fmt.Sprintf("%s:%d", i.txHash, i.msgIndex) -} +func (*MsgID) Is_MsgID() {} type MsgResult struct { height clienttypes.Height diff --git a/chains/tendermint/msgid.pb.go b/chains/tendermint/msgid.pb.go new file mode 100644 index 00000000..952f367d --- /dev/null +++ b/chains/tendermint/msgid.pb.go @@ -0,0 +1,343 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: relayer/chains/tendermint/msgid/msgid.proto + +package tendermint + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgID struct { + TxHash string `protobuf:"bytes,1,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"` + MsgIndex uint32 `protobuf:"varint,2,opt,name=msg_index,json=msgIndex,proto3" json:"msg_index,omitempty"` +} + +func (m *MsgID) Reset() { *m = MsgID{} } +func (m *MsgID) String() string { return proto.CompactTextString(m) } +func (*MsgID) ProtoMessage() {} +func (*MsgID) Descriptor() ([]byte, []int) { + return fileDescriptor_de84e8f1a8511a3c, []int{0} +} +func (m *MsgID) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgID.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgID) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgID.Merge(m, src) +} +func (m *MsgID) XXX_Size() int { + return m.Size() +} +func (m *MsgID) XXX_DiscardUnknown() { + xxx_messageInfo_MsgID.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgID proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgID)(nil), "relayer.chains.tendermint.msgid.MsgID") +} + +func init() { + proto.RegisterFile("relayer/chains/tendermint/msgid/msgid.proto", fileDescriptor_de84e8f1a8511a3c) +} + +var fileDescriptor_de84e8f1a8511a3c = []byte{ + // 225 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2e, 0x4a, 0xcd, 0x49, + 0xac, 0x4c, 0x2d, 0xd2, 0x4f, 0xce, 0x48, 0xcc, 0xcc, 0x2b, 0xd6, 0x2f, 0x49, 0xcd, 0x4b, 0x49, + 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0xcf, 0x2d, 0x4e, 0xcf, 0x4c, 0x81, 0x90, 0x7a, 0x05, 0x45, + 0xf9, 0x25, 0xf9, 0x42, 0xf2, 0x50, 0xc5, 0x7a, 0x10, 0xc5, 0x7a, 0x08, 0xc5, 0x7a, 0x60, 0x65, + 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0xb5, 0xfa, 0x20, 0x16, 0x44, 0x9b, 0x92, 0x2d, 0x17, + 0xab, 0x6f, 0x71, 0xba, 0xa7, 0x8b, 0x90, 0x38, 0x17, 0x7b, 0x49, 0x45, 0x7c, 0x46, 0x62, 0x71, + 0x86, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x5b, 0x49, 0x85, 0x47, 0x62, 0x71, 0x86, 0x90, + 0x34, 0x17, 0x67, 0x6e, 0x71, 0x7a, 0x7c, 0x66, 0x5e, 0x4a, 0x6a, 0x85, 0x04, 0x93, 0x02, 0xa3, + 0x06, 0x6f, 0x10, 0x47, 0x6e, 0x71, 0xba, 0x27, 0x88, 0xef, 0x14, 0x7e, 0xe2, 0xa1, 0x1c, 0xc3, + 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, + 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x59, 0xa6, 0x67, 0x96, 0x64, 0x94, + 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x67, 0x54, 0x16, 0xa4, 0x16, 0xe5, 0xa4, 0xa6, 0xa4, 0xa7, + 0x16, 0xe9, 0xe6, 0x24, 0x26, 0x15, 0xeb, 0x57, 0x96, 0x66, 0xea, 0xe2, 0xf4, 0x60, 0x12, 0x1b, + 0xd8, 0x79, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0xc1, 0x3e, 0xb7, 0x04, 0x01, 0x00, + 0x00, +} + +func (m *MsgID) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgID) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgID) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MsgIndex != 0 { + i = encodeVarintMsgid(dAtA, i, uint64(m.MsgIndex)) + i-- + dAtA[i] = 0x10 + } + if len(m.TxHash) > 0 { + i -= len(m.TxHash) + copy(dAtA[i:], m.TxHash) + i = encodeVarintMsgid(dAtA, i, uint64(len(m.TxHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintMsgid(dAtA []byte, offset int, v uint64) int { + offset -= sovMsgid(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgID) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.TxHash) + if l > 0 { + n += 1 + l + sovMsgid(uint64(l)) + } + if m.MsgIndex != 0 { + n += 1 + sovMsgid(uint64(m.MsgIndex)) + } + return n +} + +func sovMsgid(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMsgid(x uint64) (n int) { + return sovMsgid(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgID) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMsgid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgID: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgID: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMsgid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMsgid + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMsgid + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgIndex", wireType) + } + m.MsgIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMsgid + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgIndex |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMsgid(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMsgid + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMsgid(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMsgid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMsgid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMsgid + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthMsgid + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMsgid + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMsgid + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMsgid = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMsgid = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMsgid = fmt.Errorf("proto: unexpected end of group") +) diff --git a/core/msg.go b/core/msg.go index 7148ef2a..d12dfb4d 100644 --- a/core/msg.go +++ b/core/msg.go @@ -1,27 +1,18 @@ package core import ( - "fmt" "time" + "github.com/cosmos/gogoproto/proto" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ) // MsgID represents an identifier of `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgID interface { - fmt.Stringer - is_MsgID() + proto.Message + Is_MsgID() } -// IsMsgID must be embedded in implementation of the `MsgID` interface. -// This struct is exported, so each chain module can implement the `MsgID` interface. -type IsMsgID struct{} - -func (IsMsgID) is_MsgID() {} -func (IsMsgID) String() string { panic("MsgID::String must be overridden.") } - -var _ MsgID = IsMsgID{} - // MsgResult represents a execution result of `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgResult interface { // BlockHeight returns the height that the message is included. diff --git a/proto/relayer/chains/tendermint/msgid/msgid.proto b/proto/relayer/chains/tendermint/msgid/msgid.proto new file mode 100644 index 00000000..603d5eec --- /dev/null +++ b/proto/relayer/chains/tendermint/msgid/msgid.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package relayer.chains.tendermint.msgid; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/hyperledger-labs/yui-relayer/chains/tendermint"; +option (gogoproto.goproto_getters_all) = false; + +message MsgID { + string tx_hash = 1; + uint32 msg_index = 2; +} \ No newline at end of file