Add service provider auctions #59
@ -5668,7 +5668,8 @@ func (x *MsgReleaseFunds) GetSigner() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the
|
||||
// funds
|
||||
type MsgReleaseFundsResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
|
@ -95,9 +95,9 @@ message Auction {
|
||||
// Only applicable in provider auctions
|
||||
int32 num_providers = 15;
|
||||
|
||||
bool funds_released = 16 [
|
||||
(gogoproto.moretags) =
|
||||
"json:\"funds_released\" yaml:\"funds_released\"" ];
|
||||
bool funds_released = 16
|
||||
[ (gogoproto.moretags) =
|
||||
"json:\"funds_released\" yaml:\"funds_released\"" ];
|
||||
}
|
||||
|
||||
// Auctions represent all the auctions in the module
|
||||
|
@ -192,7 +192,8 @@ message MsgReleaseFunds {
|
||||
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
|
||||
}
|
||||
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the
|
||||
// funds
|
||||
message MsgReleaseFundsResponse {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
|
@ -892,16 +892,16 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
||||
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(auction.WinnerAddresses))))
|
||||
creatorLeftOverAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
|
||||
|
||||
creatorAddress, err := sdk.AccAddressFromBech32(auction.OwnerAddress)
|
||||
ownerAccAddress, err := sdk.AccAddressFromBech32(auction.OwnerAddress)
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid creatorAddress address. %v", err))
|
||||
panic("Invalid creator address.")
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid auction owner address. %v", err))
|
||||
panic("Invalid auction owner address.")
|
||||
}
|
||||
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
creatorAddress,
|
||||
ownerAccAddress,
|
||||
sdk.NewCoins(creatorLeftOverAmount),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
@ -920,13 +920,6 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
||||
}
|
||||
|
||||
func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds) (*auctiontypes.Auction, error) {
|
||||
if has, err := k.HasAuction(ctx, msg.AuctionId); !has {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
|
||||
}
|
||||
|
||||
auction, err := k.GetAuctionById(ctx, msg.AuctionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -936,43 +929,45 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction kind must be provider.")
|
||||
}
|
||||
|
||||
if auction.Status != auctiontypes.AuctionStatusCompleted {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.")
|
||||
}
|
||||
|
||||
if auction.Status == auctiontypes.AuctionStatusFundsReleased {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Funds have already been released.")
|
||||
}
|
||||
|
||||
// Only the auction owner can release funds.
|
||||
if msg.Signer != auction.OwnerAddress {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Auction owner mismatch.")
|
||||
}
|
||||
|
||||
// Process winner accounts (if nobody bids, there won't be a winner).
|
||||
if len(auction.WinnerAddresses) > 0 {
|
||||
for _, winnerAddress := range auction.WinnerAddresses {
|
||||
winnerAccAddress, err := sdk.AccAddressFromBech32(winnerAddress)
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
panic("Invalid winner address.")
|
||||
}
|
||||
if auction.Status != auctiontypes.AuctionStatusCompleted {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.")
|
||||
}
|
||||
|
||||
// Send winning price to bidders
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
winnerAccAddress,
|
||||
sdk.NewCoins(auction.WinningPrice),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error sending funds to winner: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
if auction.Status == auctiontypes.AuctionStatusFundsReleased {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction funds already released.")
|
||||
}
|
||||
|
||||
// Mark funds as released in the stored auction
|
||||
auction.FundsReleased = true
|
||||
if err = k.SaveAuction(ctx, &auction); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Process winner accounts.
|
||||
for _, winnerAddress := range auction.WinnerAddresses {
|
||||
winnerAccAddress, err := sdk.AccAddressFromBech32(winnerAddress)
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
panic("Invalid winner address.")
|
||||
}
|
||||
|
||||
// Send winning price to winning bidders
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
winnerAccAddress,
|
||||
sdk.NewCoins(auction.WinningPrice),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error sending funds to winner: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
|
||||
auction.FundsReleased = true
|
||||
|
||||
return &auction, err
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate
|
||||
}
|
||||
|
||||
// CommitBid is the command for committing a bid
|
||||
// nolint: all
|
||||
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
@ -94,7 +93,6 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
|
||||
}
|
||||
|
||||
// RevealBid is the command for revealing a bid
|
||||
// nolint: all
|
||||
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
@ -151,7 +149,6 @@ func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateP
|
||||
}
|
||||
|
||||
// ReleaseFunds is the command to pay the winning amounts to provider auction winners
|
||||
// nolint: all
|
||||
func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgReleaseFunds) (*auctiontypes.MsgReleaseFundsResponse, error) {
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
|
@ -434,7 +434,8 @@ func (m *MsgReleaseFunds) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_MsgReleaseFunds proto.InternalMessageInfo
|
||||
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds
|
||||
// MsgReleaseFundsResponse returns the state of the auction after releasing the
|
||||
// funds
|
||||
type MsgReleaseFundsResponse struct {
|
||||
// Auction details
|
||||
Auction *Auction `protobuf:"bytes,1,opt,name=auction,proto3" json:"auction,omitempty" json:"auction" yaml:"auction"`
|
||||
|
Loading…
Reference in New Issue
Block a user