From 4039086e8d2354600576599ef2b936d19f211baa Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Fri, 8 May 2020 16:07:11 +0100 Subject: [PATCH] tidy up events --- x/auction/keeper/auctions.go | 12 ++++++------ x/auction/keeper/math.go | 3 +-- x/auction/spec/04_events.md | 18 ++++++++++-------- x/auction/types/events.go | 23 ++++++++++------------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/x/auction/keeper/auctions.go b/x/auction/keeper/auctions.go index bfa06006..9b7ac4ba 100644 --- a/x/auction/keeper/auctions.go +++ b/x/auction/keeper/auctions.go @@ -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 diff --git a/x/auction/keeper/math.go b/x/auction/keeper/math.go index 7b7d8468..5759471d 100644 --- a/x/auction/keeper/math.go +++ b/x/auction/keeper/math.go @@ -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") } diff --git a/x/auction/spec/04_events.md b/x/auction/spec/04_events.md index 36232b2f..4da22b31 100644 --- a/x/auction/spec/04_events.md +++ b/x/auction/spec/04_events.md @@ -4,12 +4,13 @@ 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} | +| Type | Attribute Key | Attribute Value | +|---------------|---------------|-----------------| +| auction_start | auction_id | {auction ID} | +| auction_start | auction_type | {auction type} | +| 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} | diff --git a/x/auction/types/events.go b/x/auction/types/events.go index 366ed5e1..b9389945 100644 --- a/x/auction/types/events.go +++ b/x/auction/types/events.go @@ -1,21 +1,18 @@ package types -// Events for auction module +// Events for the module const ( EventTypeAuctionStart = "auction_start" EventTypeAuctionBid = "auction_bid" EventTypeAuctionClose = "auction_close" - AttributeValueCategory = ModuleName - AttributeKeyAuctionID = "auction_id" - AttributeKeyAuctionType = "auction_type" - AttributeKeyBidder = "bidder" - AttributeKeyBidDenom = "bid_denom" - AttributeKeyLotDenom = "lot_denom" - AttributeKeyLot = "lot" - AttributeKeyMaxBidAmount = "max_bid" - AttributeKeyBidAmount = "bid_amount" - AttributeKeyBid = "bid" - AttributeKeyLotAmount = "lot_amount" - AttributeKeyEndTime = "end_time" + AttributeValueCategory = ModuleName + AttributeKeyAuctionID = "auction_id" + AttributeKeyAuctionType = "auction_type" + AttributeKeyBidder = "bidder" + AttributeKeyLot = "lot" + AttributeKeyMaxBid = "max_bid" + AttributeKeyBid = "bid" + AttributeKeyEndTime = "end_time" + AttributeKeyCloseBlock = "close_block" )