auction

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TOKEN_METER     = byte(0)
	TOKEN_METER_GOV = byte(1)
)
View Source
const (
	OP_START = uint32(1)
	OP_STOP  = uint32(2)
	OP_BID   = uint32(3)
)
View Source
const (
	AUCTION_MAX_SUMMARIES = 1200
)
View Source
const (
	N = 24 // history buffer size
)

Variables

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

View Source
var (
	MinimumBidAmount = new(big.Int).Mul(big.NewInt(10), big.NewInt(1e18))
)

Functions

func AuctionEncodeBytes

func AuctionEncodeBytes(sb *AuctionBody) []byte

func CalcRewardEpochRange

func CalcRewardEpochRange(startEpoch, endEpoch uint64) (totalReward float64, totalUnrelease float64, epochRewards []float64, err error)

released MTRG for a speciefic range

func FloatToBigInt

func FloatToBigInt(val float64) *big.Int

func GetAuctionInitialRelease

func GetAuctionInitialRelease() float64

func GetAuctionReservedPrice

func GetAuctionReservedPrice() *big.Int

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) (*big.Int, *big.Int, error)

============================================== 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(data []byte, to *meter.Address, txCtx *xenv.TransactionContext, gas uint64, state *state.State) (ret []byte, leftOverGas uint64, err error))

func (*Auction) SendMTRGToBidder

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

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) TransferMTRToAuction

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

==================== account openation=========================== from addr == > AuctionAccountAddr

func (*Auction) TransferMTRToValidatorBenefit

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

form AuctionAccountAddr ==> meter.ValidatorBenefitAddr

type AuctionBody

type AuctionBody struct {
	Opcode        uint32
	Version       uint32
	Option        uint32
	StartHeight   uint64
	StartEpoch    uint64
	EndHeight     uint64
	EndEpoch      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(senv *AuctionEnviroment, gas uint64) (ret []byte, leftOverGas uint64, err error)

func (*AuctionBody) GetOpName

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

func (*AuctionBody) HandleAuctionTx

func (ab *AuctionBody) HandleAuctionTx(senv *AuctionEnviroment, gas uint64) (ret []byte, leftOverGas uint64, err error)

func (*AuctionBody) StartAuctionCB

func (ab *AuctionBody) StartAuctionCB(env *AuctionEnviroment, gas uint64) (ret []byte, leftOverGas uint64, err error)

func (*AuctionBody) ToString

func (ab *AuctionBody) ToString() string

type AuctionCB

type AuctionCB struct {
	AuctionID   meter.Bytes32
	StartHeight uint64
	StartEpoch  uint64
	EndHeight   uint64
	EndEpoch    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(c *AuctionTx) error

func (*AuctionCB) AddAuctionTx

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

func (*AuctionCB) Count

func (cb *AuctionCB) Count() int

func (*AuctionCB) Exist

func (cb *AuctionCB) Exist(addr meter.Address) bool

func (*AuctionCB) Get

func (cb *AuctionCB) Get(addr meter.Address) *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(addr meter.Address) error

func (*AuctionCB) ToList

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

func (*AuctionCB) ToString

func (cb *AuctionCB) ToString() string

type AuctionEnviroment

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

func NewAuctionEnviroment

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

func (*AuctionEnviroment) GetAuction

func (env *AuctionEnviroment) GetAuction() *Auction

func (*AuctionEnviroment) GetState

func (env *AuctionEnviroment) GetState() *state.State

func (*AuctionEnviroment) GetToAddr

func (env *AuctionEnviroment) GetToAddr() *meter.Address

func (*AuctionEnviroment) GetTxCtx

func (env *AuctionEnviroment) GetTxCtx() *xenv.TransactionContext

type AuctionSummary

type AuctionSummary struct {
	AuctionID    meter.Bytes32
	StartHeight  uint64
	StartEpoch   uint64
	EndHeight    uint64
	EndEpoch     uint64
	RlsdMTRG     *big.Int
	RsvdMTRG     *big.Int
	RsvdPrice    *big.Int
	CreateTime   uint64
	RcvdMTR      *big.Int
	ActualPrice  *big.Int
	LeftoverMTRG *big.Int
}

func (*AuctionSummary) ToString

func (a *AuctionSummary) ToString() string

type AuctionSummaryList

type AuctionSummaryList struct {
	Summaries []*AuctionSummary
}

func GetAuctionSummaryList

func GetAuctionSummaryList() (*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) 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 {
	Addr     meter.Address
	Amount   *big.Int // total amont wei is unit
	Count    uint32
	Nonce    uint64
	LastTime uint64 //last auction time
}

func (*AuctionTx) ToString

func (a *AuctionTx) ToString() string

Jump to

Keyboard shortcuts

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