• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版a301cbdb6367225c19069cc4c3589bda9051c5a1 (tree)
时间2019-11-01 11:19:57
作者shenao78 <shenao.78@163....>
Commitershenao78

Log Message

rename

更改概述

差异

--- a/application/mov/match/order_table.go
+++ b/application/mov/match/order_table.go
@@ -9,48 +9,50 @@ import (
99 )
1010
1111 type OrderTable struct {
12- movStore database.MovStore
13- orderMap map[string][]*common.Order
14- iteratorMap map[string]*database.OrderIterator
15-
16- // tradePair -> []order
17- extraAddOrderMap map[string][]*common.Order
12+ movStore database.MovStore
13+ // key of tradePair -> []order
14+ dbOrders map[string][]*common.Order
15+ // key of tradePair -> iterator
16+ orderIterators map[string]*database.OrderIterator
17+
18+ // key of tradePair -> []order
19+ arrivalAddOrders map[string][]*common.Order
1820 // key of order -> order
19- extraDelOrderMap map[string]*common.Order
21+ arrivalDelOrders map[string]*common.Order
2022 }
2123
22-func NewOrderTable(movStore database.MovStore, extraAddOrders, extraDelOrders []*common.Order) *OrderTable {
24+func NewOrderTable(movStore database.MovStore, arrivalAddOrders, arrivalDelOrders []*common.Order) *OrderTable {
2325 return &OrderTable{
24- movStore: movStore,
25- orderMap: make(map[string][]*common.Order),
26- iteratorMap: make(map[string]*database.OrderIterator),
26+ movStore: movStore,
27+ dbOrders: make(map[string][]*common.Order),
28+ orderIterators: make(map[string]*database.OrderIterator),
2729
28- extraAddOrderMap: arrangeExtraAddOrders(extraAddOrders),
29- extraDelOrderMap: arrangeExtraDelOrders(extraDelOrders),
30+ arrivalAddOrders: arrangeArrivalAddOrders(arrivalAddOrders),
31+ arrivalDelOrders: arrangeArrivalDelOrders(arrivalDelOrders),
3032 }
3133 }
3234
3335 func (o *OrderTable) PeekOrder(tradePair *common.TradePair) *common.Order {
34- if len(o.orderMap[tradePair.Key()]) == 0 {
35- o.extendOrders(tradePair)
36+ if len(o.dbOrders[tradePair.Key()]) == 0 {
37+ o.extendDBOrders(tradePair)
3638 }
3739
3840 var nextOrder *common.Order
3941
40- orders := o.orderMap[tradePair.Key()]
42+ orders := o.dbOrders[tradePair.Key()]
4143 if len(orders) != 0 {
4244 nextOrder = orders[len(orders) - 1]
4345 }
4446
45- if nextOrder != nil && o.extraDelOrderMap[nextOrder.Key()] != nil {
46- o.orderMap[tradePair.Key()] = orders[0 : len(orders)-1]
47- delete(o.extraDelOrderMap, nextOrder.Key())
47+ if nextOrder != nil && o.arrivalDelOrders[nextOrder.Key()] != nil {
48+ o.dbOrders[tradePair.Key()] = orders[0 : len(orders)-1]
49+ delete(o.arrivalDelOrders, nextOrder.Key())
4850 return o.PeekOrder(tradePair)
4951 }
5052
51- extraOrder := o.peekExtraOrder(tradePair)
52- if nextOrder == nil || (extraOrder != nil && extraOrder.Rate < nextOrder.Rate) {
53- nextOrder = extraOrder
53+ arrivalOrder := o.peekArrivalOrder(tradePair)
54+ if nextOrder == nil || (arrivalOrder != nil && arrivalOrder.Rate < nextOrder.Rate) {
55+ nextOrder = arrivalOrder
5456 }
5557 return nextOrder
5658 }
@@ -61,65 +63,65 @@ func (o *OrderTable) PopOrder(tradePair *common.TradePair) {
6163 return
6264 }
6365
64- orders := o.orderMap[tradePair.Key()]
66+ orders := o.dbOrders[tradePair.Key()]
6567 if len(orders) != 0 && orders[len(orders) - 1].Key() == order.Key() {
66- o.orderMap[tradePair.Key()] = orders[0 : len(orders)-1]
68+ o.dbOrders[tradePair.Key()] = orders[0 : len(orders)-1]
6769 }
6870
69- extraOrders := o.extraAddOrderMap[tradePair.Key()]
70- if len(extraOrders) != 0 && orders[len(extraOrders) - 1].Key() == order.Key() {
71- o.extraAddOrderMap[tradePair.Key()] = extraOrders[0 : len(extraOrders)-1]
71+ arrivalOrders := o.arrivalAddOrders[tradePair.Key()]
72+ if len(arrivalOrders) != 0 && orders[len(arrivalOrders) - 1].Key() == order.Key() {
73+ o.arrivalAddOrders[tradePair.Key()] = arrivalOrders[0 : len(arrivalOrders)-1]
7274 }
7375 }
7476
7577 func (o *OrderTable) AddOrder(order *common.Order) error {
7678 tradePair := order.GetTradePair()
77- orders := o.orderMap[tradePair.Key()]
79+ orders := o.dbOrders[tradePair.Key()]
7880 if len(orders) > 0 && order.Rate > orders[len(orders)-1].Rate {
7981 return errors.New("rate of order must less than the min order in order table")
8082 }
8183
82- o.orderMap[tradePair.Key()] = append(orders, order)
84+ o.dbOrders[tradePair.Key()] = append(orders, order)
8385 return nil
8486 }
8587
86-func (o *OrderTable) extendOrders(tradePair *common.TradePair) {
87- iterator, ok := o.iteratorMap[tradePair.Key()]
88+func (o *OrderTable) extendDBOrders(tradePair *common.TradePair) {
89+ iterator, ok := o.orderIterators[tradePair.Key()]
8890 if !ok {
8991 iterator = database.NewOrderIterator(o.movStore, tradePair)
90- o.iteratorMap[tradePair.Key()] = iterator
92+ o.orderIterators[tradePair.Key()] = iterator
9193 }
9294
9395 nextOrders := iterator.NextBatch()
9496 for i := len(nextOrders) - 1; i >= 0; i-- {
95- o.orderMap[tradePair.Key()] = append(o.orderMap[tradePair.Key()], nextOrders[i])
97+ o.dbOrders[tradePair.Key()] = append(o.dbOrders[tradePair.Key()], nextOrders[i])
9698 }
9799 }
98100
99-func (o *OrderTable) peekExtraOrder(tradePair *common.TradePair) *common.Order {
100- extraAddOrders := o.extraAddOrderMap[tradePair.Key()]
101- if len(extraAddOrders) > 0 {
102- return extraAddOrders[len(extraAddOrders) -1]
101+func (o *OrderTable) peekArrivalOrder(tradePair *common.TradePair) *common.Order {
102+ arrivalAddOrders := o.arrivalAddOrders[tradePair.Key()]
103+ if len(arrivalAddOrders) > 0 {
104+ return arrivalAddOrders[len(arrivalAddOrders) -1]
103105 }
104106 return nil
105107 }
106108
107-func arrangeExtraAddOrders(orders []*common.Order) map[string][]*common.Order {
108- extraAddOrderMap := make(map[string][]*common.Order)
109+func arrangeArrivalAddOrders(orders []*common.Order) map[string][]*common.Order {
110+ arrivalAddOrderMap := make(map[string][]*common.Order)
109111 for _, order := range orders {
110- extraAddOrderMap[order.Key()] = append(extraAddOrderMap[order.Key()], order)
112+ arrivalAddOrderMap[order.Key()] = append(arrivalAddOrderMap[order.Key()], order)
111113 }
112114
113- for _, orders := range extraAddOrderMap {
115+ for _, orders := range arrivalAddOrderMap {
114116 sort.Sort(common.OrderSlice(orders))
115117 }
116- return extraAddOrderMap
118+ return arrivalAddOrderMap
117119 }
118120
119-func arrangeExtraDelOrders(orders []*common.Order) map[string]*common.Order {
120- extraDelOrderMap := make(map[string]*common.Order)
121+func arrangeArrivalDelOrders(orders []*common.Order) map[string]*common.Order {
122+ arrivalDelOrderMap := make(map[string]*common.Order)
121123 for _, order := range orders {
122- extraDelOrderMap[order.Key()] = order
124+ arrivalDelOrderMap[order.Key()] = order
123125 }
124- return extraDelOrderMap
126+ return arrivalDelOrderMap
125127 }
--- a/application/mov/mov_core.go
+++ b/application/mov/mov_core.go
@@ -357,7 +357,7 @@ func buildOrderTable(store database.MovStore, txs []*types.Tx) (*match.OrderTabl
357357 }
358358 }
359359
360- var extraAddOrders, extraDelOrders []*common.Order
360+ var arrivalAddOrders, arrivalDelOrders []*common.Order
361361 for _, tx := range nonMatchedTxs {
362362 addOrders, err := getAddOrdersFromTx(tx)
363363 if err != nil {
@@ -369,11 +369,11 @@ func buildOrderTable(store database.MovStore, txs []*types.Tx) (*match.OrderTabl
369369 return nil, err
370370 }
371371
372- extraAddOrders = append(extraAddOrders, addOrders...)
373- extraDelOrders = append(extraDelOrders, delOrders...)
372+ arrivalAddOrders = append(arrivalAddOrders, addOrders...)
373+ arrivalDelOrders = append(arrivalDelOrders, delOrders...)
374374 }
375375
376- return match.NewOrderTable(store, extraAddOrders, extraDelOrders), nil
376+ return match.NewOrderTable(store, arrivalAddOrders, arrivalDelOrders), nil
377377 }
378378
379379 // IsDust block the transaction that are not generated by the match engine
Show on old repository browser