diff --git a/proto/regen/ecocredit/v1alpha1/events.proto b/proto/regen/ecocredit/v1alpha1/events.proto index 5b91581dcc..a680090b7d 100644 --- a/proto/regen/ecocredit/v1alpha1/events.proto +++ b/proto/regen/ecocredit/v1alpha1/events.proto @@ -42,16 +42,18 @@ message EventCreateBatch { string project_location = 7; } -// EventReceive is an event emitted when credits are received either upon -// creation of a new batch or upon transfer. Each batch_denom created or -// transferred will result in a separate EventReceive for easy indexing. +// EventReceive is an event emitted when credits are received either via +// creation of a new batch, transfer of credits, or taking credits from a +// basket. Each batch_denom created, transferred or taken from a basket will +// result in a separate EventReceive for easy indexing. message EventReceive { + // sender is the sender of the credits in the case that this event is the // result of a transfer. It will not be set when credits are received at - // initial issuance. + // initial issuance or taken from a basket. string sender = 1; - // recipient is the recipient of the credits + // recipient is the recipient of the credits. string recipient = 2; // batch_denom is the unique ID of credit batch. @@ -62,6 +64,12 @@ message EventReceive { // retired_amount is the decimal number of retired credits received. string retired_amount = 5; + + // basket_denom is the denom of the basket. when the basket_denom field is + // set, it indicates that this event was triggered by the transfer of credits + // from a basket. It will not be set if the credits were sent by a user, or by + // initial issuance. + string basket_denom = 6; } // EventRetire is an event emitted when credits are retired. When credits are diff --git a/x/ecocredit/events.pb.go b/x/ecocredit/events.pb.go index 5904872583..241b69448c 100644 --- a/x/ecocredit/events.pb.go +++ b/x/ecocredit/events.pb.go @@ -180,15 +180,16 @@ func (m *EventCreateBatch) GetProjectLocation() string { return "" } -// EventReceive is an event emitted when credits are received either upon -// creation of a new batch or upon transfer. Each batch_denom created or -// transferred will result in a separate EventReceive for easy indexing. +// EventReceive is an event emitted when credits are received either via +// creation of a new batch, transfer of credits, or taking credits from a +// basket. Each batch_denom created, transferred or taken from a baset will +// result in a separate EventReceive for easy indexing. type EventReceive struct { // sender is the sender of the credits in the case that this event is the // result of a transfer. It will not be set when credits are received at - // initial issuance. + // initial issuance or taken from a basket. Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - // recipient is the recipient of the credits + // recipient is the recipient of the credits. Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` // batch_denom is the unique ID of credit batch. BatchDenom string `protobuf:"bytes,3,opt,name=batch_denom,json=batchDenom,proto3" json:"batch_denom,omitempty"` @@ -196,6 +197,10 @@ type EventReceive struct { TradableAmount string `protobuf:"bytes,4,opt,name=tradable_amount,json=tradableAmount,proto3" json:"tradable_amount,omitempty"` // retired_amount is the decimal number of retired credits received. RetiredAmount string `protobuf:"bytes,5,opt,name=retired_amount,json=retiredAmount,proto3" json:"retired_amount,omitempty"` + // basket_denom is the denom of the basket. when the basket_denom field is set, it indicates that this event was + // triggered by the transfer of credits from a basket. It will not be set if the credits were sent by a user, or + // by initial issuance. + BasketDenom string `protobuf:"bytes,6,opt,name=basket_denom,json=basketDenom,proto3" json:"basket_denom,omitempty"` } func (m *EventReceive) Reset() { *m = EventReceive{} } @@ -266,6 +271,13 @@ func (m *EventReceive) GetRetiredAmount() string { return "" } +func (m *EventReceive) GetBasketDenom() string { + if m != nil { + return m.BasketDenom + } + return "" +} + // EventRetire is an event emitted when credits are retired. When credits are // retired from multiple batches in the same transaction, a separate event is // emitted for each batch_denom. This allows for easier indexing. @@ -427,35 +439,36 @@ func init() { } var fileDescriptor_5b6a013b00aef3af = []byte{ - // 448 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0x13, 0x31, - 0x10, 0x86, 0xb3, 0x94, 0x26, 0xcd, 0xa4, 0xb4, 0x95, 0x85, 0xd0, 0x82, 0x60, 0x81, 0x95, 0x2a, - 0xe0, 0x40, 0x56, 0x11, 0x4f, 0x40, 0x53, 0x0e, 0x08, 0x4e, 0x3d, 0x72, 0x59, 0x39, 0xf6, 0x28, - 0x31, 0x6c, 0xec, 0xc8, 0x3b, 0x09, 0x1c, 0x78, 0x08, 0x5e, 0x86,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3f, 0x44, 0x55, 0xa1, 0x9e, 0xa2, 0x2f, 0x3e, 0xed, 0xd6, 0x69, 0xd2, 0xe5, - 0xfd, 0x79, 0xf1, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x49, 0x35, 0x1f, 0x8e, 0x68, 0x03, 0x00, 0x00, + // 462 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0x63, 0x4a, 0x93, 0x66, 0x12, 0xda, 0xca, 0x42, 0xc8, 0x20, 0x30, 0xd4, 0x52, 0x05, + 0x1c, 0x88, 0x15, 0xf1, 0x04, 0x34, 0xe5, 0x80, 0xe0, 0xd4, 0x23, 0x17, 0x6b, 0xbd, 0x3b, 0x4a, + 0x96, 0x3a, 0xbb, 0xd1, 0x7a, 0x12, 0x38, 0xf0, 0x10, 0x3c, 0x16, 0xc7, 0x1e, 0x7b, 0x44, 0xc9, + 0x9d, 0x67, 0x40, 0x9e, 0x5d, 0x27, 0x0a, 0x48, 0x08, 0x71, 0xf3, 0xff, 0xed, 0xef, 0x99, 0xf9, + 0x67, 0xb5, 0x70, 0xee, 0x70, 0x8a, 0x26, 0x47, 0x69, 0xa5, 0x43, 0xa5, 0x29, 0x5f, 0x8d, 0x45, + 0xb5, 0x98, 0x89, 0x71, 0x8e, 0x2b, 0x34, 0x54, 0x8f, 0x16, 0xce, 0x92, 0x8d, 0x13, 0xb6, 0x8d, + 0xb6, 0xb6, 0x51, 0x6b, 0xcb, 0x26, 0x70, 0xfa, 0xb6, 0x71, 0x4e, 0x1c, 0x0a, 0xc2, 0x49, 0x25, + 0xea, 0x3a, 0x7e, 0x08, 0x47, 0xb2, 0xf9, 0x28, 0xb4, 0x4a, 0xa2, 0x67, 0xd1, 0x8b, 0xfe, 0x55, + 0x8f, 0xf5, 0x3b, 0x15, 0xdf, 0x87, 0x43, 0xa1, 0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 0x14, 0x3a, + 0xfa, 0x0d, 0x0c, 0x3c, 0xe3, 0x96, 0xd9, 0x57, 0x18, 0x84, 0x64, 0xcd, 0x8f, 0x71, 0x02, 0x3d, + 0x5f, 0xa2, 0x4d, 0xd6, 0xca, 0x7f, 0xba, 0xc4, 0x30, 0x4b, 0xb8, 0x44, 0xaf, 0xe2, 0x47, 0x70, + 0xb4, 0xdd, 0xaf, 0x4f, 0xb3, 0xd5, 0x99, 0x0a, 0xdd, 0x27, 0xc2, 0x48, 0xac, 0x9a, 0xf5, 0x49, + 0xfe, 0xaa, 0xb6, 0xfd, 0x77, 0xe0, 0xbf, 0x27, 0xb8, 0x78, 0xff, 0x7d, 0x9d, 0x46, 0x37, 0xeb, + 0x34, 0xfa, 0xb1, 0x4e, 0xa3, 0x6f, 0x9b, 0xb4, 0x73, 0xb3, 0x49, 0x3b, 0xb7, 0x9b, 0xb4, 0xf3, + 0x71, 0x3c, 0xd5, 0x34, 0x5b, 0x96, 0x23, 0x69, 0xe7, 0x39, 0xbf, 0x99, 0x57, 0x06, 0xe9, 0xb3, + 0x75, 0xd7, 0x41, 0x55, 0xa8, 0xa6, 0xe8, 0xf2, 0x2f, 0xbb, 0x17, 0x57, 0x76, 0xf9, 0x89, 0xbd, + 0xfe, 0x15, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x69, 0xfc, 0x3b, 0x8b, 0x03, 0x00, 0x00, } func (m *EventCreateClass) Marshal() (dAtA []byte, err error) { @@ -587,6 +600,13 @@ func (m *EventReceive) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.BasketDenom) > 0 { + i -= len(m.BasketDenom) + copy(dAtA[i:], m.BasketDenom) + i = encodeVarintEvents(dAtA, i, uint64(len(m.BasketDenom))) + i-- + dAtA[i] = 0x32 + } if len(m.RetiredAmount) > 0 { i -= len(m.RetiredAmount) copy(dAtA[i:], m.RetiredAmount) @@ -811,6 +831,10 @@ func (m *EventReceive) Size() (n int) { if l > 0 { n += 1 + l + sovEvents(uint64(l)) } + l = len(m.BasketDenom) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } return n } @@ -965,10 +989,7 @@ func (m *EventCreateClass) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEvents - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEvents } if (iNdEx + skippy) > l { @@ -1242,10 +1263,7 @@ func (m *EventCreateBatch) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEvents - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEvents } if (iNdEx + skippy) > l { @@ -1449,16 +1467,45 @@ func (m *EventReceive) Unmarshal(dAtA []byte) error { } m.RetiredAmount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BasketDenom", 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.BasketDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvents(dAtA[iNdEx:]) if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEvents - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEvents } if (iNdEx + skippy) > l { @@ -1636,10 +1683,7 @@ func (m *EventRetire) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEvents - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEvents } if (iNdEx + skippy) > l { @@ -1785,10 +1829,7 @@ func (m *EventCancel) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEvents - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEvents } if (iNdEx + skippy) > l { diff --git a/x/ecocredit/server/basket/take.go b/x/ecocredit/server/basket/take.go index 68cfb8131e..53573ab106 100644 --- a/x/ecocredit/server/basket/take.go +++ b/x/ecocredit/server/basket/take.go @@ -95,6 +95,7 @@ func (k Keeper) Take(ctx context.Context, msg *baskettypes.MsgTake) (*baskettype acct, basketBalance.BatchDenom, amountCreditsNeeded, + basket.BasketDenom, retire, msg.RetirementLocation, ) @@ -125,6 +126,7 @@ func (k Keeper) Take(ctx context.Context, msg *baskettypes.MsgTake) (*baskettype acct, basketBalance.BatchDenom, balance, + basket.BasketDenom, retire, msg.RetirementLocation, ) @@ -160,7 +162,7 @@ func (k Keeper) Take(ctx context.Context, msg *baskettypes.MsgTake) (*baskettype }, err } -func (k Keeper) addCreditBalance(ctx context.Context, owner sdk.AccAddress, batchDenom string, amount math.Dec, retire bool, retirementLocation string) error { +func (k Keeper) addCreditBalance(ctx context.Context, owner sdk.AccAddress, batchDenom string, amount math.Dec, basketDenom string, retire bool, retirementLocation string) error { sdkCtx := types.UnwrapSDKContext(ctx) store := sdkCtx.KVStore(k.storeKey) if !retire { @@ -173,6 +175,7 @@ func (k Keeper) addCreditBalance(ctx context.Context, owner sdk.AccAddress, batc Recipient: owner.String(), BatchDenom: batchDenom, TradableAmount: amount.String(), + BasketDenom: basketDenom, }) } else { err := ecocredit.AddAndSetDecimal(store, ecocredit.RetiredBalanceKey(owner, ecocredit.BatchDenomT(batchDenom)), amount) @@ -194,6 +197,7 @@ func (k Keeper) addCreditBalance(ctx context.Context, owner sdk.AccAddress, batc Recipient: owner.String(), BatchDenom: batchDenom, RetiredAmount: amount.String(), + BasketDenom: basketDenom, }) if err != nil { return err