tidy up events

This commit is contained in:
rhuairahrighairigh 2020-05-08 16:07:11 +01:00
parent f86d0f3c3b
commit 4039086e8d
4 changed files with 27 additions and 29 deletions

View File

@ -36,7 +36,7 @@ func (k Keeper) StartSurplusAuction(ctx sdk.Context, seller string, lot sdk.Coin
types.EventTypeAuctionStart,
sdk.NewAttribute(types.AttributeKeyAuctionID, fmt.Sprintf("%d", auction.GetID())),
sdk.NewAttribute(types.AttributeKeyAuctionType, auction.GetType()),
sdk.NewAttribute(types.AttributeKeyBidDenom, auction.Bid.Denom),
sdk.NewAttribute(types.AttributeKeyBid, auction.Bid.String()),
sdk.NewAttribute(types.AttributeKeyLot, auction.Lot.String()),
),
)
@ -77,7 +77,7 @@ func (k Keeper) StartDebtAuction(ctx sdk.Context, buyer string, bid sdk.Coin, in
types.EventTypeAuctionStart,
sdk.NewAttribute(types.AttributeKeyAuctionID, fmt.Sprintf("%d", auction.GetID())),
sdk.NewAttribute(types.AttributeKeyAuctionType, auction.GetType()),
sdk.NewAttribute(types.AttributeKeyBidDenom, auction.Bid.Denom),
sdk.NewAttribute(types.AttributeKeyBid, auction.Bid.String()),
sdk.NewAttribute(types.AttributeKeyLot, auction.Lot.String()),
),
)
@ -122,9 +122,9 @@ func (k Keeper) StartCollateralAuction(
types.EventTypeAuctionStart,
sdk.NewAttribute(types.AttributeKeyAuctionID, fmt.Sprintf("%d", auction.GetID())),
sdk.NewAttribute(types.AttributeKeyAuctionType, auction.GetType()),
sdk.NewAttribute(types.AttributeKeyBidDenom, auction.Bid.Denom),
sdk.NewAttribute(types.AttributeKeyBid, auction.Bid.String()),
sdk.NewAttribute(types.AttributeKeyLot, auction.Lot.String()),
sdk.NewAttribute(types.AttributeKeyMaxBidAmount, auction.MaxBid.String()),
sdk.NewAttribute(types.AttributeKeyMaxBid, auction.MaxBid.String()),
),
)
return auctionID, nil
@ -352,7 +352,7 @@ func (k Keeper) PlaceReverseBidCollateral(ctx sdk.Context, a types.CollateralAuc
return a, err
}
for i, payout := range lotPayouts {
// if due to rounding, for whatever reason, the lot amount is 0, don't execute the following code
// if the payout amount is 0, don't send 0 coins
if payout.IsPositive() {
err = k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.LotReturns.Addresses[i], sdk.NewCoins(payout))
if err != nil {
@ -488,7 +488,7 @@ func (k Keeper) CloseAuction(ctx sdk.Context, auctionID uint64) error {
sdk.NewEvent(
types.EventTypeAuctionClose,
sdk.NewAttribute(types.AttributeKeyAuctionID, fmt.Sprintf("%d", auction.GetID())),
// TODO: add closed height here to facilitate the query of the auction after it closes
sdk.NewAttribute(types.AttributeKeyCloseBlock, fmt.Sprintf("%d", ctx.BlockHeight()))
),
)
return nil

View File

@ -11,8 +11,7 @@ import (
// https://en.wikipedia.org/wiki/Largest_remainder_method
// see also: https://stackoverflow.com/questions/13483430/how-to-make-rounded-percentages-add-up-to-100
func splitIntIntoWeightedBuckets(amount sdk.Int, buckets []sdk.Int) []sdk.Int {
// TODO: ideally change algorithm to work with -ve numbers. Limiting to +ve numbers until them
// TODO: negative buckets don't make sense in this context
// Limit input to +ve numbers as algorithm hasn't been designed to work with -ve numbers.
if amount.IsNegative() {
panic("negative amount")
}

View File

@ -5,11 +5,12 @@ The `x/auction` module emits the following events:
## Triggered By Other Modules
| Type | Attribute Key | Attribute Value |
|---------------|---------------|---------------------|
|---------------|---------------|-----------------|
| auction_start | auction_id | {auction ID} |
| auction_start | auction_type | {auction type} |
| auction_start | lot_denom | {auction lot denom} |
| auction_start | bid_denom | {auction bid denom} |
| auction_start | lot | {coin amount} |
| auction_start | bid | {coin amount} |
| auction_start | max_bid | {coin amount} |
## Handlers
@ -19,8 +20,8 @@ The `x/auction` module emits the following events:
|-------------|---------------|--------------------|
| auction_bid | auction_id | {auction ID} |
| auction_bid | bidder | {latest bidder} |
| auction_bid | bid_amount | {coin amount} |
| auction_bid | lot_amount | {coin amount} |
| auction_bid | bid | {coin amount} |
| auction_bid | lot | {coin amount} |
| auction_bid | end_time | {auction end time} |
| message | module | auction |
| message | sender | {sender address} |
@ -30,3 +31,4 @@ The `x/auction` module emits the following events:
| Type | Attribute Key | Attribute Value |
|---------------|---------------|-----------------|
| auction_close | auction_id | {auction ID} |
| auction_close | close_block | {block height} |

View File

@ -1,6 +1,6 @@
package types
// Events for auction module
// Events for the module
const (
EventTypeAuctionStart = "auction_start"
EventTypeAuctionBid = "auction_bid"
@ -10,12 +10,9 @@ const (
AttributeKeyAuctionID = "auction_id"
AttributeKeyAuctionType = "auction_type"
AttributeKeyBidder = "bidder"
AttributeKeyBidDenom = "bid_denom"
AttributeKeyLotDenom = "lot_denom"
AttributeKeyLot = "lot"
AttributeKeyMaxBidAmount = "max_bid"
AttributeKeyBidAmount = "bid_amount"
AttributeKeyMaxBid = "max_bid"
AttributeKeyBid = "bid"
AttributeKeyLotAmount = "lot_amount"
AttributeKeyEndTime = "end_time"
AttributeKeyCloseBlock = "close_block"
)