Save auction object on releasing funds
Some checks failed
Protobuf / lint (pull_request) Successful in 11s
Build / build (pull_request) Successful in 2m10s
E2E Tests / test-e2e (pull_request) Successful in 3m12s
Integration Tests / test-integration (pull_request) Successful in 1m48s
SDK Tests / sdk_tests_authority_auctions (pull_request) Failing after 4m53s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 7m36s
Unit Tests / test-unit (pull_request) Successful in 1m49s
SDK Tests / sdk_tests (pull_request) Failing after 9m5s

This commit is contained in:
Prathamesh Musale 2024-09-24 11:12:57 +05:30
parent 01bc492371
commit 552db03227
6 changed files with 44 additions and 49 deletions

View File

@ -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

View File

@ -95,8 +95,8 @@ message Auction {
// Only applicable in provider auctions
int32 num_providers = 15;
bool funds_released = 16 [
(gogoproto.moretags) =
bool funds_released = 16
[ (gogoproto.moretags) =
"json:\"funds_released\" yaml:\"funds_released\"" ];
}

View File

@ -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;

View File

@ -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,21 +929,26 @@ 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 {
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, "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 {
@ -958,7 +956,7 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
panic("Invalid winner address.")
}
// Send winning price to bidders
// Send winning price to winning bidders
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx,
auctiontypes.ModuleName,
@ -970,9 +968,6 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
panic(sdkErr)
}
}
}
auction.FundsReleased = true
return &auction, err
}

View File

@ -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

View File

@ -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"`