Skip to content

Commit

Permalink
add events
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Aug 22, 2024
1 parent d6359d4 commit 65a91b3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/static/openapi.yml

Large diffs are not rendered by default.

53 changes: 51 additions & 2 deletions x/fundraising/keeper/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sort"
"strconv"
"time"

"cosmossdk.io/collections"
Expand Down Expand Up @@ -393,7 +394,8 @@ func (k Keeper) CloseBatchAuction(ctx context.Context, auction types.AuctionI) e
// CreateFixedPriceAuction handles types.MsgCreateFixedPriceAuction and create a fixed price auction.
// Note that the module is designed to delegate authorization to an external module to add allowed bidders for the auction.
func (k Keeper) CreateFixedPriceAuction(ctx context.Context, msg *types.MsgCreateFixedPriceAuction) (types.AuctionI, error) {
blockTime := sdk.UnwrapSDKContext(ctx).BlockTime()
sdkCtx := sdk.UnwrapSDKContext(ctx)
blockTime := sdkCtx.BlockTime()
if blockTime.After(msg.EndTime) { // EndTime < CurrentTime
return nil, sdkerrors.Wrap(errors.ErrInvalidRequest, "end time must be set after the current time")
}
Expand Down Expand Up @@ -476,13 +478,32 @@ func (k Keeper) CreateFixedPriceAuction(ctx context.Context, msg *types.MsgCreat
return nil, err
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeCreateFixedPriceAuction,
sdk.NewAttribute(types.AttributeKeyAuctionId, strconv.FormatUint(nextId, 10)),
sdk.NewAttribute(types.AttributeKeyAuctioneerAddress, auction.GetAuctioneer().String()),
sdk.NewAttribute(types.AttributeKeySellingReserveAddress, auction.GetSellingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyPayingReserveAddress, auction.GetPayingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyStartPrice, auction.GetStartPrice().String()),
sdk.NewAttribute(types.AttributeKeySellingCoin, auction.GetSellingCoin().String()),
sdk.NewAttribute(types.AttributeKeyPayingCoinDenom, auction.GetPayingCoinDenom()),
sdk.NewAttribute(types.AttributeKeyVestingReserveAddress, auction.GetVestingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyRemainingSellingCoin, auction.RemainingSellingCoin.String()),
sdk.NewAttribute(types.AttributeKeyStartTime, auction.GetStartTime().String()),
sdk.NewAttribute(types.AttributeKeyEndTime, msg.EndTime.String()),
sdk.NewAttribute(types.AttributeKeyAuctionStatus, auction.GetStatus().String()),
),
})

return auction, nil
}

// CreateBatchAuction handles types.MsgCreateBatchAuction and create a batch auction.
// Note that the module is designed to delegate authorization to an external module to add allowed bidders for the auction.
func (k Keeper) CreateBatchAuction(ctx context.Context, msg *types.MsgCreateBatchAuction) (types.AuctionI, error) {
blockTime := sdk.UnwrapSDKContext(ctx).BlockTime()
sdkCtx := sdk.UnwrapSDKContext(ctx)
blockTime := sdkCtx.BlockTime()
if blockTime.After(msg.EndTime) { // EndTime < CurrentTime
return nil, sdkerrors.Wrap(errors.ErrInvalidRequest, "end time must be set after the current time")
}
Expand Down Expand Up @@ -583,6 +604,26 @@ func (k Keeper) CreateBatchAuction(ctx context.Context, msg *types.MsgCreateBatc
return nil, err
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeCreateBatchAuction,
sdk.NewAttribute(types.AttributeKeyAuctionId, strconv.FormatUint(nextId, 10)),
sdk.NewAttribute(types.AttributeKeyAuctioneerAddress, auction.GetAuctioneer().String()),
sdk.NewAttribute(types.AttributeKeySellingReserveAddress, auction.GetSellingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyPayingReserveAddress, auction.GetPayingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyStartPrice, auction.GetStartPrice().String()),
sdk.NewAttribute(types.AttributeKeySellingCoin, auction.GetSellingCoin().String()),
sdk.NewAttribute(types.AttributeKeyPayingCoinDenom, auction.GetPayingCoinDenom()),
sdk.NewAttribute(types.AttributeKeyVestingReserveAddress, auction.GetVestingReserveAddress().String()),
sdk.NewAttribute(types.AttributeKeyStartTime, auction.GetStartTime().String()),
sdk.NewAttribute(types.AttributeKeyEndTime, msg.EndTime.String()),
sdk.NewAttribute(types.AttributeKeyAuctionStatus, auction.GetStatus().String()),
sdk.NewAttribute(types.AttributeKeyMinBidPrice, auction.MinBidPrice.String()),
sdk.NewAttribute(types.AttributeKeyMaxExtendedRound, fmt.Sprint(auction.MaxExtendedRound)),
sdk.NewAttribute(types.AttributeKeyExtendedRoundRate, auction.ExtendedRoundRate.String()),
),
})

