types

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName is the module name constant used in many places
	ModuleName = "market"

	// StoreKey is the store key string for market
	StoreKey = ModuleName

	// RouterKey is the message route for market
	RouterKey = ModuleName
)

Variables

View Source
var (
	// ErrInvalidOrder is the error when order id is invalid
	ErrInvalidOrder = sdkerrors.Register(ModuleName, errCodeInvalidOrder, "invalid: order id")
	// ErrEmptyProvider is the error when provider is empty
	ErrEmptyProvider = sdkerrors.Register(ModuleName, errCodeEmptyProvider, "empty provider")
	// ErrSameAccount is the error when owner and provider are the same account
	ErrSameAccount = sdkerrors.Register(ModuleName, errCodeSameAccount, "owner and provider are the same account")
	// ErrInternal is the error for internal error
	ErrInternal = sdkerrors.Register(ModuleName, errCodeInternal, "internal error")
	// ErrBidOverOrder is the error when bid price is above max order price
	ErrBidOverOrder = sdkerrors.Register(ModuleName, errCodeOverOrder, "bid price above max order price")
	// ErrAttributeMismatch is the error for attribute mismatch
	ErrAttributeMismatch = sdkerrors.Register(ModuleName, errCodeAttributeMismatch, "attribute mismatch")
	// ErrUnknownBid is the error for unknown bid
	ErrUnknownBid = sdkerrors.Register(ModuleName, errCodeUnknownBid, "unknown bid")
	// ErrUnknownLeaseForBid is the error when lease is unknown for bid
	ErrUnknownLeaseForBid = sdkerrors.Register(ModuleName, errCodeUnknownLeaseForOrder, "unknown lease for bid")
	// ErrUnknownOrderForBid is the error when order is unknown for bid
	ErrUnknownOrderForBid = sdkerrors.Register(ModuleName, errCodeUnknownOrderForBid, "unknown order for bid")
	// ErrLeaseNotActive is the error when lease is not active
	ErrLeaseNotActive = sdkerrors.Register(ModuleName, errCodeLeaseNotActive, "lease not active")
	// ErrBidNotMatched is the error when bid is not matched
	ErrBidNotMatched = sdkerrors.Register(ModuleName, errCodeBidNotMatched, "bid not matched")
	// ErrUnknownOrder is the error when order is unknown
	ErrUnknownOrder = sdkerrors.Register(ModuleName, errCodeUnknownOrder, "unknown order")
	// ErrNoLeaseForOrder is the error when there is no lease for order
	ErrNoLeaseForOrder = sdkerrors.Register(ModuleName, errCodeNoLeaseForOrder, "no lease for order")
	// ErrOrderNotFound order not found
	ErrOrderNotFound = sdkerrors.Register(ModuleName, errCodeOrderNotFound, "invalid order: order not found")
	// ErrBidNotFound bid not found
	ErrBidNotFound = sdkerrors.Register(ModuleName, errCodeBidNotFound, "invalid bid: bid not found")
	// ErrLeaseNotFound lease not found
	ErrLeaseNotFound = sdkerrors.Register(ModuleName, errCodeLeaseNotFound, "invalid lease: lease not found")
	// ErrBidExists bid exists
	ErrBidExists = sdkerrors.Register(ModuleName, errCodeBidExists, "invalid bid: bid exists from provider")
	// ErrBidInvalidPrice bid invalid price
	ErrBidInvalidPrice = sdkerrors.Register(ModuleName, errCodeInvalidPrice, "bid price is invalid")
)
View Source
var (
	ErrOrderMatched = errors.New("order matched")
	ErrOrderClosed  = errors.New("order closed")
	ErrOrderOpen    = errors.New("order open")
)
View Source
var BidStateMap = map[string]BidState{
	"open":    BidOpen,
	"matched": BidMatched,
	"lost":    BidLost,
	"closed":  BidClosed,
}

BidStateMap is used to decode bid state flag value

View Source
var (
	ErrParsingPrice = errors.New("error parsing price")
)
View Source
var LeaseStateMap = map[string]LeaseState{
	"active":       LeaseActive,
	"insufficient": LeaseInsufficientFunds,
	"closed":       LeaseClosed,
}

LeaseStateMap is used to decode lease state flag value

View Source
var OrderStateMap = map[string]OrderState{
	"open":    OrderOpen,
	"matched": OrderMatched,
	"closed":  OrderClosed,
}

OrderStateMap is used to decode order state flag value

Functions

func BidIDString added in v0.6.5

func BidIDString(id BidID) string

BidIDString provides consistent conversion to string values for BidID/LeaseIDs.

func MustMarshalJSON

func MustMarshalJSON(o interface{}) []byte

MustMarshalJSON panics if an error occurs. Besides that it behaves exactly like MarshalJSON i.e., encodes json to byte array

func MustUnmarshalJSON

func MustUnmarshalJSON(bz []byte, ptr interface{})

MustUnmarshalJSON panics if an error occurs. Besides that it behaves exactly like UnmarshalJSON.

func OrderIDString added in v0.7.3

