Add general files for auction module
This commit is contained in:
parent
6a2df5dbdd
commit
6a2c489cd3
17
x/auction/codec.go
Normal file
17
x/auction/codec.go
Normal file
@ -0,0 +1,17 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
// RegisterInterfaces registers the interfaces types with the interface registry.
|
||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
registry.RegisterImplementations((*sdk.Msg)(nil),
|
||||
&MsgCreateAuction{},
|
||||
&MsgCommitBid{},
|
||||
&MsgRevealBid{},
|
||||
)
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
24
x/auction/genesis.go
Normal file
24
x/auction/genesis.go
Normal file
@ -0,0 +1,24 @@
|
||||
package auction
|
||||
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: DefaultParams(),
|
||||
Auctions: []*Auction{},
|
||||
}
|
||||
}
|
||||
|
||||
func NewGenesisState(params Params, auctions []*Auction) *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: params,
|
||||
Auctions: auctions,
|
||||
}
|
||||
}
|
||||
|
||||
// Validate performs basic genesis state validation returning an error upon any
|
||||
func (gs *GenesisState) Validate() error {
|
||||
if err := gs.Params.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
16
x/auction/keys.go
Normal file
16
x/auction/keys.go
Normal file
@ -0,0 +1,16 @@
|
||||
package auction
|
||||
|
||||
import "cosmossdk.io/collections"
|
||||
|
||||
const (
|
||||
ModuleName = "auction"
|
||||
|
||||
// AuctionBurnModuleAccountName is the name of the auction burn module account.
|
||||
AuctionBurnModuleAccountName = "auction_burn"
|
||||
)
|
||||
|
||||
// Store prefixes
|
||||
var (
|
||||
// ParamsKey is the prefix for params key
|
||||
ParamsKeyPrefix = collections.NewPrefix(0)
|
||||
)
|
@ -1,10 +1,44 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"errors"
|
||||
fmt "fmt"
|
||||
"strings"
|
||||
time "time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultCommitsDuration = 5 * time.Minute
|
||||
DefaultRevealsDuration = 5 * time.Minute
|
||||
DefaultCommitFee = sdk.Coin{Amount: sdkmath.NewInt(10), Denom: sdk.DefaultBondDenom}
|
||||
DefaultRevealFee = sdk.Coin{Amount: sdkmath.NewInt(10), Denom: sdk.DefaultBondDenom}
|
||||
DefaultMinimumBid = sdk.Coin{Amount: sdkmath.NewInt(1000), Denom: sdk.DefaultBondDenom}
|
||||
)
|
||||
|
||||
func NewParams(commitsDuration time.Duration, revealsDuration time.Duration, commitFee sdk.Coin, revealFee sdk.Coin, minimumBid sdk.Coin) Params {
|
||||
return Params{
|
||||
CommitsDuration: commitsDuration,
|
||||
RevealsDuration: revealsDuration,
|
||||
CommitFee: commitFee,
|
||||
RevealFee: revealFee,
|
||||
MinimumBid: minimumBid,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultParams returns a default set of parameters.
|
||||
func DefaultParams() Params {
|
||||
return Params{
|
||||
CommitsDuration: DefaultCommitsDuration,
|
||||
RevealsDuration: DefaultRevealsDuration,
|
||||
CommitFee: DefaultCommitFee,
|
||||
RevealFee: DefaultRevealFee,
|
||||
MinimumBid: DefaultMinimumBid,
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of the parameters.
|
||||
func (p Params) String() string {
|
||||
var sb strings.Builder
|
||||
@ -16,3 +50,93 @@ func (p Params) String() string {
|
||||
sb.WriteString(fmt.Sprintf("MinimumBid: %s\n", p.MinimumBid.String()))
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// Validate a set of params.
|
||||
func (p Params) Validate() error {
|
||||
if err := validateCommitsDuration(p.CommitsDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateRevealsDuration(p.RevealsDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateCommitFee(p.CommitFee); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateRevealFee(p.RevealFee); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateMinimumBid(p.MinimumBid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCommitsDuration(i interface{}) error {
|
||||
v, ok := i.(time.Duration)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v < 0 {
|
||||
return errors.New("commits duration cannot be negative")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRevealsDuration(i interface{}) error {
|
||||
v, ok := i.(time.Duration)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v < 0 {
|
||||
return errors.New("reveals duration cannot be negative")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCommitFee(i interface{}) error {
|
||||
v, ok := i.(sdk.Coin)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v.Amount.IsNegative() {
|
||||
return errors.New("commit fee must be positive")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRevealFee(i interface{}) error {
|
||||
v, ok := i.(sdk.Coin)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v.Amount.IsNegative() {
|
||||
return errors.New("reveal fee must be positive")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMinimumBid(i interface{}) error {
|
||||
v, ok := i.(sdk.Coin)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v.Amount.IsNegative() {
|
||||
return errors.New("minimum bid must be positive")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package bond
|
||||
|
||||
// DefaultGenesisState sets default evm genesis state with empty accounts and default params and
|
||||
// chain config values.
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: DefaultParams(),
|
||||
|
@ -4,9 +4,6 @@ import "cosmossdk.io/collections"
|
||||
|
||||
const (
|
||||
ModuleName = "bond"
|
||||
|
||||
// StoreKey is the string store representation
|
||||
StoreKey = ModuleName
|
||||
)
|
||||
|
||||
// Store prefixes
|
||||
|
Loading…
Reference in New Issue
Block a user