ordermanager

package
v0.0.0-...-491e088 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2019 License: Apache-2.0 Imports: 16 Imported by: 12

Documentation

Index

Constants

View Source
const (
	FORK_EVT_TYPE_FILL        = "fill"
	FORK_EVT_TYPE_CANCEL      = "cancel"
	FORK_EVT_TYPE_CUTOFF      = "cutoff"
	FORK_EVT_TYPE_CUTOFF_PAIR = "cutoff_pair"
)
View Source
const DefaultP2POrderExpireTime = 3600 * 24 * 7

Variables

This section is empty.

Functions

func HandleP2PRingMined

func HandleP2PRingMined(input eventemitter.EventData) error

func IsP2PMakerLocked

func IsP2PMakerLocked(maker string) bool

func SaveP2POrderRelation

func SaveP2POrderRelation(takerOwner, taker, makerOwner, maker, txHash string) error

Types

type CutoffCache

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

func NewCutoffCache

func NewCutoffCache(expire int64) *CutoffCache

func (*CutoffCache) GetCutoff

func (c *CutoffCache) GetCutoff(protocol, owner common.Address) *big.Int

func (*CutoffCache) GetCutoffPair

func (c *CutoffCache) GetCutoffPair(protocol, owner, token1, token2 common.Address) *big.Int

func (*CutoffCache) IsOrderCutoff

func (c *CutoffCache) IsOrderCutoff(protocol, owner, token1, token2 common.Address, validsince *big.Int) bool

合约验证的是创建时间

func (*CutoffCache) UpdateCutoff

func (c *CutoffCache) UpdateCutoff(protocol, owner common.Address, cutoff *big.Int) error

func (*CutoffCache) UpdateCutoffPair

func (c *CutoffCache) UpdateCutoffPair(protocol, owner, token1, token2 common.Address, cutoff *big.Int) error

type ForkProcessor

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

func (*ForkProcessor) Fork

func (p *ForkProcessor) Fork(event *types.ForkedEvent) error
fork process chain fork logic in order manager

1.从各个事件表中获取所有处于分叉块中的事件(fill,cancel,cutoff,cutoffPair)并按照blockNumber以及logIndex倒序 2.遍历event,处理各个类型event对应的回滚逻辑:

a.处理fill,不需关心订单当前状态,减去相应fill量,然后判定订单status为new/partial/finished
b.处理cancel,在合约里,订单是可以被持续cancel的,ordermanager跟随合约逻辑,即便订单已经处于finished/cutoff状态,cancel的量也会递增
  那么,在回滚时,我们可以不关心订单状态(前提是订单只有finished状态,没有cancelled状态,如果前端展示需要cancelled状态,必须根据cancel的量进行计算)
c.处理cutoff,合约里cutoff可以重复提交,而在ordermanager中,所有cutoff事件都会被存储,但是更新订单时,同一个订单不会被多次cutoff
  那么,在回滚时,我们需要知道某一个订单以前是否也cutoff过,在dao/cutoff中我们存储了orderhashList,可以将这些订单取出并按照订单量重置状态
d.处理cutoffPair,同cutoff

func (*ForkProcessor) GetForkEvents

func (p *ForkProcessor) GetForkEvents(from, to int64) (InnerForkEventList, error)

func (*ForkProcessor) MarkForkEvents

func (p *ForkProcessor) MarkForkEvents(from, to int64) error

func (*ForkProcessor) RollBackSingleCancel

func (p *ForkProcessor) RollBackSingleCancel(evt *types.OrderCancelledEvent) error

func (*ForkProcessor) RollBackSingleCutoff

func (p *ForkProcessor) RollBackSingleCutoff(evt *types.CutoffEvent) error

func (*ForkProcessor) RollBackSingleCutoffPair

func (p *ForkProcessor) RollBackSingleCutoffPair(evt *types.CutoffPairEvent) error

func (*ForkProcessor) RollBackSingleFill

func (p *ForkProcessor) RollBackSingleFill(evt *types.OrderFilledEvent) error

calculate order's related values and status, update order

type InnerForkEvent

type InnerForkEvent struct {
	Type        string
	BlockNumber int64
	LogIndex    int64
	Event       interface{}
}

type InnerForkEventList

type InnerForkEventList []InnerForkEvent

func (InnerForkEventList) Len

func (l InnerForkEventList) Len() int

func (InnerForkEventList) Less

func (l InnerForkEventList) Less(i, j int) bool

func (InnerForkEventList) Swap

func (l InnerForkEventList) Swap(i, j int)

type OrderFillOrCancelType

type OrderFillOrCancelType string

写入订单状态

const (
	ORDER_FROM_FILL   OrderFillOrCancelType = "fill"
	ORDER_FROM_CANCEL OrderFillOrCancelType = "cancel"
)

