auction

package
v1.2.0-fork5-fix2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_START = uint32(1)
	OP_STOP  = uint32(2)
	OP_BID   = uint32(3)

	USER_BID = uint32(0)
	AUTO_BID = uint32(1)
)
View Source
const (
	AUCTION_MAX_SUMMARIES = 32
)

Variables

View Source
var (
	// normal min amount is 10 mtr, autobid is 0.1 mtr
	MinimumBidAmount = new(big.Int).Mul(big.NewInt(10), big.NewInt(1e18))
	AutobidMinAmount = big.NewInt(1e17)
)
View Source
var (
	// 0x74696f6e2d6163636f756e742d61646472657373
	AuctionAccountAddr = meter.BytesToAddress([]byte("auction-account-address"))
	SummaryListKey     = meter.Blake2b([]byte("summary-list-key"))
	AuctionCBKey       = meter.Blake2b([]byte("auction-active-cb-key"))
)

the global variables in auction

Functions

func AuctionEncodeBytes

func AuctionEncodeBytes(sb *AuctionBody) []byte

func GetOpName

func GetOpName(op uint32) string

func SetAuctionGlobInst

func SetAuctionGlobInst(inst *Auction)

Types

type Auction

type Auction struct {
	// contains filtered or unexported fields
}

Candidate indicates the structure of a candidate

var (
	AuctionGlobInst *Auction
)

func GetAuctionGlobInst

func GetAuctionGlobInst() *Auction

func NewAuction

func NewAuction(ch *chain.Chain, sc *state.Creator) *Auction

func (*Auction) ClearAuction

func (a *Auction) ClearAuction(cb *AuctionCB, state *state.State, env *AuctionEnv) (*big.Int, *big.Int, []*DistMtrg, error)

////////////////////// called when auction is over

func (*Auction) GetAuctionCB

func (a *Auction) GetAuctionCB(state *state.State) (result *AuctionCB)

Candidate List

func (*Auction) GetSummaryList

func (a *Auction) GetSummaryList(state *state.State) (result *AuctionSummaryList)

summary List

func (*Auction) PrepareAuctionHandler

func (a *Auction) PrepareAuctionHandler() (AuctionHandler func([]byte, *meter.Address, *xenv.TransactionContext, uint64, *state.State) (*setypes.ScriptEngineOutput, uint64, error))

func (*Auction) SendMTRGToBidder

func (a *Auction) SendMTRGToBidder(addr meter.Address, amount *big.Int, stateDB *statedb.StateDB, env *AuctionEnv)

func (*Auction) SetAuctionCB

func (a *Auction) SetAuctionCB(auctionCB *AuctionCB, state *state.State)

func (*Auction) SetSummaryList

func (a *Auction) SetSummaryList(summaryList *AuctionSummaryList, state *state.State)

func (*Auction) Start

func (a *Auction) Start() error

func (*Auction) TransferAutobidMTRToAuction added in v1.2.0

func (a *Auction) TransferAutobidMTRToAuction(addr meter.Address, amount *big.Int, state *state.State, env *AuctionEnv) error

==================== account openation=========================== from meter.ValidatorBenefitAddr ==> AuctionAccountAddr

func (*Auction) TransferMTRToAuction

func (a *Auction) TransferMTRToAuction(addr meter.Address, amount *big.Int, state *state.State, env *AuctionEnv) error

from addr == > AuctionAccountAddr

func (*Auction) TransferMTRToValidatorBenefit

func (a *Auction) TransferMTRToValidatorBenefit(amount *big.Int, state *state.State, env *AuctionEnv) error

form AuctionAccountAddr ==> meter.ValidatorBenefitAddr

type AuctionBody

type AuctionBody struct {
	Opcode        uint32
	Version       uint32
	Option        uint32
	StartHeight   uint64
	StartEpoch    uint64
	EndHeight     uint64
	EndEpoch      uint64
	Sequence      uint64
	AuctionID     meter.Bytes32
	Bidder        meter.Address
	Amount        *big.Int
	ReserveAmount *big.Int
	Token         byte   // meter or meter gov
	Timestamp     uint64 // timestamp
	Nonce         uint64 // nonce
}

Candidate indicates the structure of a candidate

func AuctionDecodeFromBytes

func AuctionDecodeFromBytes(bytes []byte) (*AuctionBody, error)

func (*AuctionBody) CloseAuctionCB

func (ab *AuctionBody) CloseAuctionCB(env *AuctionEnv, gas uint64) (leftOverGas uint64, err error)

func (*AuctionBody) GetOpName

func (ab *AuctionBody) GetOpName(op uint32) string

func (*AuctionBody) HandleAuctionTx

func (ab *AuctionBody) HandleAuctionTx(env *AuctionEnv, gas uint64) (leftOverGas uint64, err error)

func (*AuctionBody) StartAuctionCB

func (ab *AuctionBody) StartAuctionCB(env *AuctionEnv, gas uint64) (leftOverGas uint64, err error)

func (*AuctionBody) String added in v1.2.0

func (sb *AuctionBody) String() string

func (*AuctionBody) ToString

func (ab *AuctionBody) ToString() string

func (*AuctionBody) UniteHash added in v1.2.0

func (sb *AuctionBody) UniteHash() (hash meter.Bytes32)

