mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
remove uncessary Auction interface methods
This commit is contained in:
parent
48a2d5b6dc
commit
08689305cc
@ -83,23 +83,21 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auctionID uint64, bidder sdk.AccAddres
|
||||
|
||||
// place bid
|
||||
var err sdk.Error
|
||||
var a types.Auction
|
||||
switch auc := auction.(type) {
|
||||
var updatedAuction types.Auction
|
||||
switch a := auction.(type) {
|
||||
case types.ForwardAuction:
|
||||
a, err = k.PlaceBidForward(ctx, auc, bidder, newAmount)
|
||||
if err != nil {
|
||||
if updatedAuction, err = k.PlaceBidForward(ctx, a, bidder, newAmount); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ReverseAuction:
|
||||
a, err = k.PlaceBidReverse(ctx, auc, bidder, newAmount)
|
||||
if err != nil {
|
||||
if updatedAuction, err = k.PlaceBidReverse(ctx, a, bidder, newAmount); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ForwardReverseAuction:
|
||||
if !auc.IsReversePhase() {
|
||||
a, err = k.PlaceBidForwardReverseForward(ctx, auc, bidder, newAmount)
|
||||
if !a.IsReversePhase() {
|
||||
updatedAuction, err = k.PlaceBidForwardReverseForward(ctx, a, bidder, newAmount)
|
||||
} else {
|
||||
a, err = k.PlaceBidForwardReverseReverse(ctx, auc, bidder, newAmount)
|
||||
updatedAuction, err = k.PlaceBidForwardReverseReverse(ctx, a, bidder, newAmount)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@ -109,12 +107,12 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auctionID uint64, bidder sdk.AccAddres
|
||||
}
|
||||
|
||||
// store updated auction
|
||||
k.SetAuction(ctx, a)
|
||||
k.SetAuction(ctx, updatedAuction)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PlaceBidForward(ctx sdk.Context, a types.ForwardAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardAuction, sdk.Error) {
|
||||
// Valid New Bid
|
||||
// Validate New Bid
|
||||
if bid.Denom != a.Bid.Denom {
|
||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
||||
}
|
||||
@ -155,7 +153,7 @@ func (k Keeper) PlaceBidForward(ctx sdk.Context, a types.ForwardAuction, bidder
|
||||
|
||||
// TODO naming
|
||||
func (k Keeper) PlaceBidForwardReverseForward(ctx sdk.Context, a types.ForwardReverseAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardReverseAuction, sdk.Error) {
|
||||
// Validate bid
|
||||
// Validate new bid
|
||||
if bid.Denom != a.Bid.Denom {
|
||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
||||
}
|
||||
@ -289,27 +287,28 @@ func (k Keeper) CloseAuction(ctx sdk.Context, auctionID uint64) sdk.Error {
|
||||
}
|
||||
|
||||
// payout to the last bidder
|
||||
var err sdk.Error
|
||||
switch auc := auction.(type) {
|
||||
case types.ForwardAuction, types.ForwardReverseAuction:
|
||||
err = k.PayoutAuctionLot(ctx, auc)
|
||||
if err != nil {
|
||||
case types.ForwardAuction:
|
||||
if err := k.PayoutForwardAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ReverseAuction:
|
||||
err = k.MintAndPayoutAuctionLot(ctx, auc)
|
||||
if err != nil {
|
||||
if err := k.PayoutReverseAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ForwardReverseAuction:
|
||||
if err := k.PayoutForwardReverseAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
panic("unrecognized auction type")
|
||||
}
|
||||
|
||||
// Delete auction from store (and queue)
|
||||
k.DeleteAuction(ctx, auctionID)
|
||||
return nil
|
||||
}
|
||||
func (k Keeper) MintAndPayoutAuctionLot(ctx sdk.Context, a types.ReverseAuction) sdk.Error {
|
||||
|
||||
func (k Keeper) PayoutReverseAuction(ctx sdk.Context, a types.ReverseAuction) sdk.Error {
|
||||
err := k.supplyKeeper.MintCoins(ctx, a.Initiator, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -320,8 +319,17 @@ func (k Keeper) MintAndPayoutAuctionLot(ctx sdk.Context, a types.ReverseAuction)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (k Keeper) PayoutAuctionLot(ctx sdk.Context, a types.Auction) sdk.Error {
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.GetBidder(), sdk.NewCoins(a.GetLot()))
|
||||
|
||||
func (k Keeper) PayoutForwardAuction(ctx sdk.Context, a types.ForwardAuction) sdk.Error {
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.Bidder, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PayoutForwardReverseAuction(ctx sdk.Context, a types.ForwardReverseAuction) sdk.Error {
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.Bidder, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ import (
|
||||
type Auction interface {
|
||||
GetID() uint64
|
||||
WithID(uint64) Auction
|
||||
GetBidder() sdk.AccAddress
|
||||
GetBid() sdk.Coin
|
||||
GetLot() sdk.Coin
|
||||
GetEndTime() time.Time
|
||||
}
|
||||
|
||||
@ -32,15 +29,6 @@ type BaseAuction struct {
|
||||
// GetID getter for auction ID
|
||||
func (a BaseAuction) GetID() uint64 { return a.ID }
|
||||
|
||||
// GetBid getter for auction bid
|
||||
func (a BaseAuction) GetBidder() sdk.AccAddress { return a.Bidder }
|
||||
|
||||
// GetBid getter for auction lot
|
||||
func (a BaseAuction) GetBid() sdk.Coin { return a.Bid }
|
||||
|
||||
// GetLot getter for auction lot
|
||||
func (a BaseAuction) GetLot() sdk.Coin { return a.Lot }
|
||||
|
||||
// GetEndTime getter for auction end time
|
||||
func (a BaseAuction) GetEndTime() time.Time { return a.EndTime }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user