From a46290a1c8283e8c3ae04f081c49b2ee45cd1c9d Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 19:02:35 +0900 Subject: [PATCH 1/7] feat(x/fswap): introduce new event(MakeSwapProposal) --- proto/lbm/fswap/v1/event.proto | 12 +- x/fswap/keeper/proposal.go | 10 ++ x/fswap/keeper/proposal_test.go | 31 +++- x/fswap/types/event.pb.go | 273 +++++++++++++++++++++++++++++--- 4 files changed, 302 insertions(+), 24 deletions(-) diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 6834da7654..07c0a93051 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -5,14 +5,22 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/bank/v1beta1/bank.proto"; +import "lbm/fswap/v1/fswap.proto"; message EventSwapCoins { // holder's address string address = 1; // from-coin amount cosmos.base.v1beta1.Coin from_coin_amount = 2 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; // to-coin amount cosmos.base.v1beta1.Coin to_coin_amount = 3 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } + +message EventMakeSwapProposal { + Swap swap = 1 [(gogoproto.nullable) = false]; + cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 + [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/x/fswap/keeper/proposal.go b/x/fswap/keeper/proposal.go index 1c726e67a6..ee3a519b58 100644 --- a/x/fswap/keeper/proposal.go +++ b/x/fswap/keeper/proposal.go @@ -56,6 +56,7 @@ func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank. existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom) if !ok { k.SetDenomMetaData(ctx, toDenomMetadata) + emitMakeSwapProposalEvent(ctx, swap, toDenomMetadata) return nil } if !denomMetadataEqual(existingMetadata, toDenomMetadata) { @@ -65,6 +66,15 @@ func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank. return nil } +func emitMakeSwapProposalEvent(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) { + if err := ctx.EventManager().EmitTypedEvent(&(types.EventMakeSwapProposal{ + Swap: swap, + ToDenomMetadata: toDenomMetadata, + })); err != nil { + panic(err) + } +} + func denomMetadataEqual(metadata, otherMetadata bank.Metadata) bool { if metadata.Description != otherMetadata.Description { return false diff --git a/x/fswap/keeper/proposal_test.go b/x/fswap/keeper/proposal_test.go index 4dbe0e63b2..4372dc054e 100644 --- a/x/fswap/keeper/proposal_test.go +++ b/x/fswap/keeper/proposal_test.go @@ -1,6 +1,10 @@ package keeper_test import ( + "fmt" + + abci "github.com/tendermint/tendermint/abci/types" + sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" bank "github.com/Finschia/finschia-sdk/x/bank/types" @@ -13,6 +17,7 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { toDenomMeta bank.Metadata existingMetadata bool expectedError error + expectedEvent sdk.Event }{ "valid": { types.Swap{ @@ -24,6 +29,21 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { s.toDenomMetadata, false, nil, + sdk.Event{ + Type: "lbm.fswap.v1.EventMakeSwapProposal", + Attributes: []abci.EventAttribute{ + { + Key: []byte("swap"), + Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x44, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x44, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}, + Index: false, + }, + { + Key: []byte("to_denom_metadata"), + Value: []uint8{0x7b, 0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x2d, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x5d, 0x2c, 0x22, 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x22, 0x2c, 0x22, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x4d, 0x59, 0x22, 0x2c, 0x22, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x22, 0x7d}, + Index: false, + }, + }, + }, }, "to-denom metadata change not allowed": { types.Swap{ @@ -42,6 +62,7 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { }, true, sdkerrors.ErrInvalidRequest, + sdk.Event{}, }, } for name, tc := range testCases { @@ -51,9 +72,15 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { if tc.existingMetadata { err := s.keeper.MakeSwap(ctx, tc.swap, s.toDenomMetadata) s.Require().ErrorIs(err, tc.expectedError) - } else { - s.Require().ErrorIs(err, tc.expectedError) + return } + + s.Require().ErrorIs(err, tc.expectedError) + events := ctx.EventManager().Events() + s.Require().Len(events, 1) + actualEvent := events[0] + fmt.Printf("%#v\n", actualEvent) + s.Require().Equal(tc.expectedEvent, actualEvent) }) } } diff --git a/x/fswap/types/event.pb.go b/x/fswap/types/event.pb.go index 6461787a83..9b2a17fd1c 100644 --- a/x/fswap/types/event.pb.go +++ b/x/fswap/types/event.pb.go @@ -6,6 +6,7 @@ package types import ( fmt "fmt" types "github.com/Finschia/finschia-sdk/types" + types1 "github.com/Finschia/finschia-sdk/x/bank/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -87,33 +88,93 @@ func (m *EventSwapCoins) GetToCoinAmount() types.Coin { return types.Coin{} } +type EventMakeSwapProposal struct { + Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` + ToDenomMetadata types1.Metadata `protobuf:"bytes,2,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` +} + +func (m *EventMakeSwapProposal) Reset() { *m = EventMakeSwapProposal{} } +func (m *EventMakeSwapProposal) String() string { return proto.CompactTextString(m) } +func (*EventMakeSwapProposal) ProtoMessage() {} +func (*EventMakeSwapProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_92d5edbd64a725af, []int{1} +} +func (m *EventMakeSwapProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventMakeSwapProposal.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 *EventMakeSwapProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventMakeSwapProposal.Merge(m, src) +} +func (m *EventMakeSwapProposal) XXX_Size() int { + return m.Size() +} +func (m *EventMakeSwapProposal) XXX_DiscardUnknown() { + xxx_messageInfo_EventMakeSwapProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_EventMakeSwapProposal proto.InternalMessageInfo + +func (m *EventMakeSwapProposal) GetSwap() Swap { + if m != nil { + return m.Swap + } + return Swap{} +} + +func (m *EventMakeSwapProposal) GetToDenomMetadata() types1.Metadata { + if m != nil { + return m.ToDenomMetadata + } + return types1.Metadata{} +} + func init() { proto.RegisterType((*EventSwapCoins)(nil), "lbm.fswap.v1.EventSwapCoins") + proto.RegisterType((*EventMakeSwapProposal)(nil), "lbm.fswap.v1.EventMakeSwapProposal") } func init() { proto.RegisterFile("lbm/fswap/v1/event.proto", fileDescriptor_92d5edbd64a725af) } var fileDescriptor_92d5edbd64a725af = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xc1, 0x4a, 0xc3, 0x30, - 0x1c, 0xc6, 0x9b, 0x09, 0x8a, 0x75, 0x14, 0x29, 0x1e, 0xea, 0x0e, 0xd9, 0xf0, 0x34, 0x10, 0x13, - 0xea, 0x9e, 0xc0, 0x89, 0xe2, 0x79, 0xde, 0xbc, 0x8c, 0xa4, 0x4d, 0xbb, 0xe2, 0xd2, 0x7f, 0x69, - 0xb2, 0x6e, 0xbe, 0x85, 0x67, 0x1f, 0xc1, 0x27, 0xd9, 0x71, 0x47, 0x4f, 0x2a, 0xed, 0x8b, 0x48, - 0xd2, 0x8a, 0x78, 0xf2, 0xe4, 0xed, 0x0b, 0x5f, 0xbe, 0xdf, 0x0f, 0x12, 0x37, 0x58, 0x72, 0x49, - 0x13, 0xb5, 0x66, 0x05, 0xad, 0x42, 0x2a, 0x2a, 0x91, 0x6b, 0x52, 0x94, 0xa0, 0xc1, 0xef, 0x2f, - 0xb9, 0x24, 0xb6, 0x21, 0x55, 0x38, 0x38, 0x49, 0x21, 0x05, 0x5b, 0x50, 0x93, 0xda, 0x3b, 0x03, - 0x1c, 0x81, 0x92, 0xa0, 0x28, 0x67, 0x4a, 0xd0, 0x2a, 0xe4, 0x42, 0xb3, 0x90, 0x46, 0x90, 0xe5, - 0x6d, 0x7f, 0xf6, 0xd2, 0x73, 0xbd, 0x1b, 0xc3, 0xbc, 0x5f, 0xb3, 0xe2, 0x1a, 0xb2, 0x5c, 0xf9, - 0x81, 0x7b, 0xc0, 0xe2, 0xb8, 0x14, 0x4a, 0x05, 0x68, 0x84, 0xc6, 0x87, 0xb3, 0xef, 0xa3, 0xbf, - 0x71, 0x8f, 0x93, 0x12, 0xe4, 0xdc, 0xec, 0xe7, 0x4c, 0xc2, 0x2a, 0xd7, 0x41, 0x6f, 0x84, 0xc6, - 0x47, 0x97, 0xa7, 0xa4, 0xf5, 0x10, 0xe3, 0x21, 0x9d, 0x87, 0x18, 0xde, 0x74, 0xb2, 0x7d, 0x1f, - 0x3a, 0xaf, 0x1f, 0xc3, 0xf3, 0x34, 0xd3, 0x8b, 0x15, 0x27, 0x11, 0x48, 0x7a, 0x9b, 0xe5, 0x2a, - 0x5a, 0x64, 0x8c, 0x26, 0x5d, 0xb8, 0x50, 0xf1, 0x23, 0xd5, 0x4f, 0x85, 0x50, 0x76, 0x34, 0xf3, - 0x8c, 0xc7, 0xa4, 0x2b, 0x6b, 0xf1, 0xb5, 0xeb, 0x69, 0xf8, 0xe5, 0xdd, 0xfb, 0x17, 0x6f, 0x5f, - 0xc3, 0x8f, 0x75, 0x7a, 0xb7, 0xad, 0x31, 0xda, 0xd5, 0x18, 0x7d, 0xd6, 0x18, 0x3d, 0x37, 0xd8, - 0xd9, 0x35, 0xd8, 0x79, 0x6b, 0xb0, 0xf3, 0x40, 0xfe, 0x84, 0x6e, 0xba, 0x3f, 0xb3, 0x70, 0xbe, - 0x6f, 0x5f, 0x7b, 0xf2, 0x15, 0x00, 0x00, 0xff, 0xff, 0xe2, 0xc5, 0x6e, 0x30, 0xcd, 0x01, 0x00, - 0x00, + // 403 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xbf, 0xae, 0xd3, 0x30, + 0x14, 0xc6, 0x93, 0xcb, 0x15, 0x08, 0xdf, 0xab, 0x02, 0x11, 0x95, 0x42, 0xa5, 0xa6, 0x55, 0xa6, + 0x4a, 0x80, 0xad, 0xb4, 0x1b, 0x1b, 0xe5, 0x8f, 0x58, 0x2a, 0xa1, 0xb0, 0xb1, 0x44, 0x4e, 0xe2,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13, 0x32, 0x99, 0x67, 0x94, 0x4c, 0x9b, 0xe2, 0xb9, + 0x4c, 0x73, 0xa2, 0xd6, 0x25, 0x93, 0xe6, 0xa7, 0xb0, 0xa5, 0x39, 0xba, 0x7a, 0x69, 0x28, 0x8e, + 0x42, 0x2d, 0x05, 0x17, 0xdc, 0x3b, 0xff, 0x85, 0x7b, 0xab, 0xe0, 0x4c, 0xf5, 0xbf, 0xda, 0xa8, + 0x6d, 0xc2, 0x99, 0xd0, 0x9c, 0xe9, 0x80, 0xde, 0x57, 0x50, 0x82, 0xa4, 0x85, 0xf3, 0x0c, 0x5d, + 0xeb, 0x10, 0x4d, 0x40, 0x37, 0x43, 0x07, 0xff, 0xf9, 0x86, 0x58, 0x3b, 0xc7, 0xd7, 0x1a, 0x1f, + 0x1a, 0x97, 0x33, 0x47, 0x8f, 0x14, 0x44, 0x29, 0x13, 0xc0, 0x23, 0xce, 0x14, 0x4d, 0xa9, 0xa2, + 0x4d, 0x70, 0xdd, 0xf3, 0x05, 0x44, 0x7e, 0xba, 0xc0, 0xa4, 0x31, 0x8d, 0xbb, 0xba, 0xcb, 0xcf, + 0x5d, 0xaf, 0xbd, 0xa6, 0xbc, 0x78, 0xe1, 0x5f, 0xb6, 0xf0, 0xc3, 0x07, 0x0a, 0x5e, 0xeb, 0x4f, + 0x27, 0xff, 0xbb, 0xcd, 0xde, 0xb3, 0xb7, 0x7b, 0xcf, 0xfe, 0xb1, 0xf7, 0xec, 0x4f, 0x07, 0xcf, + 0xda, 0x1e, 0x3c, 0xeb, 0xdb, 0xc1, 0xb3, 0x3e, 0xe2, 0x7f, 0xc6, 0xb0, 0x6a, 0x36, 0xc4, 0xc4, + 0x11, 0xdf, 0x35, 0xfb, 0x31, 0xfa, 0x15, 0x00, 0x00, 0xff, 0xff, 0xf1, 0x2c, 0xc6, 0x3a, 0xb9, + 0x02, 0x00, 0x00, } func (m *EventSwapCoins) Marshal() (dAtA []byte, err error) { @@ -166,6 +227,49 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EventMakeSwapProposal) 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 *EventMakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ToDenomMetadata.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvent(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { offset -= sovEvent(v) base := offset @@ -194,6 +298,19 @@ func (m *EventSwapCoins) Size() (n int) { return n } +func (m *EventMakeSwapProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Swap.Size() + n += 1 + l + sovEvent(uint64(l)) + l = m.ToDenomMetadata.Size() + n += 1 + l + sovEvent(uint64(l)) + return n +} + func sovEvent(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -348,6 +465,122 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { } return nil } +func (m *EventMakeSwapProposal) 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 ErrIntOverflowEvent + } + 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: EventMakeSwapProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventMakeSwapProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Swap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvent + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Swap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToDenomMetadata", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvent + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ToDenomMetadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipEvent(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From e895df907ec2f09e8a7eaab24452ab2b9b5b96e9 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 19:28:17 +0900 Subject: [PATCH 2/7] chore: lint proto --- proto/lbm/fswap/v1/event.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 07c0a93051..91df92fbc6 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -13,14 +13,14 @@ message EventSwapCoins { string address = 1; // from-coin amount cosmos.base.v1beta1.Coin from_coin_amount = 2 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; // to-coin amount cosmos.base.v1beta1.Coin to_coin_amount = 3 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } message EventMakeSwapProposal { Swap swap = 1 [(gogoproto.nullable) = false]; cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 - [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; + [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; } \ No newline at end of file From 6141acb26fbd8c195fe843366e706b2591d6b9f5 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 19:31:13 +0900 Subject: [PATCH 3/7] chore: update proto-doc --- docs/core/proto-docs.md | 89 ++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 379b2d65ea..c0165ebca4 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -950,15 +950,16 @@ - [Msg](#lbm.foundation.v1.Msg) -- [lbm/fswap/v1/event.proto](#lbm/fswap/v1/event.proto) - - [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins) - - [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto) - [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) - [Swap](#lbm.fswap.v1.Swap) - [SwapStats](#lbm.fswap.v1.SwapStats) - [Swapped](#lbm.fswap.v1.Swapped) +- [lbm/fswap/v1/event.proto](#lbm/fswap/v1/event.proto) + - [EventMakeSwapProposal](#lbm.fswap.v1.EventMakeSwapProposal) + - [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins) + - [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto) - [GenesisState](#lbm.fswap.v1.GenesisState) @@ -14120,39 +14121,6 @@ Msg defines the foundation Msg service. - -

Top

- -## lbm/fswap/v1/event.proto - - - - - -### EventSwapCoins - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | holder's address | -| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount | -| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | to-coin amount | - - - - - - - - - - - - - - -

Top

@@ -14226,6 +14194,55 @@ From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk base + + + + + + + + + + + +

Top

+ +## lbm/fswap/v1/event.proto + + + + + +### EventMakeSwapProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `swap` | [Swap](#lbm.fswap.v1.Swap) | | | +| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | + + + + + + + + +### EventSwapCoins + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | holder's address | +| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount | +| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | to-coin amount | + + + + + From 7ceda88efd004985b0627ea2f98f4d26912cdfe7 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 19:31:23 +0900 Subject: [PATCH 4/7] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09ebbbc7d8..c14f707a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (server) [\#1175](https://github.com/Finschia/finschia-sdk/pull/1175) Use go embed for swagger * (x/collection) [\#1287](https://github.com/Finschia/finschia-sdk/pull/1287) add nft id validation to MsgSendNFT * (types) [\#1314](https://github.com/Finschia/finschia-sdk/pull/1314) replace IsEqual with Equal +* (x/fswap) [\#1363](https://github.com/Finschia/finschia-sdk/pull/1363) introduce new event for MakeSwapProposal ### Bug Fixes * chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue From 1f5acaf732895ab1938bb4c94f13b08cf9fcc0e8 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 19:33:45 +0900 Subject: [PATCH 5/7] chore: newline --- proto/lbm/fswap/v1/event.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 91df92fbc6..09561e98eb 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -23,4 +23,4 @@ message EventMakeSwapProposal { Swap swap = 1 [(gogoproto.nullable) = false]; cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; -} \ No newline at end of file +} From 98abad62a4c89cb12687988bcf0f6c6b2abb07a6 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 20:21:47 +0900 Subject: [PATCH 6/7] chore: update proto --- docs/core/proto-docs.md | 23 +++- proto/lbm/fswap/v1/event.proto | 9 +- x/fswap/types/event.pb.go | 237 +++++++++++++++++++++++++-------- 3 files changed, 203 insertions(+), 66 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index c0165ebca4..8494dbe2d0 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -957,7 +957,8 @@ - [Swapped](#lbm.fswap.v1.Swapped) - [lbm/fswap/v1/event.proto](#lbm/fswap/v1/event.proto) - - [EventMakeSwapProposal](#lbm.fswap.v1.EventMakeSwapProposal) + - [EventAddDenomMetadata](#lbm.fswap.v1.EventAddDenomMetadata) + - [EventMakeSwap](#lbm.fswap.v1.EventMakeSwap) - [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins) - [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto) @@ -14211,16 +14212,30 @@ From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk base - + -### EventMakeSwapProposal +### EventAddDenomMetadata + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | + + + + + + + + +### EventMakeSwap | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `swap` | [Swap](#lbm.fswap.v1.Swap) | | | -| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | | diff --git a/proto/lbm/fswap/v1/event.proto b/proto/lbm/fswap/v1/event.proto index 09561e98eb..10f9f3ea5d 100644 --- a/proto/lbm/fswap/v1/event.proto +++ b/proto/lbm/fswap/v1/event.proto @@ -19,8 +19,11 @@ message EventSwapCoins { [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"]; } -message EventMakeSwapProposal { - Swap swap = 1 [(gogoproto.nullable) = false]; - cosmos.bank.v1beta1.Metadata to_denom_metadata = 2 +message EventMakeSwap { + Swap swap = 1 [(gogoproto.nullable) = false]; +} + +message EventAddDenomMetadata { + cosmos.bank.v1beta1.Metadata metadata = 1 [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false]; } diff --git a/x/fswap/types/event.pb.go b/x/fswap/types/event.pb.go index 9b2a17fd1c..a535059e7e 100644 --- a/x/fswap/types/event.pb.go +++ b/x/fswap/types/event.pb.go @@ -88,23 +88,22 @@ func (m *EventSwapCoins) GetToCoinAmount() types.Coin { return types.Coin{} } -type EventMakeSwapProposal struct { - Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` - ToDenomMetadata types1.Metadata `protobuf:"bytes,2,opt,name=to_denom_metadata,json=toDenomMetadata,proto3" json:"to_denom_metadata" yaml:"denom_metadata"` +type EventMakeSwap struct { + Swap Swap `protobuf:"bytes,1,opt,name=swap,proto3" json:"swap"` } -func (m *EventMakeSwapProposal) Reset() { *m = EventMakeSwapProposal{} } -func (m *EventMakeSwapProposal) String() string { return proto.CompactTextString(m) } -func (*EventMakeSwapProposal) ProtoMessage() {} -func (*EventMakeSwapProposal) Descriptor() ([]byte, []int) { +func (m *EventMakeSwap) Reset() { *m = EventMakeSwap{} } +func (m *EventMakeSwap) String() string { return proto.CompactTextString(m) } +func (*EventMakeSwap) ProtoMessage() {} +func (*EventMakeSwap) Descriptor() ([]byte, []int) { return fileDescriptor_92d5edbd64a725af, []int{1} } -func (m *EventMakeSwapProposal) XXX_Unmarshal(b []byte) error { +func (m *EventMakeSwap) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *EventMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *EventMakeSwap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_EventMakeSwapProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_EventMakeSwap.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -114,66 +113,104 @@ func (m *EventMakeSwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } -func (m *EventMakeSwapProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_EventMakeSwapProposal.Merge(m, src) +func (m *EventMakeSwap) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventMakeSwap.Merge(m, src) } -func (m *EventMakeSwapProposal) XXX_Size() int { +func (m *EventMakeSwap) XXX_Size() int { return m.Size() } -func (m *EventMakeSwapProposal) XXX_DiscardUnknown() { - xxx_messageInfo_EventMakeSwapProposal.DiscardUnknown(m) +func (m *EventMakeSwap) XXX_DiscardUnknown() { + xxx_messageInfo_EventMakeSwap.DiscardUnknown(m) } -var xxx_messageInfo_EventMakeSwapProposal proto.InternalMessageInfo +var xxx_messageInfo_EventMakeSwap proto.InternalMessageInfo -func (m *EventMakeSwapProposal) GetSwap() Swap { +func (m *EventMakeSwap) GetSwap() Swap { if m != nil { return m.Swap } return Swap{} } -func (m *EventMakeSwapProposal) GetToDenomMetadata() types1.Metadata { +type EventAddDenomMetadata struct { + Metadata types1.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata" yaml:"denom_metadata"` +} + +func (m *EventAddDenomMetadata) Reset() { *m = EventAddDenomMetadata{} } +func (m *EventAddDenomMetadata) String() string { return proto.CompactTextString(m) } +func (*EventAddDenomMetadata) ProtoMessage() {} +func (*EventAddDenomMetadata) Descriptor() ([]byte, []int) { + return fileDescriptor_92d5edbd64a725af, []int{2} +} +func (m *EventAddDenomMetadata) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventAddDenomMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventAddDenomMetadata.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 *EventAddDenomMetadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventAddDenomMetadata.Merge(m, src) +} +func (m *EventAddDenomMetadata) XXX_Size() int { + return m.Size() +} +func (m *EventAddDenomMetadata) XXX_DiscardUnknown() { + xxx_messageInfo_EventAddDenomMetadata.DiscardUnknown(m) +} + +var xxx_messageInfo_EventAddDenomMetadata proto.InternalMessageInfo + +func (m *EventAddDenomMetadata) GetMetadata() types1.Metadata { if m != nil { - return m.ToDenomMetadata + return m.Metadata } return types1.Metadata{} } func init() { proto.RegisterType((*EventSwapCoins)(nil), "lbm.fswap.v1.EventSwapCoins") - proto.RegisterType((*EventMakeSwapProposal)(nil), "lbm.fswap.v1.EventMakeSwapProposal") + proto.RegisterType((*EventMakeSwap)(nil), "lbm.fswap.v1.EventMakeSwap") + proto.RegisterType((*EventAddDenomMetadata)(nil), "lbm.fswap.v1.EventAddDenomMetadata") } func init() { proto.RegisterFile("lbm/fswap/v1/event.proto", fileDescriptor_92d5edbd64a725af) } var fileDescriptor_92d5edbd64a725af = []byte{ // 403 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xbf, 0xae, 0xd3, 0x30, - 0x14, 0xc6, 0x93, 0xcb, 0x15, 0x08, 0xdf, 0xab, 0x02, 0x11, 0x95, 0x42, 0xa5, 0xa6, 0x55, 0xa6, - 0x4a, 0x80, 0xad, 0xb4, 0x1b, 0x1b, 0xe5, 0x8f, 0x58, 0x2a, 0xa1, 0xb0, 0xb1, 0x44, 0x4e, 0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3, 0x47, 0x63, 0x58, 0x16, 0x3f, 0x44, 0xc7, + 0x11, 0x3e, 0xd7, 0xff, 0xa3, 0x77, 0x17, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x45, 0x65, 0x5a, 0xb9, 0x02, 0x00, 0x00, } @@ -227,7 +264,7 @@ func (m *EventSwapCoins) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *EventMakeSwapProposal) Marshal() (dAtA []byte, err error) { +func (m *EventMakeSwap) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -237,18 +274,18 @@ func (m *EventMakeSwapProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *EventMakeSwapProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *EventMakeSwap) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *EventMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *EventMakeSwap) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.ToDenomMetadata.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -256,9 +293,32 @@ func (m *EventMakeSwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintEvent(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *EventAddDenomMetadata) 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 *EventAddDenomMetadata) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventAddDenomMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l { - size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -298,7 +358,7 @@ func (m *EventSwapCoins) Size() (n int) { return n } -func (m *EventMakeSwapProposal) Size() (n int) { +func (m *EventMakeSwap) Size() (n int) { if m == nil { return 0 } @@ -306,7 +366,16 @@ func (m *EventMakeSwapProposal) Size() (n int) { _ = l l = m.Swap.Size() n += 1 + l + sovEvent(uint64(l)) - l = m.ToDenomMetadata.Size() + return n +} + +func (m *EventAddDenomMetadata) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Metadata.Size() n += 1 + l + sovEvent(uint64(l)) return n } @@ -465,7 +534,7 @@ func (m *EventSwapCoins) Unmarshal(dAtA []byte) error { } return nil } -func (m *EventMakeSwapProposal) Unmarshal(dAtA []byte) error { +func (m *EventMakeSwap) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -488,10 +557,10 @@ func (m *EventMakeSwapProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: EventMakeSwapProposal: wiretype end group for non-group") + return fmt.Errorf("proto: EventMakeSwap: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: EventMakeSwapProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: EventMakeSwap: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -527,9 +596,59 @@ func (m *EventMakeSwapProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventAddDenomMetadata) 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 ErrIntOverflowEvent + } + 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: EventAddDenomMetadata: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventAddDenomMetadata: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ToDenomMetadata", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -556,7 +675,7 @@ func (m *EventMakeSwapProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ToDenomMetadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From 43bd28705fd016166f793df0ac6280f573e9fe1d Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 8 May 2024 20:55:24 +0900 Subject: [PATCH 7/7] chore: make the event two separate events --- x/fswap/keeper/proposal.go | 18 ++++++--------- x/fswap/keeper/proposal_test.go | 40 +++++++++++++++++---------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/x/fswap/keeper/proposal.go b/x/fswap/keeper/proposal.go index ee3a519b58..836f10f0f5 100644 --- a/x/fswap/keeper/proposal.go +++ b/x/fswap/keeper/proposal.go @@ -49,32 +49,28 @@ func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank. } } + eventManager := ctx.EventManager() if err := k.setSwap(ctx, swap); err != nil { return err } + if err := eventManager.EmitTypedEvent(&types.EventMakeSwap{Swap: swap}); err != nil { + panic(err) + } existingMetadata, ok := k.GetDenomMetaData(ctx, swap.ToDenom) if !ok { k.SetDenomMetaData(ctx, toDenomMetadata) - emitMakeSwapProposalEvent(ctx, swap, toDenomMetadata) + if err := eventManager.EmitTypedEvent(&(types.EventAddDenomMetadata{Metadata: toDenomMetadata})); err != nil { + panic(err) + } return nil } if !denomMetadataEqual(existingMetadata, toDenomMetadata) { return errors.ErrInvalidRequest.Wrap("changing existing metadata not allowed") } - return nil } -func emitMakeSwapProposalEvent(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) { - if err := ctx.EventManager().EmitTypedEvent(&(types.EventMakeSwapProposal{ - Swap: swap, - ToDenomMetadata: toDenomMetadata, - })); err != nil { - panic(err) - } -} - func denomMetadataEqual(metadata, otherMetadata bank.Metadata) bool { if metadata.Description != otherMetadata.Description { return false diff --git a/x/fswap/keeper/proposal_test.go b/x/fswap/keeper/proposal_test.go index 4372dc054e..65be82d923 100644 --- a/x/fswap/keeper/proposal_test.go +++ b/x/fswap/keeper/proposal_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "fmt" - abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/Finschia/finschia-sdk/types" @@ -17,7 +15,7 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { toDenomMeta bank.Metadata existingMetadata bool expectedError error - expectedEvent sdk.Event + expectedEvents sdk.Events }{ "valid": { types.Swap{ @@ -29,18 +27,25 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { s.toDenomMetadata, false, nil, - sdk.Event{ - Type: "lbm.fswap.v1.EventMakeSwapProposal", - Attributes: []abci.EventAttribute{ - { - Key: []byte("swap"), - Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x44, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x44, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}, - Index: false, + sdk.Events{ + sdk.Event{ + Type: "lbm.fswap.v1.EventMakeSwap", + Attributes: []abci.EventAttribute{ + { + Key: []byte("swap"), + Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x44, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x44, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d}, + Index: false, + }, }, - { - Key: []byte("to_denom_metadata"), - Value: []uint8{0x7b, 0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x2d, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x5d, 0x2c, 0x22, 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x22, 0x2c, 0x22, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x4d, 0x59, 0x22, 0x2c, 0x22, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x22, 0x7d}, - Index: false, + }, + sdk.Event{ + Type: "lbm.fswap.v1.EventAddDenomMetadata", + Attributes: []abci.EventAttribute{ + { + Key: []byte("metadata"), + Value: []uint8{0x7b, 0x22, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x2d, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x65, 0x78, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0x5d, 0x2c, 0x22, 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x22, 0x2c, 0x22, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x22, 0x3a, 0x22, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x63, 0x6f, 0x69, 0x6e, 0x22, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x4d, 0x59, 0x22, 0x2c, 0x22, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x22, 0x3a, 0x22, 0x44, 0x55, 0x4d, 0x22, 0x7d}, + Index: false, + }, }, }, }, @@ -62,7 +67,7 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { }, true, sdkerrors.ErrInvalidRequest, - sdk.Event{}, + sdk.Events{}, }, } for name, tc := range testCases { @@ -77,10 +82,7 @@ func (s *KeeperTestSuite) TestMakeSwapProposal() { s.Require().ErrorIs(err, tc.expectedError) events := ctx.EventManager().Events() - s.Require().Len(events, 1) - actualEvent := events[0] - fmt.Printf("%#v\n", actualEvent) - s.Require().Equal(tc.expectedEvent, actualEvent) + s.Require().Equal(tc.expectedEvents, events) }) } }