type AuctionCB

type AuctionCB struct {
	AuctionID   meter.Bytes32
	StartHeight uint64
	StartEpoch  uint64
	EndHeight   uint64
	EndEpoch    uint64
	Sequence    uint64
	RlsdMTRG    *big.Int //released mtrg
	RsvdMTRG    *big.Int // reserved mtrg
	RsvdPrice   *big.Int
	CreateTime  uint64

	//changed fields after auction start
	RcvdMTR    *big.Int
	AuctionTxs []*AuctionTx
}

///////////////////////////////////////////////// auctionTx indicates the structure of a auctionTx

func GetActiveAuctionCB

func GetActiveAuctionCB() (*AuctionCB, error)

api routine interface

func (*AuctionCB) Add

func (cb *AuctionCB) Add(tx *AuctionTx)

func (*AuctionCB) AddAuctionTx

func (cb *AuctionCB) AddAuctionTx(tx *AuctionTx) error

func (*AuctionCB) Count

func (cb *AuctionCB) Count() int

func (*AuctionCB) Exist

func (cb *AuctionCB) Exist(id meter.Bytes32) bool

func (*AuctionCB) Get

func (cb *AuctionCB) Get(id meter.Bytes32) *AuctionTx

func (*AuctionCB) ID

func (cb *AuctionCB) ID() (hash meter.Bytes32)

bucketID auctionTx .. are excluded

func (*AuctionCB) IsActive

func (cb *AuctionCB) IsActive() bool

func (*AuctionCB) Remove

func (cb *AuctionCB) Remove(id meter.Bytes32)

func (*AuctionCB) RemoveAuctionTx added in v1.2.0

func (cb *AuctionCB) RemoveAuctionTx(tx *AuctionTx) error

Actually Auction do not allow to cancel, so this func should not be called

func (*AuctionCB) ToString

func (cb *AuctionCB) ToString() string

func (*AuctionCB) ToTxList added in v1.2.0

func (cb *AuctionCB) ToTxList() []*AuctionTx

type AuctionEnv added in v1.2.0

type AuctionEnv struct {
	*setypes.ScriptEnv
	// contains filtered or unexported fields
}

func NewAuctionEnv added in v1.2.0

func NewAuctionEnv(auction *Auction, state *state.State, txCtx *xenv.TransactionContext, to *meter.Address) *AuctionEnv

func (*AuctionEnv) GetAuction added in v1.2.0

func (env *AuctionEnv) GetAuction() *Auction

type AuctionSummary

type AuctionSummary struct {
	AuctionID    meter.Bytes32
	StartHeight  uint64
	StartEpoch   uint64
	EndHeight    uint64
	EndEpoch     uint64
	Sequence     uint64
	RlsdMTRG     *big.Int
	RsvdMTRG     *big.Int
	RsvdPrice    *big.Int
	CreateTime   uint64
	RcvdMTR      *big.Int
	ActualPrice  *big.Int
	LeftoverMTRG *big.Int
	AuctionTxs   []*AuctionTx
	DistMTRG     []*DistMtrg
}

func (*AuctionSummary) ToString

func (a *AuctionSummary) ToString() string

type AuctionSummaryList

type AuctionSummaryList struct {
	Summaries []*AuctionSummary
}

func GetAuctionSummaryList

func GetAuctionSummaryList() (*AuctionSummaryList, error)

func GetAuctionSummaryListByHeader added in v1.2.0

func GetAuctionSummaryListByHeader(header *block.Header) (*AuctionSummaryList, error)

api routine interface

func NewAuctionSummaryList

func NewAuctionSummaryList(summaries []*AuctionSummary) *AuctionSummaryList

func (*AuctionSummaryList) Add

func (a *AuctionSummaryList) Add(summary *AuctionSummary) error

func (*AuctionSummaryList) Count

func (a *AuctionSummaryList) Count() int

func (*AuctionSummaryList) Get

func (*AuctionSummaryList) Last added in v1.2.0

func (*AuctionSummaryList) Remove

func (a *AuctionSummaryList) Remove(id meter.Bytes32) error

unsupport at this time

func (*AuctionSummaryList) String

func (a *AuctionSummaryList) String() string

func (*AuctionSummaryList) ToList

func (a *AuctionSummaryList) ToList() []AuctionSummary

func (*AuctionSummaryList) ToString

func (a *AuctionSummaryList) ToString() string

type AuctionTx

type AuctionTx struct {
	TxID      meter.Bytes32
	Address   meter.Address
	Amount    *big.Int // total amont wei is unit
	Type      uint32   // USER_BID or AUTO_BID
	Timestamp uint64   //timestamp
	Nonce     uint64   //randomness
}

func NewAuctionTx added in v1.2.0

func NewAuctionTx(addr meter.Address, amount *big.Int, txtype uint32, time uint64, nonce uint64) *AuctionTx

func (*AuctionTx) ID added in v1.2.0

func (a *AuctionTx) ID() (hash meter.Bytes32)

func (*AuctionTx) ToString

func (a *AuctionTx) ToString() string

type DistMtrg added in v1.2.0

type DistMtrg struct {
	Addr   meter.Address
	Amount *big.Int
}

Jump to

Keyboard shortcuts

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