From: Poseidon Date: Wed, 27 Nov 2019 07:25:05 +0000 (+0800) Subject: fix mov should pay amount (#453) X-Git-Tag: v1.0.5~6 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0c5bf5c10b0d8291f4d46e220afd0d4fdd09d134;p=bytom%2Fvapor.git fix mov should pay amount (#453) * fix mov should pay amount * opt code --- diff --git a/application/mov/match/match.go b/application/mov/match/match.go index ef8b2419..8feab6ac 100644 --- a/application/mov/match/match.go +++ b/application/mov/match/match.go @@ -223,7 +223,7 @@ func addMatchTxOutput(txData *types.TxData, txInput *types.TxInput, order *commo func CalcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 { res := big.NewInt(0).SetUint64(fromAmount) - res.Mul(res, big.NewInt(contractArg.RatioNumerator)).Div(res, big.NewInt(contractArg.RatioDenominator)) + res.Mul(res, big.NewInt(contractArg.RatioNumerator)).Quo(res, big.NewInt(contractArg.RatioDenominator)) if !res.IsUint64() { return 0 } @@ -231,7 +231,12 @@ func CalcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractAr } func calcShouldPayAmount(receiveAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 { - return uint64(math.Floor(float64(receiveAmount) * float64(contractArg.RatioDenominator) / float64(contractArg.RatioNumerator))) + res := big.NewInt(0).SetUint64(receiveAmount) + res.Mul(res, big.NewInt(contractArg.RatioDenominator)).Quo(res, big.NewInt(contractArg.RatioNumerator)) + if !res.IsUint64() { + return 0 + } + return res.Uint64() } func calcMaxFeeAmount(shouldPayAmount uint64, maxFeeRate float64) int64 { @@ -244,7 +249,7 @@ func calcOppositeIndex(size int, selfIdx int) int { func isMatched(orders []*common.Order) bool { for i, order := range orders { - if opposisteOrder := orders[calcOppositeIndex(len(orders), i)]; 1/order.Rate < opposisteOrder.Rate { + if oppositeOrder := orders[calcOppositeIndex(len(orders), i)]; 1/order.Rate < oppositeOrder.Rate { return false } } diff --git a/protocol/vm/numeric.go b/protocol/vm/numeric.go index f74290f0..e95a3dd8 100644 --- a/protocol/vm/numeric.go +++ b/protocol/vm/numeric.go @@ -484,7 +484,7 @@ func opMulFraction(vm *virtualMachine) error { } res := big.NewInt(x) - res.Mul(res, big.NewInt(y)).Div(res, big.NewInt(z)) + res.Mul(res, big.NewInt(y)).Quo(res, big.NewInt(z)) if !res.IsInt64() { return ErrRange }