laconicd/x/auction/types.go
Prathamesh Musale 52e8d322fa Add service provider auctions (#59)
Part of [Service provider auctions](https://www.notion.so/Service-provider-auctions-a7b63697d818479493ec145ea6ea3c1c)

- Add a new type of auction for service providers
  - Add a command to release provider auction funds
- Remove unused auction module params

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Co-authored-by: Isha Venikar <ishavenikar@Ishas-MacBook-Air.local>
Reviewed-on: cerc-io/laconicd#59
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-09-25 12:38:49 +00:00

72 lines
1.5 KiB
Go

package auction
import (
"crypto/sha256"
"encoding/hex"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Auction status values.
const (
// Auction is in commit phase.
AuctionStatusCommitPhase = "commit"
// Auction is in reveal phase.
AuctionStatusRevealPhase = "reveal"
// Auction has ended (no reveals allowed).
AuctionStatusExpired = "expired"
// Auction has completed (winner selected).
AuctionStatusCompleted = "completed"
)
// Bid status values.
const (
BidStatusCommitted = "commit"
BidStatusRevealed = "reveal"
)
// Auction kinds
const (
AuctionKindVickrey = "vickrey"
AuctionKindProvider = "provider"
)
// AuctionId simplifies generation of auction ids.
type AuctionId struct {
Address sdk.Address
AccNum uint64
Sequence uint64
}
// Generate creates the auction id.
func (auctionId AuctionId) Generate() string {
hasher := sha256.New()
str := fmt.Sprintf("%s:%d:%d", auctionId.Address.String(), auctionId.AccNum, auctionId.Sequence)
hasher.Write([]byte(str))
return hex.EncodeToString(hasher.Sum(nil))
}
func (auction Auction) GetCreateTime() string {
return string(sdk.FormatTimeBytes(auction.CreateTime))
}
func (auction Auction) GetCommitsEndTime() string {
return string(sdk.FormatTimeBytes(auction.CommitsEndTime))
}
func (auction Auction) GetRevealsEndTime() string {
return string(sdk.FormatTimeBytes(auction.RevealsEndTime))
}
func (bid Bid) GetCommitTime() string {
return string(sdk.FormatTimeBytes(bid.CommitTime))
}
func (bid Bid) GetRevealTime() string {
return string(sdk.FormatTimeBytes(bid.RevealTime))
}