mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35: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
|
// place bid
|
||||||
var err sdk.Error
|
var err sdk.Error
|
||||||
var a types.Auction
|
var updatedAuction types.Auction
|
||||||
switch auc := auction.(type) {
|
switch a := auction.(type) {
|
||||||
case types.ForwardAuction:
|
case types.ForwardAuction:
|
||||||
a, err = k.PlaceBidForward(ctx, auc, bidder, newAmount)
|
if updatedAuction, err = k.PlaceBidForward(ctx, a, bidder, newAmount); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case types.ReverseAuction:
|
case types.ReverseAuction:
|
||||||
a, err = k.PlaceBidReverse(ctx, auc, bidder, newAmount)
|
if updatedAuction, err = k.PlaceBidReverse(ctx, a, bidder, newAmount); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case types.ForwardReverseAuction:
|
case types.ForwardReverseAuction:
|
||||||
if !auc.IsReversePhase() {
|
if !a.IsReversePhase() {
|
||||||
a, err = k.PlaceBidForwardReverseForward(ctx, auc, bidder, newAmount)
|
updatedAuction, err = k.PlaceBidForwardReverseForward(ctx, a, bidder, newAmount)
|
||||||
} else {
|
} else {
|
||||||
a, err = k.PlaceBidForwardReverseReverse(ctx, auc, bidder, newAmount)
|
updatedAuction, err = k.PlaceBidForwardReverseReverse(ctx, a, bidder, newAmount)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -109,12 +107,12 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auctionID uint64, bidder sdk.AccAddres
|
|||||||
}
|
}
|
||||||
|
|
||||||
// store updated auction
|
// store updated auction
|
||||||
k.SetAuction(ctx, a)
|
k.SetAuction(ctx, updatedAuction)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) PlaceBidForward(ctx sdk.Context, a types.ForwardAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardAuction, sdk.Error) {
|
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 {
|
if bid.Denom != a.Bid.Denom {
|
||||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
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
|
// TODO naming
|
||||||
func (k Keeper) PlaceBidForwardReverseForward(ctx sdk.Context, a types.ForwardReverseAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardReverseAuction, sdk.Error) {
|
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 {
|
if bid.Denom != a.Bid.Denom {
|
||||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
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
|
// payout to the last bidder
|
||||||
var err sdk.Error
|
|
||||||
switch auc := auction.(type) {
|
switch auc := auction.(type) {
|
||||||
case types.ForwardAuction, types.ForwardReverseAuction:
|
case types.ForwardAuction:
|
||||||
err = k.PayoutAuctionLot(ctx, auc)
|
if err := k.PayoutForwardAuction(ctx, auc); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case types.ReverseAuction:
|
case types.ReverseAuction:
|
||||||
err = k.MintAndPayoutAuctionLot(ctx, auc)
|
if err := k.PayoutReverseAuction(ctx, auc); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
|
}
|
||||||
|
case types.ForwardReverseAuction:
|
||||||
|
if err := k.PayoutForwardReverseAuction(ctx, auc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("unrecognized auction type")
|
panic("unrecognized auction type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete auction from store (and queue)
|
|
||||||
k.DeleteAuction(ctx, auctionID)
|
k.DeleteAuction(ctx, auctionID)
|
||||||
return nil
|
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))
|
err := k.supplyKeeper.MintCoins(ctx, a.Initiator, sdk.NewCoins(a.Lot))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -320,8 +319,17 @@ func (k Keeper) MintAndPayoutAuctionLot(ctx sdk.Context, a types.ReverseAuction)
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,6 @@ import (
|
|||||||
type Auction interface {
|
type Auction interface {
|
||||||
GetID() uint64
|
GetID() uint64
|
||||||
WithID(uint64) Auction
|
WithID(uint64) Auction
|
||||||
GetBidder() sdk.AccAddress
|
|
||||||
GetBid() sdk.Coin
|
|
||||||
GetLot() sdk.Coin
|
|
||||||
GetEndTime() time.Time
|
GetEndTime() time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,15 +29,6 @@ type BaseAuction struct {
|
|||||||
// GetID getter for auction ID
|
// GetID getter for auction ID
|
||||||
func (a BaseAuction) GetID() uint64 { return a.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
|
// GetEndTime getter for auction end time
|
||||||
func (a BaseAuction) GetEndTime() time.Time { return a.EndTime }
|
func (a BaseAuction) GetEndTime() time.Time { return a.EndTime }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user