new auction tx & event emission includes hw specs

[UNTESTED]
This commit is contained in:
2022-09-22 23:18:08 +00:00
parent 98c082693d
commit f25f798443
4 changed files with 47 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package keeper
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
@@ -87,6 +88,12 @@ found:
LeaseEnd: msg.LeaseEnd,
// remaining payout -> null
// Remaining: "0",
Gpus: msg.Gpus,
}
// validate hardware
if err := k.ValidateAuctionHardware(ctx, auction); err != nil {
return nil, err
}
spendable := k.bank.SpendableCoins(ctx, senderAddr)
@@ -111,12 +118,22 @@ found:
k.Keeper.SetNextAuction(ctx, types.NextAuction{AuctionId: next.AuctionId})
gpuList, err := json.Marshal(msg.Gpus)
if err != nil {
return nil, fmt.Errorf("failed to marshal gpu list %v", msg.Gpus)
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.AuctionCreatedEventType,
sdk.NewAttribute(types.AuctionCreatedIndex, auction.Index),
sdk.NewAttribute(types.AuctionCreatedEventCreator, msg.Creator),
sdk.NewAttribute(types.AuctionCreatedCeiling, msg.Ceiling),
sdk.NewAttribute(types.AuctionCreatedCpuCores, msg.CpuArch.String()),
sdk.NewAttribute(types.AuctionCreatedCpuArch, msg.CpuArch.String()),
sdk.NewAttribute(types.AuctionCreatedGpus, string(gpuList)),
sdk.NewAttribute(types.AuctionCreatedMemMb, fmt.Sprint(msg.MemMb)),
sdk.NewAttribute(types.AuctionCreatedStorage, fmt.Sprint(msg.StorageGb)),
),
)
@@ -124,3 +141,28 @@ found:
AuctionId: strconv.FormatUint(next.AuctionId, 10),
}, nil
}
func (k *Keeper) ValidateAuctionHardware(ctx sdk.Context, a types.Auction) error {
if a.Gpus == nil {
return errors.New("GPU list not found")
}
for _, gpu := range a.Gpus {
if _, ok := k.GetParams(ctx).GpuModels[gpu]; !ok {
return fmt.Errorf("GPU model %s invalid", gpu)
}
}
// move these to module params later
if a.CpuCores == 0 || a.CpuCores > 12 {
return errors.New("CPU Cores must be between 0 and 12")
}
if a.StorageGb < 25 || a.StorageGb > 2000 {
return fmt.Errorf("storage must be between 25GB and 2TB (got %dGB)", a.StorageGb)
}
return nil
}