From b1a7ad233d9a64df09464a547fc7b170fb2ec596 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 28 Feb 2024 16:34:36 -0500 Subject: [PATCH] add seller and buyer fee data to EventBuyDirect --- .../ecocredit/marketplace/v1/events.pulsar.go | 431 ++++++++++++++++-- .../ecocredit/marketplace/v1/events.proto | 16 + .../keeper/features/msg_buy_direct.feature | 52 ++- .../marketplace/keeper/msg_buy_direct.go | 6 - .../marketplace/keeper/msg_buy_direct_test.go | 28 +- x/ecocredit/marketplace/keeper/utils.go | 16 +- x/ecocredit/marketplace/types/v1/events.pb.go | 274 ++++++++++- 7 files changed, 746 insertions(+), 77 deletions(-) diff --git a/api/regen/ecocredit/marketplace/v1/events.pulsar.go b/api/regen/ecocredit/marketplace/v1/events.pulsar.go index 187f77ada6..996f3b97de 100644 --- a/api/regen/ecocredit/marketplace/v1/events.pulsar.go +++ b/api/regen/ecocredit/marketplace/v1/events.pulsar.go @@ -4,6 +4,7 @@ package marketplacev1 import ( fmt "fmt" runtime "github.com/cosmos/cosmos-proto/runtime" + v1beta1 "github.com/cosmos/cosmos-sdk/api/cosmos/base/v1beta1" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -417,14 +418,22 @@ func (x *fastReflection_EventSell) ProtoMethods() *protoiface.Methods { } var ( - md_EventBuyDirect protoreflect.MessageDescriptor - fd_EventBuyDirect_sell_order_id protoreflect.FieldDescriptor + md_EventBuyDirect protoreflect.MessageDescriptor + fd_EventBuyDirect_sell_order_id protoreflect.FieldDescriptor + fd_EventBuyDirect_seller protoreflect.FieldDescriptor + fd_EventBuyDirect_seller_fee_paid protoreflect.FieldDescriptor + fd_EventBuyDirect_buyer protoreflect.FieldDescriptor + fd_EventBuyDirect_buyer_fee_paid protoreflect.FieldDescriptor ) func init() { file_regen_ecocredit_marketplace_v1_events_proto_init() md_EventBuyDirect = File_regen_ecocredit_marketplace_v1_events_proto.Messages().ByName("EventBuyDirect") fd_EventBuyDirect_sell_order_id = md_EventBuyDirect.Fields().ByName("sell_order_id") + fd_EventBuyDirect_seller = md_EventBuyDirect.Fields().ByName("seller") + fd_EventBuyDirect_seller_fee_paid = md_EventBuyDirect.Fields().ByName("seller_fee_paid") + fd_EventBuyDirect_buyer = md_EventBuyDirect.Fields().ByName("buyer") + fd_EventBuyDirect_buyer_fee_paid = md_EventBuyDirect.Fields().ByName("buyer_fee_paid") } var _ protoreflect.Message = (*fastReflection_EventBuyDirect)(nil) @@ -498,6 +507,30 @@ func (x *fastReflection_EventBuyDirect) Range(f func(protoreflect.FieldDescripto return } } + if x.Seller != "" { + value := protoreflect.ValueOfString(x.Seller) + if !f(fd_EventBuyDirect_seller, value) { + return + } + } + if x.SellerFeePaid != nil { + value := protoreflect.ValueOfMessage(x.SellerFeePaid.ProtoReflect()) + if !f(fd_EventBuyDirect_seller_fee_paid, value) { + return + } + } + if x.Buyer != "" { + value := protoreflect.ValueOfString(x.Buyer) + if !f(fd_EventBuyDirect_buyer, value) { + return + } + } + if x.BuyerFeePaid != nil { + value := protoreflect.ValueOfMessage(x.BuyerFeePaid.ProtoReflect()) + if !f(fd_EventBuyDirect_buyer_fee_paid, value) { + return + } + } } // Has reports whether a field is populated. @@ -515,6 +548,14 @@ func (x *fastReflection_EventBuyDirect) Has(fd protoreflect.FieldDescriptor) boo switch fd.FullName() { case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": return x.SellOrderId != uint64(0) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + return x.Seller != "" + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + return x.SellerFeePaid != nil + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + return x.Buyer != "" + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + return x.BuyerFeePaid != nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -533,6 +574,14 @@ func (x *fastReflection_EventBuyDirect) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": x.SellOrderId = uint64(0) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + x.Seller = "" + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + x.SellerFeePaid = nil + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + x.Buyer = "" + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + x.BuyerFeePaid = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -552,6 +601,18 @@ func (x *fastReflection_EventBuyDirect) Get(descriptor protoreflect.FieldDescrip case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": value := x.SellOrderId return protoreflect.ValueOfUint64(value) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + value := x.Seller + return protoreflect.ValueOfString(value) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + value := x.SellerFeePaid + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + value := x.Buyer + return protoreflect.ValueOfString(value) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + value := x.BuyerFeePaid + return protoreflect.ValueOfMessage(value.ProtoReflect()) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -574,6 +635,14 @@ func (x *fastReflection_EventBuyDirect) Set(fd protoreflect.FieldDescriptor, val switch fd.FullName() { case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": x.SellOrderId = value.Uint() + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + x.Seller = value.Interface().(string) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + x.SellerFeePaid = value.Message().Interface().(*v1beta1.Coin) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + x.Buyer = value.Interface().(string) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + x.BuyerFeePaid = value.Message().Interface().(*v1beta1.Coin) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -594,8 +663,22 @@ func (x *fastReflection_EventBuyDirect) Set(fd protoreflect.FieldDescriptor, val // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_EventBuyDirect) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + if x.SellerFeePaid == nil { + x.SellerFeePaid = new(v1beta1.Coin) + } + return protoreflect.ValueOfMessage(x.SellerFeePaid.ProtoReflect()) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + if x.BuyerFeePaid == nil { + x.BuyerFeePaid = new(v1beta1.Coin) + } + return protoreflect.ValueOfMessage(x.BuyerFeePaid.ProtoReflect()) case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": panic(fmt.Errorf("field sell_order_id of message regen.ecocredit.marketplace.v1.EventBuyDirect is not mutable")) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + panic(fmt.Errorf("field seller of message regen.ecocredit.marketplace.v1.EventBuyDirect is not mutable")) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + panic(fmt.Errorf("field buyer of message regen.ecocredit.marketplace.v1.EventBuyDirect is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -611,6 +694,16 @@ func (x *fastReflection_EventBuyDirect) NewField(fd protoreflect.FieldDescriptor switch fd.FullName() { case "regen.ecocredit.marketplace.v1.EventBuyDirect.sell_order_id": return protoreflect.ValueOfUint64(uint64(0)) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller": + return protoreflect.ValueOfString("") + case "regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid": + m := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer": + return protoreflect.ValueOfString("") + case "regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid": + m := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(m.ProtoReflect()) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: regen.ecocredit.marketplace.v1.EventBuyDirect")) @@ -683,6 +776,22 @@ func (x *fastReflection_EventBuyDirect) ProtoMethods() *protoiface.Methods { if x.SellOrderId != 0 { n += 1 + runtime.Sov(uint64(x.SellOrderId)) } + l = len(x.Seller) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.SellerFeePaid != nil { + l = options.Size(x.SellerFeePaid) + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.Buyer) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.BuyerFeePaid != nil { + l = options.Size(x.BuyerFeePaid) + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -712,6 +821,48 @@ func (x *fastReflection_EventBuyDirect) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.BuyerFeePaid != nil { + encoded, err := options.Marshal(x.BuyerFeePaid) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x2a + } + if len(x.Buyer) > 0 { + i -= len(x.Buyer) + copy(dAtA[i:], x.Buyer) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Buyer))) + i-- + dAtA[i] = 0x22 + } + if x.SellerFeePaid != nil { + encoded, err := options.Marshal(x.SellerFeePaid) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1a + } + if len(x.Seller) > 0 { + i -= len(x.Seller) + copy(dAtA[i:], x.Seller) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Seller))) + i-- + dAtA[i] = 0x12 + } if x.SellOrderId != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.SellOrderId)) i-- @@ -785,6 +936,142 @@ func (x *fastReflection_EventBuyDirect) ProtoMethods() *protoiface.Methods { break } } + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Seller", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Seller = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SellerFeePaid", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.SellerFeePaid == nil { + x.SellerFeePaid = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.SellerFeePaid); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Buyer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Buyer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field BuyerFeePaid", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.BuyerFeePaid == nil { + x.BuyerFeePaid = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.BuyerFeePaid); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -2527,6 +2814,16 @@ type EventBuyDirect struct { // sell_order_id is the unique identifier of the sell order that credits were // purchased from. SellOrderId uint64 `protobuf:"varint,1,opt,name=sell_order_id,json=sellOrderId,proto3" json:"sell_order_id,omitempty"` + // seller is the address of the account that sold the credits. + Seller string `protobuf:"bytes,2,opt,name=seller,proto3" json:"seller,omitempty"` + // seller_fee_paid is the amount of coins paid by the seller + // to the marketplace as a fee for facilitating the sale. + SellerFeePaid *v1beta1.Coin `protobuf:"bytes,3,opt,name=seller_fee_paid,json=sellerFeePaid,proto3" json:"seller_fee_paid,omitempty"` + // buyer is the address of the account that purchased the credits. + Buyer string `protobuf:"bytes,4,opt,name=buyer,proto3" json:"buyer,omitempty"` + // buyer_fee_paid is the amount of coins paid by the buyer + // to the marketplace as a fee for facilitating the sale. + BuyerFeePaid *v1beta1.Coin `protobuf:"bytes,5,opt,name=buyer_fee_paid,json=buyerFeePaid,proto3" json:"buyer_fee_paid,omitempty"` } func (x *EventBuyDirect) Reset() { @@ -2556,6 +2853,34 @@ func (x *EventBuyDirect) GetSellOrderId() uint64 { return 0 } +func (x *EventBuyDirect) GetSeller() string { + if x != nil { + return x.Seller + } + return "" +} + +func (x *EventBuyDirect) GetSellerFeePaid() *v1beta1.Coin { + if x != nil { + return x.SellerFeePaid + } + return nil +} + +func (x *EventBuyDirect) GetBuyer() string { + if x != nil { + return x.Buyer + } + return "" +} + +func (x *EventBuyDirect) GetBuyerFeePaid() *v1beta1.Coin { + if x != nil { + return x.BuyerFeePaid + } + return nil +} + // EventUpdateSellOrder is an event emitted when a sell order is updated. type EventUpdateSellOrder struct { state protoimpl.MessageState @@ -2718,46 +3043,59 @@ var file_regen_ecocredit_marketplace_v1_events_proto_rawDesc = []byte{ 0x74, 0x2f, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1e, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2e, 0x65, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2e, 0x6d, - 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x22, 0x2f, 0x0a, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2f, 0x0a, 0x09, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6c, 0x6c, 0x12, 0x22, 0x0a, 0x0d, 0x73, 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x34, - 0x0a, 0x0e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x79, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, - 0x12, 0x22, 0x0a, 0x0d, 0x73, 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, - 0x65, 0x72, 0x49, 0x64, 0x22, 0x3a, 0x0a, 0x14, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x53, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0d, - 0x73, 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, - 0x22, 0x3a, 0x0a, 0x14, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, - 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0d, 0x73, 0x65, 0x6c, 0x6c, - 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x27, 0x0a, 0x0f, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x44, 0x65, 0x6e, 0x6f, 0x6d, 0x12, - 0x14, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2f, 0x0a, 0x17, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, - 0x6d, 0x6f, 0x76, 0x65, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x44, 0x65, 0x6e, 0x6f, 0x6d, - 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x42, 0xa4, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x2e, 0x72, - 0x65, 0x67, 0x65, 0x6e, 0x2e, 0x65, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2e, 0x6d, - 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x56, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2d, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2d, 0x6c, 0x65, 0x64, - 0x67, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2f, 0x65, 0x63, - 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2f, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, - 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, - 0x63, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x52, 0x45, 0x4d, 0xaa, 0x02, 0x1e, 0x52, 0x65, 0x67, - 0x65, 0x6e, 0x2e, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2e, 0x4d, 0x61, 0x72, - 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x1e, 0x52, 0x65, - 0x67, 0x65, 0x6e, 0x5c, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x5c, 0x4d, 0x61, - 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x2a, 0x52, - 0x65, 0x67, 0x65, 0x6e, 0x5c, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x5c, 0x4d, - 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, - 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x52, 0x65, 0x67, 0x65, - 0x6e, 0x3a, 0x3a, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x3a, 0x3a, 0x4d, 0x61, - 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0xe6, + 0x01, 0x0a, 0x0e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x79, 0x44, 0x69, 0x72, 0x65, 0x63, + 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x73, 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x41, 0x0a, + 0x0f, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x5f, 0x66, 0x65, 0x65, 0x5f, 0x70, 0x61, 0x69, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, + 0x6e, 0x52, 0x0d, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x46, 0x65, 0x65, 0x50, 0x61, 0x69, 0x64, + 0x12, 0x14, 0x0a, 0x05, 0x62, 0x75, 0x79, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x62, 0x75, 0x79, 0x65, 0x72, 0x12, 0x3f, 0x0a, 0x0e, 0x62, 0x75, 0x79, 0x65, 0x72, 0x5f, + 0x66, 0x65, 0x65, 0x5f, 0x70, 0x61, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x0c, 0x62, 0x75, 0x79, 0x65, 0x72, + 0x46, 0x65, 0x65, 0x50, 0x61, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x14, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x22, 0x0a, 0x0d, 0x73, 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x3a, 0x0a, 0x14, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x61, 0x6e, 0x63, + 0x65, 0x6c, 0x53, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0d, 0x73, + 0x65, 0x6c, 0x6c, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0b, 0x73, 0x65, 0x6c, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, + 0x27, 0x0a, 0x0f, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x44, 0x65, 0x6e, + 0x6f, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2f, 0x0a, 0x17, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x44, 0x65, + 0x6e, 0x6f, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x42, 0xa4, 0x02, 0x0a, 0x22, 0x63, 0x6f, + 0x6d, 0x2e, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2e, 0x65, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, + 0x74, 0x2e, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, + 0x42, 0x0b, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x56, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x67, 0x65, + 0x6e, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x72, 0x65, 0x67, 0x65, 0x6e, 0x2d, + 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x67, 0x65, 0x6e, + 0x2f, 0x65, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2f, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x52, 0x45, 0x4d, 0xaa, 0x02, 0x1e, + 0x52, 0x65, 0x67, 0x65, 0x6e, 0x2e, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x2e, + 0x4d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, + 0x1e, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x5c, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, + 0x5c, 0x4d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5c, 0x56, 0x31, 0xe2, + 0x02, 0x2a, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x5c, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, + 0x74, 0x5c, 0x4d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5c, 0x56, 0x31, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, 0x52, + 0x65, 0x67, 0x65, 0x6e, 0x3a, 0x3a, 0x45, 0x63, 0x6f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x3a, + 0x3a, 0x4d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x3a, 0x3a, 0x56, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2780,13 +3118,16 @@ var file_regen_ecocredit_marketplace_v1_events_proto_goTypes = []interface{}{ (*EventCancelSellOrder)(nil), // 3: regen.ecocredit.marketplace.v1.EventCancelSellOrder (*EventAllowDenom)(nil), // 4: regen.ecocredit.marketplace.v1.EventAllowDenom (*EventRemoveAllowedDenom)(nil), // 5: regen.ecocredit.marketplace.v1.EventRemoveAllowedDenom + (*v1beta1.Coin)(nil), // 6: cosmos.base.v1beta1.Coin } var file_regen_ecocredit_marketplace_v1_events_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 6, // 0: regen.ecocredit.marketplace.v1.EventBuyDirect.seller_fee_paid:type_name -> cosmos.base.v1beta1.Coin + 6, // 1: regen.ecocredit.marketplace.v1.EventBuyDirect.buyer_fee_paid:type_name -> cosmos.base.v1beta1.Coin + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_regen_ecocredit_marketplace_v1_events_proto_init() } diff --git a/proto/regen/ecocredit/marketplace/v1/events.proto b/proto/regen/ecocredit/marketplace/v1/events.proto index e5d6023579..a629b1a01c 100644 --- a/proto/regen/ecocredit/marketplace/v1/events.proto +++ b/proto/regen/ecocredit/marketplace/v1/events.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package regen.ecocredit.marketplace.v1; +import "cosmos/base/v1beta1/coin.proto"; + option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/marketplace/types/v1"; // EventSell is an event emitted when a sell order is created. @@ -17,6 +19,20 @@ message EventBuyDirect { // sell_order_id is the unique identifier of the sell order that credits were // purchased from. uint64 sell_order_id = 1; + + // seller is the address of the account that sold the credits. + string seller = 2; + + // seller_fee_paid is the amount of coins paid by the seller + // to the marketplace as a fee for facilitating the sale. + cosmos.base.v1beta1.Coin seller_fee_paid = 3; + + // buyer is the address of the account that purchased the credits. + string buyer = 4; + + // buyer_fee_paid is the amount of coins paid by the buyer + // to the marketplace as a fee for facilitating the sale. + cosmos.base.v1beta1.Coin buyer_fee_paid = 5; } // EventUpdateSellOrder is an event emitted when a sell order is updated. diff --git a/x/ecocredit/marketplace/keeper/features/msg_buy_direct.feature b/x/ecocredit/marketplace/keeper/features/msg_buy_direct.feature index d6b689fdb4..bacfcd50a3 100644 --- a/x/ecocredit/marketplace/keeper/features/msg_buy_direct.feature +++ b/x/ecocredit/marketplace/keeper/features/msg_buy_direct.feature @@ -384,7 +384,17 @@ Feature: Msg/BuyDirect And expect event buy direct with properties """ { - "sell_order_id": 1 + "sell_order_id": 1, + "seller": "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68", + "seller_fee_paid":{ + "amount": "0", + "denom": "regen" + }, + "buyer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "buyer_fee_paid":{ + "amount": "0", + "denom": "regen" + } } """ @@ -393,7 +403,9 @@ Feature: Msg/BuyDirect Given a credit type Scenario: fees go to fee pool - Given alice created a sell order with quantity "10" and ask price "10foo" + Given alice's address "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68" + * bob's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + * alice created a sell order with quantity "10" and ask price "10foo" * bob has bank balance "110foo" * alice has bank balance "0foo" * buyer fees are 0.1 and seller fees are 0.05 @@ -402,9 +414,27 @@ Feature: Msg/BuyDirect * expect alice bank balance "95foo" * expect bob bank balance "0foo" * expect fee pool balance "15foo" + And expect event buy direct with properties + """ + { + "sell_order_id": 1, + "seller": "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68", + "seller_fee_paid":{ + "amount": "5", + "denom": "foo" + }, + "buyer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "buyer_fee_paid":{ + "amount": "10", + "denom": "foo" + } + } + """ Scenario: fees get burned - Given alice created a sell order with quantity "10" and ask price "20uregen" + Given alice's address "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68" + * bob's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + * alice created a sell order with quantity "10" and ask price "20uregen" * bob has bank balance "240uregen" * alice has bank balance "0regen" * buyer fees are 0.2 and seller fees are 0.1 @@ -413,6 +443,22 @@ Feature: Msg/BuyDirect * expect alice bank balance "180uregen" * expect bob bank balance "0uregen" * expect fee pool balance "0uregen" + And expect event buy direct with properties + """ + { + "sell_order_id": 1, + "seller": "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68", + "seller_fee_paid":{ + "amount": "20", + "denom": "uregen" + }, + "buyer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "buyer_fee_paid":{ + "amount": "40", + "denom": "uregen" + } + } + """ Rule: max_fee_amount is enforced Scenario Outline: max_fee_amount is enforced diff --git a/x/ecocredit/marketplace/keeper/msg_buy_direct.go b/x/ecocredit/marketplace/keeper/msg_buy_direct.go index c95a56ecc0..7be39f457d 100644 --- a/x/ecocredit/marketplace/keeper/msg_buy_direct.go +++ b/x/ecocredit/marketplace/keeper/msg_buy_direct.go @@ -148,12 +148,6 @@ func (k Keeper) BuyDirect(ctx context.Context, req *types.MsgBuyDirect) (*types. }); err != nil { return nil, err } - - if err = sdkCtx.EventManager().EmitTypedEvent(&types.EventBuyDirect{ - SellOrderId: sellOrder.Id, - }); err != nil { - return nil, err - } } return &types.MsgBuyDirectResponse{}, nil diff --git a/x/ecocredit/marketplace/keeper/msg_buy_direct_test.go b/x/ecocredit/marketplace/keeper/msg_buy_direct_test.go index 0990d7fedf..01b9e81684 100644 --- a/x/ecocredit/marketplace/keeper/msg_buy_direct_test.go +++ b/x/ecocredit/marketplace/keeper/msg_buy_direct_test.go @@ -8,9 +8,15 @@ import ( "github.com/cockroachdb/apd/v3" "github.com/gogo/protobuf/jsonpb" + gogoproto "github.com/gogo/protobuf/proto" "github.com/golang/mock/gomock" + "github.com/google/go-cmp/cmp" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/testing/protocmp" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -549,14 +555,30 @@ func (s *buyDirectSuite) ExpectBatchSupply(a gocuke.DocString) { func (s *buyDirectSuite) ExpectEventBuyDirectWithProperties(a gocuke.DocString) { var event types.EventBuyDirect - err := json.Unmarshal([]byte(a.Content), &event) + err := jsonpb.UnmarshalString(a.Content, &event) require.NoError(s.t, err) - sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events()) + s.expectEvent(&event) +} + +func (s *buyDirectSuite) expectEvent(expected gogoproto.Message) { + sdkEvent, found := testutil.GetEvent(expected, s.sdkCtx.EventManager().Events()) require.True(s.t, found) - err = testutil.MatchEvent(&event, sdkEvent) + foundEvt, err := sdk.ParseTypedEvent(abci.Event(sdkEvent)) require.NoError(s.t, err) + + msgType, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(gogoproto.MessageName(expected))) + require.NoError(s.t, err) + evt := msgType.New().Interface() + evt2 := msgType.New().Interface() + + require.NoError(s.t, gogoToProtoReflect(foundEvt, evt)) + require.NoError(s.t, gogoToProtoReflect(expected, evt2)) + + if diff := cmp.Diff(evt, evt2, protocmp.Transform()); diff != "" { + s.t.Fatalf("unexpected event diff: %s", diff) + } } func (s *buyDirectSuite) ExpectEventTransferWithProperties(a gocuke.DocString) { diff --git a/x/ecocredit/marketplace/keeper/utils.go b/x/ecocredit/marketplace/keeper/utils.go index 9322e2a5fb..36cc9b345b 100644 --- a/x/ecocredit/marketplace/keeper/utils.go +++ b/x/ecocredit/marketplace/keeper/utils.go @@ -13,6 +13,7 @@ import ( api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/marketplace/v1" "github.com/regen-network/regen-ledger/types/v2/math" basetypes "github.com/regen-network/regen-ledger/x/ecocredit/v3/base/types/v1" + types "github.com/regen-network/regen-ledger/x/ecocredit/v3/marketplace/types/v1" "github.com/regen-network/regen-ledger/x/ecocredit/v3/server/utils" ) @@ -243,11 +244,24 @@ func (k Keeper) fillOrder(ctx context.Context, params fillOrderParams) error { return err } + seller := sdk.AccAddress(params.sellOrder.Seller) + // send seller payment from buyer account to seller account - return k.bankKeeper.SendCoins(sdkCtx, params.buyerAcc, params.sellOrder.Seller, sdk.NewCoins(sdk.NewCoin( + err = k.bankKeeper.SendCoins(sdkCtx, params.buyerAcc, seller, sdk.NewCoins(sdk.NewCoin( params.bankDenom, sellerPayment.SdkIntTrim(), ))) + if err != nil { + return err + } + + return sdkCtx.EventManager().EmitTypedEvent(&types.EventBuyDirect{ + SellOrderId: params.sellOrder.Id, + Buyer: params.buyerAcc.String(), + BuyerFeePaid: &sdk.Coin{Denom: params.bankDenom, Amount: params.buyerFee.SdkIntTrim()}, + Seller: seller.String(), + SellerFeePaid: &sdk.Coin{Denom: params.bankDenom, Amount: sellerFee.SdkIntTrim()}, + }) } // getSubTotalCost calculates the total cost of the buy order by multiplying the price per credit specified diff --git a/x/ecocredit/marketplace/types/v1/events.pb.go b/x/ecocredit/marketplace/types/v1/events.pb.go index 3e6068a1df..e39f658ce9 100644 --- a/x/ecocredit/marketplace/types/v1/events.pb.go +++ b/x/ecocredit/marketplace/types/v1/events.pb.go @@ -5,6 +5,7 @@ package v1 import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -73,6 +74,16 @@ type EventBuyDirect struct { // sell_order_id is the unique identifier of the sell order that credits were // purchased from. SellOrderId uint64 `protobuf:"varint,1,opt,name=sell_order_id,json=sellOrderId,proto3" json:"sell_order_id,omitempty"` + // seller is the address of the account that sold the credits. + Seller string `protobuf:"bytes,2,opt,name=seller,proto3" json:"seller,omitempty"` + // seller_fee_paid is the amount of coins paid by the seller + // to the marketplace as a fee for facilitating the sale. + SellerFeePaid *types.Coin `protobuf:"bytes,3,opt,name=seller_fee_paid,json=sellerFeePaid,proto3" json:"seller_fee_paid,omitempty"` + // buyer is the address of the account that purchased the credits. + Buyer string `protobuf:"bytes,4,opt,name=buyer,proto3" json:"buyer,omitempty"` + // buyer_fee_paid is the amount of coins paid by the buyer + // to the marketplace as a fee for facilitating the sale. + BuyerFeePaid *types.Coin `protobuf:"bytes,5,opt,name=buyer_fee_paid,json=buyerFeePaid,proto3" json:"buyer_fee_paid,omitempty"` } func (m *EventBuyDirect) Reset() { *m = EventBuyDirect{} } @@ -115,6 +126,34 @@ func (m *EventBuyDirect) GetSellOrderId() uint64 { return 0 } +func (m *EventBuyDirect) GetSeller() string { + if m != nil { + return m.Seller + } + return "" +} + +func (m *EventBuyDirect) GetSellerFeePaid() *types.Coin { + if m != nil { + return m.SellerFeePaid + } + return nil +} + +func (m *EventBuyDirect) GetBuyer() string { + if m != nil { + return m.Buyer + } + return "" +} + +func (m *EventBuyDirect) GetBuyerFeePaid() *types.Coin { + if m != nil { + return m.BuyerFeePaid + } + return nil +} + // EventUpdateSellOrder is an event emitted when a sell order is updated. type EventUpdateSellOrder struct { // sell_order_id is the unique identifier of the sell order that was updated. @@ -320,25 +359,32 @@ func init() { } var fileDescriptor_68b71b54d42cf1d9 = []byte{ - // 282 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0x3f, 0x4b, 0xc3, 0x40, - 0x1c, 0x86, 0x13, 0x50, 0xa1, 0x27, 0x2a, 0x84, 0x82, 0x4e, 0x87, 0x64, 0x51, 0x10, 0x73, 0x04, - 0x9d, 0xdc, 0xac, 0x55, 0x70, 0x12, 0x52, 0x5c, 0x5c, 0x6a, 0x7a, 0xf7, 0x12, 0x43, 0x2f, 0xb9, - 0x70, 0xb9, 0x5e, 0xed, 0xb7, 0xf0, 0x63, 0x39, 0x76, 0x74, 0x94, 0xe4, 0x8b, 0x48, 0xce, 0x3f, - 0xb8, 0x28, 0xed, 0x76, 0xef, 0x7b, 0xcf, 0xb3, 0xfc, 0x5e, 0x72, 0xa2, 0x91, 0xa1, 0x64, 0xe0, - 0x8a, 0x6b, 0x88, 0xdc, 0xb0, 0x22, 0xd5, 0x53, 0x98, 0x4a, 0xa6, 0x1c, 0xcc, 0xc6, 0x0c, 0x16, - 0xa5, 0xa9, 0xa3, 0x4a, 0x2b, 0xa3, 0x02, 0xea, 0xe0, 0xe8, 0x07, 0x8e, 0x7e, 0xc1, 0x91, 0x8d, - 0x43, 0x46, 0x7a, 0xd7, 0x1d, 0x3f, 0x82, 0x94, 0x41, 0x48, 0x76, 0x6a, 0x48, 0x39, 0x56, 0x5a, - 0x40, 0x8f, 0x73, 0x71, 0xe0, 0x1f, 0xfa, 0xc7, 0x1b, 0xc9, 0x76, 0x57, 0xde, 0x75, 0xdd, 0xad, - 0x08, 0xcf, 0xc9, 0xae, 0x13, 0x06, 0xb3, 0xc5, 0x30, 0xd7, 0xe0, 0x66, 0x25, 0xeb, 0x82, 0xf4, - 0x9d, 0x75, 0x5f, 0x89, 0xd4, 0x60, 0xf4, 0xfd, 0xb3, 0x96, 0x7b, 0x95, 0x96, 0x1c, 0x72, 0x3d, - 0xf7, 0x88, 0xec, 0x39, 0xf7, 0x52, 0x4a, 0x35, 0x1f, 0xa2, 0x54, 0x45, 0xd0, 0x27, 0x9b, 0xa2, - 0x7b, 0x38, 0xbc, 0x97, 0x7c, 0x86, 0x90, 0x91, 0x7d, 0x07, 0x26, 0x28, 0x94, 0x85, 0xc3, 0x21, - 0xfe, 0x11, 0x06, 0x8f, 0xaf, 0x0d, 0xf5, 0x97, 0x0d, 0xf5, 0xdf, 0x1b, 0xea, 0xbf, 0xb4, 0xd4, - 0x5b, 0xb6, 0xd4, 0x7b, 0x6b, 0xa9, 0xf7, 0x70, 0x93, 0xe5, 0xe6, 0x69, 0x36, 0x89, 0xb8, 0x2a, - 0x98, 0xbb, 0xfe, 0x69, 0x09, 0x33, 0x57, 0x7a, 0xfa, 0x95, 0x24, 0x44, 0x06, 0xcd, 0x9e, 0xff, - 0x58, 0xd0, 0x2c, 0x2a, 0xd4, 0xcc, 0xc6, 0x93, 0x2d, 0xb7, 0xe0, 0xd9, 0x47, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x33, 0xb9, 0xd9, 0xe6, 0xf0, 0x01, 0x00, 0x00, + // 392 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xc1, 0x8b, 0x13, 0x31, + 0x14, 0xc6, 0x1b, 0xdd, 0x5d, 0x68, 0xd6, 0xdd, 0x85, 0x61, 0xd1, 0xd1, 0x43, 0x28, 0x73, 0xb1, + 0x20, 0x26, 0x54, 0x6f, 0x5e, 0x64, 0xdb, 0x5a, 0xf0, 0xa4, 0x4c, 0xf1, 0xe2, 0x65, 0xcc, 0x24, + 0xcf, 0x1a, 0x9a, 0x99, 0x0c, 0x99, 0x74, 0x6a, 0xff, 0x0b, 0xff, 0x2c, 0x8f, 0x3d, 0x7a, 0x94, + 0x16, 0xfc, 0x3b, 0x24, 0x99, 0xa9, 0x7a, 0x51, 0xbb, 0xb7, 0xf7, 0x85, 0xef, 0xf7, 0xf1, 0x5e, + 0xf8, 0xf0, 0x13, 0x0b, 0x0b, 0x28, 0x19, 0x08, 0x23, 0x2c, 0x48, 0xe5, 0x58, 0xc1, 0xed, 0x12, + 0x5c, 0xa5, 0xb9, 0x00, 0xd6, 0x8c, 0x18, 0x34, 0x50, 0xba, 0x9a, 0x56, 0xd6, 0x38, 0x13, 0x91, + 0x60, 0xa6, 0xbf, 0xcc, 0xf4, 0x0f, 0x33, 0x6d, 0x46, 0x8f, 0x88, 0x30, 0x75, 0x61, 0x6a, 0x96, + 0xf3, 0xda, 0xc3, 0x39, 0x38, 0x3e, 0x62, 0xc2, 0xa8, 0xb2, 0xe5, 0x13, 0x86, 0xfb, 0xaf, 0x7c, + 0xde, 0x1c, 0xb4, 0x8e, 0x12, 0x7c, 0x51, 0x83, 0xd6, 0x99, 0xb1, 0x12, 0x6c, 0xa6, 0x64, 0x8c, + 0x06, 0x68, 0x78, 0x92, 0x9e, 0xfb, 0xc7, 0x37, 0xfe, 0xed, 0xb5, 0x4c, 0x7e, 0x20, 0x7c, 0x19, + 0x88, 0xf1, 0x6a, 0x33, 0x55, 0x16, 0x84, 0x3b, 0x06, 0x8b, 0xee, 0xe3, 0x33, 0x2f, 0xc1, 0xc6, + 0x77, 0x06, 0x68, 0xd8, 0x4f, 0x3b, 0x15, 0xdd, 0xe0, 0xab, 0x76, 0xca, 0x3e, 0x02, 0x64, 0x15, + 0x57, 0x32, 0xbe, 0x3b, 0x40, 0xc3, 0xf3, 0x67, 0x0f, 0x69, 0xbb, 0x39, 0xf5, 0x9b, 0xd3, 0x6e, + 0x73, 0x3a, 0x31, 0xaa, 0x4c, 0x2f, 0x5a, 0x62, 0x06, 0xf0, 0x96, 0x2b, 0x19, 0x5d, 0xe3, 0xd3, + 0x7c, 0xb5, 0x01, 0x1b, 0x9f, 0x84, 0xe4, 0x56, 0x44, 0x2f, 0xf1, 0x65, 0x18, 0x7e, 0xe7, 0x9e, + 0xfe, 0x2f, 0xf7, 0x5e, 0x00, 0xba, 0xd8, 0xe4, 0x05, 0xbe, 0x0e, 0x77, 0xbe, 0xab, 0x24, 0x77, + 0x30, 0x3f, 0xdc, 0x72, 0xd4, 0x27, 0x1d, 0xd8, 0x09, 0x2f, 0x05, 0xe8, 0xdb, 0xb1, 0x8f, 0xf1, + 0x55, 0x60, 0x6f, 0xb4, 0x36, 0xeb, 0x29, 0x94, 0xa6, 0xf0, 0x17, 0x4a, 0x3f, 0x04, 0x7b, 0x3f, + 0x6d, 0x45, 0xc2, 0xf0, 0x83, 0x60, 0x4c, 0xa1, 0x30, 0x0d, 0x04, 0x3b, 0xc8, 0x7f, 0x00, 0xe3, + 0x0f, 0x5f, 0x77, 0x04, 0x6d, 0x77, 0x04, 0x7d, 0xdf, 0x11, 0xf4, 0x65, 0x4f, 0x7a, 0xdb, 0x3d, + 0xe9, 0x7d, 0xdb, 0x93, 0xde, 0xfb, 0xd9, 0x42, 0xb9, 0x4f, 0xab, 0x9c, 0x0a, 0x53, 0xb0, 0x50, + 0xa8, 0xa7, 0x25, 0xb8, 0xb5, 0xb1, 0xcb, 0x4e, 0x69, 0x90, 0x0b, 0xb0, 0xec, 0xf3, 0x5f, 0x4a, + 0xe9, 0x36, 0x15, 0xd4, 0xbe, 0x5d, 0x67, 0xa1, 0x54, 0xcf, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, + 0x17, 0x0b, 0xc9, 0xdb, 0xc3, 0x02, 0x00, 0x00, } func (m *EventSell) Marshal() (dAtA []byte, err error) { @@ -389,6 +435,44 @@ func (m *EventBuyDirect) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.BuyerFeePaid != nil { + { + size, err := m.BuyerFeePaid.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + if len(m.Buyer) > 0 { + i -= len(m.Buyer) + copy(dAtA[i:], m.Buyer) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Buyer))) + i-- + dAtA[i] = 0x22 + } + if m.SellerFeePaid != nil { + { + size, err := m.SellerFeePaid.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Seller) > 0 { + i -= len(m.Seller) + copy(dAtA[i:], m.Seller) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Seller))) + i-- + dAtA[i] = 0x12 + } if m.SellOrderId != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.SellOrderId)) i-- @@ -545,6 +629,22 @@ func (m *EventBuyDirect) Size() (n int) { if m.SellOrderId != 0 { n += 1 + sovEvents(uint64(m.SellOrderId)) } + l = len(m.Seller) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + if m.SellerFeePaid != nil { + l = m.SellerFeePaid.Size() + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.Buyer) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + if m.BuyerFeePaid != nil { + l = m.BuyerFeePaid.Size() + n += 1 + l + sovEvents(uint64(l)) + } return n } @@ -721,6 +821,142 @@ func (m *EventBuyDirect) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Seller", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Seller = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SellerFeePaid", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SellerFeePaid == nil { + m.SellerFeePaid = &types.Coin{} + } + if err := m.SellerFeePaid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Buyer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Buyer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BuyerFeePaid", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BuyerFeePaid == nil { + m.BuyerFeePaid = &types.Coin{} + } + if err := m.BuyerFeePaid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvents(dAtA[iNdEx:])