• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版655389ae9e70b7383db6c95440e92f38e5815b80 (tree)
时间2019-11-25 11:33:06
作者shenao78 <shenao.78@163....>
Commitershenao78

Log Message

fix request amount zero

更改概述

差异

--- a/application/mov/match/match.go
+++ b/application/mov/match/match.go
@@ -185,7 +185,7 @@ func CalcMatchedTxFee(txData *types.TxData, maxFeeRate float64) (map[bc.AssetID]
185185 }
186186
187187 oppositeAmount := uint64(assetFeeMap[contractArgs.RequestedAsset].FeeAmount)
188- receiveAmount := vprMath.MinUint64(calcRequestAmount(input.Amount(), contractArgs), oppositeAmount)
188+ receiveAmount := vprMath.MinUint64(CalcRequestAmount(input.Amount(), contractArgs), oppositeAmount)
189189 assetFeeMap[input.AssetID()].MaxFeeAmount = calcMaxFeeAmount(calcShouldPayAmount(receiveAmount, contractArgs), maxFeeRate)
190190 }
191191
@@ -207,7 +207,7 @@ func addMatchTxOutput(txData *types.TxData, txInput *types.TxInput, order *commo
207207 return err
208208 }
209209
210- requestAmount := calcRequestAmount(order.Utxo.Amount, contractArgs)
210+ requestAmount := CalcRequestAmount(order.Utxo.Amount, contractArgs)
211211 receiveAmount := vprMath.MinUint64(requestAmount, oppositeAmount)
212212 shouldPayAmount := calcShouldPayAmount(receiveAmount, contractArgs)
213213 isPartialTrade := requestAmount > receiveAmount
@@ -220,7 +220,7 @@ func addMatchTxOutput(txData *types.TxData, txInput *types.TxInput, order *commo
220220 return nil
221221 }
222222
223-func calcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 {
223+func CalcRequestAmount(fromAmount uint64, contractArg *vmutil.MagneticContractArgs) uint64 {
224224 return uint64(int64(fromAmount) * contractArg.RatioNumerator / contractArg.RatioDenominator)
225225 }
226226
--- a/application/mov/mov_core.go
+++ b/application/mov/mov_core.go
@@ -27,6 +27,7 @@ var (
2727 errNumeratorOfRatioIsOverflow = errors.New("ratio numerator of contract args product input amount is overflow")
2828 errLengthOfInputIsIncorrect = errors.New("length of matched tx input is not equals to actual matched tx input")
2929 errSpendOutputIDIsIncorrect = errors.New("spend output id of matched tx is not equals to actual matched tx")
30+ errRequestAmountLessThenOne = errors.New("request amount of order less than one")
3031 )
3132
3233 // MovCore represent the core logic of the match module, which include generate match transactions before packing the block,
@@ -222,7 +223,7 @@ func validateCancelOrderTx(tx *types.Tx, verifyResult *bc.TxVerifyResult) error
222223 return nil
223224 }
224225
225-func validateMagneticContractArgs(inputAmount uint64, program []byte) error {
226+func validateMagneticContractArgs(fromAmount uint64, program []byte) error {
226227 contractArgs, err := segwit.DecodeP2WMCProgram(program)
227228 if err != nil {
228229 return err
@@ -232,9 +233,13 @@ func validateMagneticContractArgs(inputAmount uint64, program []byte) error {
232233 return errRatioOfTradeLessThanZero
233234 }
234235
235- if _, ok := checked.MulInt64(int64(inputAmount), contractArgs.RatioNumerator); !ok {
236+ if _, ok := checked.MulInt64(int64(fromAmount), contractArgs.RatioNumerator); !ok {
236237 return errNumeratorOfRatioIsOverflow
237238 }
239+
240+ if match.CalcRequestAmount(fromAmount, contractArgs) < 1 {
241+ return errRequestAmountLessThenOne
242+ }
238243 return nil
239244 }
240245
Show on old repository browser