func OrderIDString(id OrderID) string

OrderIDString provides consistent conversion to string values for OrderID.

func ParseEvent

func ParseEvent(ev sdkutil.Event) (interface{}, error)

ParseEvent parses event and returns details of event and error if occurred

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec register concrete types on codec

func UnmarshalJSON

func UnmarshalJSON(bz []byte, ptr interface{}) error

UnmarshalJSON decodes bytes into json

Types

type Bid

type Bid struct {
	BidID `json:"id"`
	State BidState `json:"state"`
	Price sdk.Coin `json:"price"`
}

Bid stores BidID, state of bid and price

func (Bid) ID

func (obj Bid) ID() BidID

ID method returns BidID details of specific bid

type BidID

type BidID struct {
	Owner    sdk.AccAddress `json:"owner"`
	DSeq     uint64         `json:"dseq"`
	GSeq     uint32         `json:"gseq"`
	OSeq     uint32         `json:"oseq"`
	Provider sdk.AccAddress `json:"provider"`
}

BidID stores owner, provider and all other seq numbers. A successful bid becomes a Lease(ID).

func MakeBidID

func MakeBidID(id OrderID, provider sdk.AccAddress) BidID

MakeBidID returns BidID instance with provided order details and provider

func (BidID) DeploymentID

func (id BidID) DeploymentID() dtypes.DeploymentID

DeploymentID method returns deployment details with specific bid details

func (BidID) Equals

func (id BidID) Equals(other BidID) bool

Equals method compares specific bid with provided bid

func (BidID) GroupID

func (id BidID) GroupID() dtypes.GroupID

GroupID method returns GroupID details with specific bid details

func (BidID) LeaseID

func (id BidID) LeaseID() LeaseID

LeaseID method returns lease details of bid

func (BidID) OrderID

func (id BidID) OrderID() OrderID

OrderID method returns OrderID details with specific bid details

func (BidID) Validate

func (id BidID) Validate() error

Validate validates bid instance and returns nil

type BidState

type BidState uint8

BidState defines state of bid

const (
	// BidOpen is used when state of bid is opened
	BidOpen BidState = iota + 1
	// BidMatched is used when state of bid is matched
	BidMatched
	// BidLost is used when state of bid is lost
	BidLost
	// BidClosed is used when state of bid is closed
	BidClosed
)

type EventBidClosed

type EventBidClosed struct {
	ID    BidID
	Price sdk.Coin
}

EventBidClosed struct

func (EventBidClosed) ToSDKEvent

func (e EventBidClosed) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventBidClosed struct

type EventBidCreated

type EventBidCreated struct {
	ID    BidID
	Price sdk.Coin
}

EventBidCreated struct

func (EventBidCreated) ToSDKEvent

func (e EventBidCreated) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventBidCreated struct

type EventLeaseClosed

type EventLeaseClosed struct {
	ID    LeaseID
	Price sdk.Coin
}

EventLeaseClosed struct

func (EventLeaseClosed) ToSDKEvent

func (e EventLeaseClosed) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventLeaseClosed struct

type EventLeaseCreated

type EventLeaseCreated struct {
	ID    LeaseID
	Price sdk.Coin
}

EventLeaseCreated struct

func (EventLeaseCreated) ToSDKEvent

func (e EventLeaseCreated) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventLeaseCreated struct

type EventOrderClosed

type EventOrderClosed struct {
	ID OrderID
}

EventOrderClosed struct

func (EventOrderClosed) ToSDKEvent

func (e EventOrderClosed) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventOrderClosed struct

type EventOrderCreated

type EventOrderCreated struct {
	ID OrderID
}

EventOrderCreated struct

func (EventOrderCreated) ToSDKEvent

func (e EventOrderCreated) ToSDKEvent() sdk.Event

ToSDKEvent method creates new sdk event for EventOrderCreated struct

type Lease

type Lease struct {
	LeaseID `json:"id"`
	State   LeaseState `json:"state"`
	Price   sdk.Coin   `json:"price"`
}

Lease stores LeaseID, state of lease and price

func (Lease) ID

func (obj Lease) ID() LeaseID

ID method returns LeaseID details of specific lease

type LeaseID

type LeaseID BidID

LeaseID stores bid details of lease

func MakeLeaseID

func MakeLeaseID(id BidID) LeaseID

MakeLeaseID returns LeaseID instance with provided bid details

func (LeaseID) BidID

func (id LeaseID) BidID() BidID

BidID method returns BidID details with specific LeaseID

func (LeaseID) DeploymentID

func (id LeaseID) DeploymentID() dtypes.DeploymentID

DeploymentID method returns deployment details with specific lease details

func (LeaseID) Equals

func (id LeaseID) Equals(other LeaseID) bool

Equals method compares specific lease with provided lease

func (LeaseID) GroupID

func (id LeaseID) GroupID() dtypes.GroupID

GroupID method returns GroupID details with specific lease details

func (LeaseID) OrderID

func (id LeaseID) OrderID() OrderID

OrderID method returns OrderID details with specific lease details

func (LeaseID) Validate added in v0.6.2

