manager

package
v1.5.0 Latest Latest
Warning

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

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

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 FlexCancelOrder

func FlexCancelOrder(event *types.FlexCancelOrderEvent) error

func HandleCutoffEvent

func HandleCutoffEvent(event *types.CutoffEvent) error

func HandleCutoffPair

func HandleCutoffPair(event *types.CutoffPairEvent) error

func HandleGatewayOrder

func HandleGatewayOrder(state *types.OrderState) error

所有来自gateway的订单都是新订单

func HandleOrderCancelledEvent

func HandleOrderCancelledEvent(event *types.OrderCancelledEvent) error

func HandleOrderFilledEvent

func HandleOrderFilledEvent(event *types.OrderFilledEvent) error

func HandleP2PRingMined

func HandleP2PRingMined(input eventemitter.EventData) error

func HandleRingMinedEvent

func HandleRingMinedEvent(event *types.RingMinedEvent) error

func HandleSubmitRingMethodEvent

func HandleSubmitRingMethodEvent(event *types.SubmitRingMethodEvent) error

func IsEventDuplicate

func IsEventDuplicate(eventStatus types.TxStatus, modelStatus uint8) bool

记录已经存在的情况下 判断是否重复

func IsP2PMakerLocked

func IsP2PMakerLocked(maker string) bool

func MinerOrders

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

func NewOrderEntity

func NewOrderEntity(state *types.OrderState, blockNumber *big.Int) (*dao.Order, error)

func SaveP2POrderRelation

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

func SettleOrderAmountOnChain

func SettleOrderAmountOnChain(state *types.OrderState) error

func SettleOrderStatus

func SettleOrderStatus(state *types.OrderState, isCancel bool)

func UpdateBroadcastTimeByHash

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

Types

type BaseHandler

type BaseHandler struct {
	Rds         *dao.RdsService
	MarketCap   marketcap.MarketCapProvider
	CutoffCache *omcm.CutoffCache
	TxInfo      types.TxInfo
}

type EventStatusHandler

type EventStatusHandler interface {
	HandleFailed() error
	HandlePending() error
	HandleSuccess() error
}

type ForkProcessor

type ForkProcessor struct{}

func NewForkProcess

func NewForkProcess() *ForkProcessor

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 OrderManager

type OrderManager interface {
	Start()
	Stop()
}

type OrderManagerImpl

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

func NewOrderManager

func NewOrderManager(
	options *common.OrderManagerOptions,
	db *dao.RdsService,
	market marketcap.MarketCapProvider,
	brokers []string) *OrderManagerImpl

func (*OrderManagerImpl) HandleOrderCorrelatedEvent

func (om *OrderManagerImpl) HandleOrderCorrelatedEvent(input eventemitter.EventData) error

func (*OrderManagerImpl) HandlerOrderRelatedEvent

func (om *OrderManagerImpl) HandlerOrderRelatedEvent(input eventemitter.EventData) error

func (*OrderManagerImpl) Start

func (om *OrderManagerImpl) Start()

Start start orderbook as a service

func (*OrderManagerImpl) Stop

func (om *OrderManagerImpl) Stop()

type OrderTxHandler

type OrderTxHandler struct {
	Event    *omtyp.OrderTx
	TxStatus types.TxStatus
}

func BaseOrderTxHandler

func BaseOrderTxHandler(txinfo types.TxInfo) *OrderTxHandler

func FullOrderTxHandler

func FullOrderTxHandler(txinfo types.TxInfo, orderhash common.Hash, orderstatus types.OrderStatus) *OrderTxHandler

func (*OrderTxHandler) HandlerOrderCorrelatedTx

func (handler *OrderTxHandler) HandlerOrderCorrelatedTx() error

func (*OrderTxHandler) HandlerOrderRelatedTx

func (handler *OrderTxHandler) HandlerOrderRelatedTx() error

Jump to

Keyboard shortcuts

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