return auction, nil
}

Expand Down Expand Up @@ -628,5 +669,13 @@ func (k Keeper) CancelAuction(ctx context.Context, msg *types.MsgCancelAuction)
return err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeCancelAuction,
sdk.NewAttribute(types.AttributeKeyAuctionId, strconv.FormatUint(auction.GetId(), 10)),
),
})

return nil
}
12 changes: 12 additions & 0 deletions x/fundraising/keeper/bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"strconv"

"cosmossdk.io/collections"
sdkerrors "cosmossdk.io/errors"
Expand Down Expand Up @@ -174,6 +175,17 @@ func (k Keeper) PlaceBid(ctx context.Context, msg *types.MsgPlaceBid) (types.Bid
return types.Bid{}, err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypePlaceBid,
sdk.NewAttribute(types.AttributeKeyAuctionId, strconv.FormatUint(auction.GetId(), 10)),
sdk.NewAttribute(types.AttributeKeyBidderAddress, msg.GetBidder()),
sdk.NewAttribute(types.AttributeKeyBidPrice, msg.Price.String()),
sdk.NewAttribute(types.AttributeKeyBidCoin, msg.Coin.String()),
),
})

return bid, nil
}

Expand Down
30 changes: 30 additions & 0 deletions x/fundraising/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package types

// Event types for the farming module.
const (
EventTypeCreateFixedPriceAuction = "create_fixed_price_auction"
EventTypeCreateBatchAuction = "create_batch_auction"
EventTypeCancelAuction = "cancel_auction"
EventTypePlaceBid = "place_bid"

AttributeKeyAuctionId = "auction_id" //nolint:golint
AttributeKeyAuctioneerAddress = "auctioneer_address"
AttributeKeySellingReserveAddress = "selling_pool_address"
AttributeKeyPayingReserveAddress = "paying_pool_address"
AttributeKeyVestingReserveAddress = "vesting_pool_address"
AttributeKeyStartPrice = "start_price"
AttributeKeySellingCoin = "selling_coin"
AttributeKeyRemainingSellingCoin = "remaining_selling_coin"
AttributeKeyVestingSchedules = "vesting_schedules"
AttributeKeyPayingCoinDenom = "paying_coin_denom"
AttributeKeyAuctionStatus = "auction_status"
AttributeKeyStartTime = "start_time"
AttributeKeyEndTime = "end_time"
AttributeKeyBidderAddress = "bidder_address"
AttributeKeyBidPrice = "bid_price"
AttributeKeyBidCoin = "bid_coin"
AttributeKeyBidAmount = "bid_amount"
AttributeKeyMinBidPrice = "min_bid_price"
AttributeKeyMaxExtendedRound = "maximum_extended_round"
AttributeKeyExtendedRoundRate = "extended_round_rate"
)

0 comments on commit 65a91b3

Please sign in to comment.