type OrderManager

type OrderManager interface {
	Start()
	Stop()
	MinerOrders(protocol, tokenS, tokenB common.Address, length int, reservedTime, startBlockNumber, endBlockNumber int64, filterOrderHashLists ...*types.OrderDelayList) []*types.OrderState
	GetOrderBook(protocol, tokenS, tokenB common.Address, length int) ([]types.OrderState, error)
	GetOrders(query map[string]interface{}, statusList []types.OrderStatus, pageIndex, pageSize int) (dao.PageResult, error)
	GetOrderByHash(hash common.Hash) (*types.OrderState, error)
	UpdateBroadcastTimeByHash(hash common.Hash, bt int) error
	FillsPageQuery(query map[string]interface{}, pageIndex, pageSize int) (dao.PageResult, error)
	GetLatestFills(query map[string]interface{}, limit int) ([]dao.FillEvent, error)
	FindFillsByRingHash(ringHash common.Hash) (result []dao.FillEvent, err error)
	RingMinedPageQuery(query map[string]interface{}, pageIndex, pageSize int) (dao.PageResult, error)
	IsOrderCutoff(protocol, owner, token1, token2 common.Address, validsince *big.Int) bool
	IsOrderFullFinished(state *types.OrderState) bool
	IsValueDusted(tokenAddress common.Address, value *big.Rat) bool
	GetFrozenAmount(owner common.Address, token common.Address, statusSet []types.OrderStatus, delegateAddress common.Address) (*big.Int, error)
	GetFrozenLRCFee(owner common.Address, statusSet []types.OrderStatus) (*big.Int, error)
}

type OrderManagerImpl

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

func (*OrderManagerImpl) FillsPageQuery

func (om *OrderManagerImpl) FillsPageQuery(query map[string]interface{}, pageIndex, pageSize int) (result dao.PageResult, err error)

func (*OrderManagerImpl) FindFillsByRingHash

func (om *OrderManagerImpl) FindFillsByRingHash(ringHash common.Hash) (result []dao.FillEvent, err error)

func (*OrderManagerImpl) GetFrozenAmount

func (om *OrderManagerImpl) GetFrozenAmount(owner common.Address, token common.Address, statusSet []types.OrderStatus, delegateAddress common.Address) (*big.Int, error)

func (*OrderManagerImpl) GetFrozenLRCFee

func (om *OrderManagerImpl) GetFrozenLRCFee(owner common.Address, statusSet []types.OrderStatus) (*big.Int, error)

func (*OrderManagerImpl) GetLatestFills

func (om *OrderManagerImpl) GetLatestFills(query map[string]interface{}, limit int) (result []dao.FillEvent, err error)

func (*OrderManagerImpl) GetOrderBook

func (om *OrderManagerImpl) GetOrderBook(protocol, tokenS, tokenB common.Address, length int) ([]types.OrderState, error)

func (*OrderManagerImpl) GetOrderByHash

func (om *OrderManagerImpl) GetOrderByHash(hash common.Hash) (orderState *types.OrderState, err error)

func (*OrderManagerImpl) GetOrders

func (om *OrderManagerImpl) GetOrders(query map[string]interface{}, statusList []types.OrderStatus, pageIndex, pageSize int) (dao.PageResult, error)

func (*OrderManagerImpl) IsOrderCutoff

func (om *OrderManagerImpl) IsOrderCutoff(protocol, owner, token1, token2 common.Address, validsince *big.Int) bool

func (*OrderManagerImpl) IsOrderFullFinished

func (om *OrderManagerImpl) IsOrderFullFinished(state *types.OrderState) bool

func (*OrderManagerImpl) IsValueDusted

func (om *OrderManagerImpl) IsValueDusted(tokenAddress common.Address, value *big.Rat) bool

func (*OrderManagerImpl) MinerOrders

func (om *OrderManagerImpl) MinerOrders(protocol, tokenS, tokenB common.Address, length int, reservedTime, startBlockNumber, endBlockNumber int64, filterOrderHashLists ...*types.OrderDelayList) []*types.OrderState

func (*OrderManagerImpl) RingMinedPageQuery

func (om *OrderManagerImpl) RingMinedPageQuery(query map[string]interface{}, pageIndex, pageSize int) (result dao.PageResult, err error)

func (*OrderManagerImpl) Start

func (om *OrderManagerImpl) Start()

Start start orderbook as a service

func (*OrderManagerImpl) Stop

func (om *OrderManagerImpl) Stop()

func (*OrderManagerImpl) UpdateBroadcastTimeByHash

func (om *OrderManagerImpl) UpdateBroadcastTimeByHash(hash common.Hash, bt int) error

Jump to

Keyboard shortcuts

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