Documentation ¶
Index ¶
- Constants
- Variables
- func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingstate.OrderItem, ...) error
- func GetTokenAbi() (*abi.ABI, error)
- func GetTradeQuantity(takerSide string, takerFeeRate *big.Int, takerBalance *big.Int, ...) (*big.Int, bool)
- func NewLDBEngine(cfg *Config) *XDCxDAO.BatchDatabase
- func NewMongoDBEngine(cfg *Config) *XDCxDAO.MongoDatabase
- func RunContract(chain consensus.ChainContext, statedb *state.StateDB, ...) (interface{}, error)
- type Config
- type PublicXDCXAPI
- type XDCX
- func (XDCx *XDCX) APIs() []rpc.API
- func (XDCx *XDCX) ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, ...) ([]map[string]string, []*tradingstate.OrderItem, error)
- func (XDCx *XDCX) CommitOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, ...) ([]map[string]string, []*tradingstate.OrderItem, error)
- func (XDCx *XDCX) ConvertXDCToToken(chain consensus.ChainContext, statedb *state.StateDB, ...) (*big.Int, *big.Int, error)
- func (XDCx *XDCX) GetAveragePriceLastEpoch(chain consensus.ChainContext, statedb *state.StateDB, ...) (*big.Int, error)
- func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error)
- func (XDCx *XDCX) GetLevelDB() XDCxDAO.XDCXDAO
- func (XDCx *XDCX) GetMongoDB() XDCxDAO.XDCXDAO
- func (XDCx *XDCX) GetStateCache() tradingstate.Database
- func (XDCx *XDCX) GetTokenDecimal(chain consensus.ChainContext, statedb *state.StateDB, tokenAddr common.Address) (*big.Int, error)
- func (XDCx *XDCX) GetTradingState(block *types.Block, author common.Address) (*tradingstate.TradingStateDB, error)
- func (XDCx *XDCX) GetTradingStateRoot(block *types.Block, author common.Address) (common.Hash, error)
- func (XDCx *XDCX) GetTriegc() *prque.Prque
- func (XDCx *XDCX) HasTradingState(block *types.Block, author common.Address) bool
- func (XDCx *XDCX) IsSDKNode() bool
- func (XDCx *XDCX) LogEpochPrice(epochNumber uint64, epochPriceResult map[common.Hash]*big.Int) error
- func (XDCx *XDCX) Overflow() bool
- func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradingstate.TradingStateDB, ...) (error, bool)
- func (XDCx *XDCX) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, ...) ([]tradingstate.TxDataMatch, map[common.Hash]tradingstate.MatchingResult)
- func (XDCx *XDCX) Protocols() []p2p.Protocol
- func (XDCx *XDCX) RollbackReorgTxMatch(txhash common.Hash) error
- func (XDCx *XDCX) SaveData()
- func (XDCx *XDCX) SetTokenDecimal(token common.Address, decimal *big.Int)
- func (XDCx *XDCX) Start(server *p2p.Server) error
- func (XDCx *XDCX) Stop() error
- func (XDCx *XDCX) SyncDataToSDKNode(takerOrderInTx *tradingstate.OrderItem, txHash common.Hash, ...) error
- func (XDCx *XDCX) UpdateMediumPriceBeforeEpoch(epochNumber uint64, tradingStateDB *tradingstate.TradingStateDB, ...) error
- func (XDCx *XDCX) UpdateOrderCache(baseToken, quoteToken common.Address, orderHash common.Hash, ...)
- func (XDCx *XDCX) Version() uint64
Constants ¶
const ( ProtocolName = "XDCx" ProtocolVersion = uint64(1) ProtocolVersionStr = "1.0" MaximumTxMatchSize = 1000 )
const (
LimitThresholdOrderNonceInQueue = 100
)
Variables ¶
var ( ErrNonceTooHigh = errors.New("nonce too high") ErrNonceTooLow = errors.New("nonce too low") )
var ( ErrNoTopics = errors.New("missing topic(s)") ErrOrderNonceTooLow = errors.New("OrderNonce too low") ErrOrderNonceTooHigh = errors.New("OrderNonce too high") )
List of errors
var DefaultConfig = Config{
DataDir: "",
}
DefaultConfig represents (shocker!) the default configuration.
Functions ¶
func DoSettleBalance ¶
func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingstate.OrderItem, settleBalance *tradingstate.SettleBalance, statedb *state.StateDB) error
func GetTradeQuantity ¶
func NewLDBEngine ¶
func NewLDBEngine(cfg *Config) *XDCxDAO.BatchDatabase
func NewMongoDBEngine ¶
func NewMongoDBEngine(cfg *Config) *XDCxDAO.MongoDatabase
Types ¶
type PublicXDCXAPI ¶
type PublicXDCXAPI struct {
// contains filtered or unexported fields
}
PublicXDCXAPI provides the XDCX RPC service that can be use publicly without security implications.
func NewPublicXDCXAPI ¶
func NewPublicXDCXAPI(t *XDCX) *PublicXDCXAPI
NewPublicXDCXAPI create a new RPC XDCX service.
type XDCX ¶
type XDCX struct { Triegc *prque.Prque // Priority queue mapping block numbers to tries to gc StateCache tradingstate.Database // State database to reuse between imports (contains state cache) *XDCx_state.TradingStateDB // contains filtered or unexported fields }
func (*XDCX) ApplyOrder ¶
func (XDCx *XDCX) ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDB *tradingstate.TradingStateDB, orderBook common.Hash, order *tradingstate.OrderItem) ([]map[string]string, []*tradingstate.OrderItem, error)
func (*XDCX) CommitOrder ¶
func (XDCx *XDCX) CommitOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDB *tradingstate.TradingStateDB, orderBook common.Hash, order *tradingstate.OrderItem) ([]map[string]string, []*tradingstate.OrderItem, error)
func (*XDCX) ConvertXDCToToken ¶
func (XDCx *XDCX) ConvertXDCToToken(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, token common.Address, quantity *big.Int) (*big.Int, *big.Int, error)
return tokenQuantity (after convert from XDC to token), tokenPriceInXDC, error
func (*XDCX) GetAveragePriceLastEpoch ¶
func (XDCx *XDCX) GetAveragePriceLastEpoch(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, baseToken common.Address, quoteToken common.Address) (*big.Int, error)
return average price of the given pair in the last epoch
func (*XDCX) GetEmptyTradingState ¶
func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error)
func (*XDCX) GetLevelDB ¶
func (*XDCX) GetMongoDB ¶
func (*XDCX) GetStateCache ¶
func (XDCx *XDCX) GetStateCache() tradingstate.Database
func (*XDCX) GetTokenDecimal ¶
func (*XDCX) GetTradingState ¶
func (XDCx *XDCX) GetTradingState(block *types.Block, author common.Address) (*tradingstate.TradingStateDB, error)
func (*XDCX) GetTradingStateRoot ¶
func (*XDCX) HasTradingState ¶
func (*XDCX) LogEpochPrice ¶
func (XDCx *XDCX) LogEpochPrice(epochNumber uint64, epochPriceResult map[common.Hash]*big.Int) error
put average price of epoch to mongodb for tracking liquidation trades epochPriceResult: a map of epoch average price, key is orderbook hash , value is epoch average price orderbook hash genereted from baseToken, quoteToken at XDPoSChain/XDCx/tradingstate/common.go:214
func (*XDCX) ProcessCancelOrder ¶
func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradingstate.TradingStateDB, statedb *state.StateDB, chain consensus.ChainContext, coinbase common.Address, orderBook common.Hash, order *tradingstate.OrderItem) (error, bool)
func (*XDCX) ProcessOrderPending ¶
func (XDCx *XDCX) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, pending map[common.Address]types.OrderTransactions, statedb *state.StateDB, XDCXstatedb *tradingstate.TradingStateDB) ([]tradingstate.TxDataMatch, map[common.Hash]tradingstate.MatchingResult)
func (*XDCX) RollbackReorgTxMatch ¶
func (*XDCX) SetTokenDecimal ¶
FIXME: using in unit tests only
func (*XDCX) SyncDataToSDKNode ¶
func (XDCx *XDCX) SyncDataToSDKNode(takerOrderInTx *tradingstate.OrderItem, txHash common.Hash, txMatchTime time.Time, statedb *state.StateDB, trades []map[string]string, rejectedOrders []*tradingstate.OrderItem, dirtyOrderCount *uint64) error
there are 3 tasks need to complete to update data in SDK nodes after matching
- txMatchData.Order: order has been processed. This order should be put to `orders` collection with status sdktypes.OrderStatusOpen
- txMatchData.Trades: includes information of matched orders. a. PutObject them to `trades` collection b. Update status of regrading orders to sdktypes.OrderStatusFilled
func (*XDCX) UpdateMediumPriceBeforeEpoch ¶
func (XDCx *XDCX) UpdateMediumPriceBeforeEpoch(epochNumber uint64, tradingStateDB *tradingstate.TradingStateDB, statedb *state.StateDB) error
func (*XDCX) UpdateOrderCache ¶
func (XDCx *XDCX) UpdateOrderCache(baseToken, quoteToken common.Address, orderHash common.Hash, txhash common.Hash, lastState tradingstate.OrderHistoryItem)
Directories ¶
Path | Synopsis |
---|---|
Package state provides a caching layer atop the Ethereum state trie.
|
Package state provides a caching layer atop the Ethereum state trie. |