Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: basket events update #794

Merged
merged 6 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions proto/regen/ecocredit/v1alpha1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
string basket_denom = 6;
}

// EventRetire is an event emitted when credits are retired. When credits are
Expand Down
149 changes: 95 additions & 54 deletions x/ecocredit/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion x/ecocredit/server/basket/take.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (k Keeper) Take(ctx context.Context, msg *baskettypes.MsgTake) (*baskettype
acct,
basketBalance.BatchDenom,
amountCreditsNeeded,
basket.BasketDenom,
retire,
msg.RetirementLocation,
)
Expand Down Expand Up @@ -125,6 +126,7 @@ func (k Keeper) Take(ctx context.Context, msg *baskettypes.MsgTake) (*baskettype
acct,
basketBalance.BatchDenom,
balance,
basket.BasketDenom,
retire,
msg.RetirementLocation,
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down