func (id LeaseID) Validate() error

Validate calls the BidID's validator and returns any error.

type LeaseState

type LeaseState uint8

LeaseState defines state of Lease

const (
	// LeaseActive is used when state of lease is active
	LeaseActive LeaseState = iota + 1
	// LeaseInsufficientFunds is used when lease has insufficient funds
	LeaseInsufficientFunds
	// LeaseClosed is used when state of lease is closed
	LeaseClosed
)

type MsgCloseBid

type MsgCloseBid struct {
	BidID `json:"id"`
}

MsgCloseBid defines an SDK message for closing bid

func (MsgCloseBid) GetSignBytes

func (msg MsgCloseBid) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgCloseBid) GetSigners

func (msg MsgCloseBid) GetSigners() []sdk.AccAddress

GetSigners defines whose signature is required

func (MsgCloseBid) Route

func (msg MsgCloseBid) Route() string

Route implements the sdk.Msg interface

func (MsgCloseBid) Type

func (msg MsgCloseBid) Type() string

Type implements the sdk.Msg interface

func (MsgCloseBid) ValidateBasic

func (msg MsgCloseBid) ValidateBasic() error

ValidateBasic method for MsgCloseBid

type MsgCloseOrder

type MsgCloseOrder struct {
	OrderID `json:"id"`
}

MsgCloseOrder defines an SDK message for closing order

func (MsgCloseOrder) GetSignBytes

func (msg MsgCloseOrder) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgCloseOrder) GetSigners

func (msg MsgCloseOrder) GetSigners() []sdk.AccAddress

GetSigners defines whose signature is required

func (MsgCloseOrder) Route

func (msg MsgCloseOrder) Route() string

Route implements the sdk.Msg interface

func (MsgCloseOrder) Type

func (msg MsgCloseOrder) Type() string

Type implements the sdk.Msg interface

func (MsgCloseOrder) ValidateBasic

func (msg MsgCloseOrder) ValidateBasic() error

ValidateBasic method for MsgCloseOrder

type MsgCreateBid

type MsgCreateBid struct {
	Order    OrderID        `json:"order"`
	Provider sdk.AccAddress `json:"owner"`
	Price    sdk.Coin       `json:"price"`
}

MsgCreateBid defines an SDK message for creating Bid

func (MsgCreateBid) GetSignBytes

func (msg MsgCreateBid) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgCreateBid) GetSigners

func (msg MsgCreateBid) GetSigners() []sdk.AccAddress

GetSigners defines whose signature is required

func (MsgCreateBid) Route

func (msg MsgCreateBid) Route() string

Route implements the sdk.Msg interface

func (MsgCreateBid) Type

func (msg MsgCreateBid) Type() string

Type implements the sdk.Msg interface

func (MsgCreateBid) ValidateBasic

func (msg MsgCreateBid) ValidateBasic() error

ValidateBasic does basic validation of provider and order

type Order

type Order struct {
	OrderID `json:"id"`
	State   OrderState `json:"state"`

	// block height to start matching
	StartAt int64            `json:"start-at"`
	Spec    dtypes.GroupSpec `json:"spec"`
}

Order stores orderID, state of order and other details

func (Order) ID

func (o Order) ID() OrderID

ID method returns OrderID details of specific order

func (Order) MatchAttributes

func (o Order) MatchAttributes(attrs []sdk.Attribute) bool

MatchAttributes method compares provided attributes with specific order attributes

func (Order) Price

func (o Order) Price() sdk.Coin

Price method returns price of specific order

func (Order) ValidateCanBid

func (o Order) ValidateCanBid() error

ValidateCanBid method validates whether order is open or not and returns error if not

func (Order) ValidateCanMatch

func (o Order) ValidateCanMatch(height int64) error

ValidateCanMatch method validates whether to match order for provided height

func (Order) ValidateInactive added in v0.6.3

func (o Order) ValidateInactive() error

ValidateInactive method validates whether order is open or not and returns error if not

type OrderID

type OrderID struct {
	Owner sdk.AccAddress `json:"owner"`
	DSeq  uint64         `json:"dseq"`
	GSeq  uint32         `json:"gseq"`
	OSeq  uint32         `json:"oseq"`
}

OrderID stores owner and all other seq numbers

func MakeOrderID

func MakeOrderID(id dtypes.GroupID, oseq uint32) OrderID

MakeOrderID returns OrderID instance with provided groupID details and oseq

func (OrderID) Equals

func (id OrderID) Equals(other OrderID) bool

Equals method compares specific order with provided order

func (OrderID) GroupID

func (id OrderID) GroupID() dtypes.GroupID

GroupID method returns groupID details for specific order

func (OrderID) Validate

func (id OrderID) Validate() error

Validate method for OrderID and returns nil

type OrderState

type OrderState uint8

OrderState defines state of order

const (
	// OrderOpen is used when state of order is open
	OrderOpen OrderState = iota + 1
	// OrderMatched is used when state of order is matched
	OrderMatched
	// OrderClosed is used when state of order is closed
	OrderClosed
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL