// MovStore is the interface for mov's persistent storage
type MovStore interface {
+ Clear()
GetMovDatabaseState() (*common.MovDatabaseState, error)
InitDBState(height uint64, hash *bc.Hash) error
ListOrders(orderAfter *common.Order) ([]*common.Order, error)
return &LevelDBMovStore{db: db}
}
+// Clear will clear all the data of store
+func (m *LevelDBMovStore) Clear() {
+ batch := m.db.NewBatch()
+
+ iter := m.db.Iterator()
+ defer iter.Release()
+
+ for iter.Next() {
+ batch.Delete(iter.Key())
+ }
+ batch.Write()
+}
+
// GetMovDatabaseState return the current DB's image status
func (m *LevelDBMovStore) GetMovDatabaseState() (*common.MovDatabaseState, error) {
if value := m.db.Get(bestMatchStore); value != nil {
// ApplyBlock parse pending order and cancel from the the transactions of block
// and add pending order to the dex db, remove cancel order from dex db.
func (m *Core) ApplyBlock(block *types.Block) error {
- if block.Height <= m.startBlockHeight {
+ if block.Height < m.startBlockHeight {
return nil
}
+ if block.Height == m.startBlockHeight {
+ blockHash := block.Hash()
+ return m.InitChainStatus(&blockHash)
+ }
+
if err := m.validateMatchedTxSequence(block.Transactions); err != nil {
return err
}
return nil
}
+ if block.Height == m.startBlockHeight {
+ m.movStore.Clear()
+ return nil
+ }
+
deleteOrders, addOrders, err := decodeTxsOrders(block.Transactions)
if err != nil {
return err