• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版7702f5fd3bcf7b5ac4751792b0c5d31c42d135b9 (tree)
时间2019-11-05 17:50:39
作者Paladz <yzhu101@uott...>
CommiterGitHub

Log Message

Merge branch 'mov' into check_mov_store

更改概述

差异

--- a/application/mov/match/match.go
+++ b/application/mov/match/match.go
@@ -35,28 +35,18 @@ func (e *Engine) HasMatchedTx(tradePairs ...*common.TradePair) bool {
3535 return false
3636 }
3737
38- for i, order := range orders {
39- if canNotBeMatched(order, orders[getOppositeIndex(len(orders), i)]) {
40- return false
41- }
42- }
43- return true
38+ return isMatched(orders)
4439 }
4540
4641 // NextMatchedTx return the next matchable transaction by the specified trade pairs
4742 // the size of trade pairs at least 2, and the sequence of trade pairs can form a loop
4843 // for example, [assetA -> assetB, assetB -> assetC, assetC -> assetA]
4944 func (e *Engine) NextMatchedTx(tradePairs ...*common.TradePair) (*types.Tx, error) {
50- if err := validateTradePairs(tradePairs); err != nil {
51- return nil, err
52- }
53-
54- orders := e.peekOrders(tradePairs)
55- if len(orders) == 0 {
56- return nil, errors.New("no order for the specified trade pair in the order table")
45+ if !e.HasMatchedTx(tradePairs...) {
46+ return nil, errors.New("the specified trade pairs can not be matched")
5747 }
5848
59- tx, err := e.buildMatchTx(orders)
49+ tx, err := e.buildMatchTx(e.peekOrders(tradePairs))
6050 if err != nil {
6151 return nil, err
6252 }
@@ -98,9 +88,14 @@ func validateTradePairs(tradePairs []*common.TradePair) error {
9888 return nil
9989 }
10090
101-func canNotBeMatched(order, oppositeOrder *common.Order) bool {
102- rate := 1 / order.Rate
103- return rate < oppositeOrder.Rate
91+func isMatched(orders []*common.Order) bool {
92+ for i, order := range orders {
93+ opposisteOrder := orders[getOppositeIndex(len(orders), i)]
94+ if 1 / order.Rate < opposisteOrder.Rate {
95+ return false
96+ }
97+ }
98+ return true
10499 }
105100
106101 func (e *Engine) buildMatchTx(orders []*common.Order) (*types.Tx, error) {
Show on old repository browser