X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=application%2Fmov%2Fmatch%2Fmatch.go;fp=application%2Fmov%2Fmatch%2Fmatch.go;h=64ed4e8c0a8ad3652ed875f6a7c7478a60b00951;hb=7e590629dcf769af5440edb07b8056b570721f2e;hp=845c2283bc4b015db25b839290c7ececd910df83;hpb=490657e3ff777e73bc834e0ba4003982f95117d0;p=bytom%2Fvapor.git diff --git a/application/mov/match/match.go b/application/mov/match/match.go index 845c2283..64ed4e8c 100644 --- a/application/mov/match/match.go +++ b/application/mov/match/match.go @@ -208,6 +208,7 @@ func addMatchTxOutput(txData *types.TxData, txInput *types.TxInput, order *commo return nil } +// CalcRequestAmount is from amount * numerator / ratioDenominator func CalcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 { res := big.NewInt(0).SetUint64(fromAmount) res.Mul(res, big.NewInt(contractArg.RatioNumerator)).Quo(res, big.NewInt(contractArg.RatioDenominator)) @@ -234,6 +235,7 @@ func calcOppositeIndex(size int, selfIdx int) int { return (selfIdx + 1) % size } +// IsMatched check does the orders can be exchange func IsMatched(orders []*common.Order) bool { sortedOrders := sortOrders(orders) if len(sortedOrders) == 0 { @@ -283,6 +285,10 @@ func validateTradePairs(tradePairs []*common.TradePair) error { } func sortOrders(orders []*common.Order) []*common.Order { + if len(orders) == 0 { + return nil + } + orderMap := make(map[bc.AssetID]*common.Order) firstOrder := orders[0] for i := 1; i < len(orders); i++ {