• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版f058ca00db77b3172aa57040570bd6b2fcd18062 (tree)
时间2019-11-25 12:31:21
作者Paladz <yzhu101@uott...>
CommiterGitHub

Log Message

Merge branch 'mov' into edit_time_limit

更改概述

差异

--- 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
--- a/blockchain/txbuilder/actions.go
+++ b/blockchain/txbuilder/actions.go
@@ -156,8 +156,8 @@ type crossOutAction struct {
156156
157157 func (a *crossOutAction) Build(ctx context.Context, b *TemplateBuilder) error {
158158 var missing []string
159- if a.Address == "" {
160- missing = append(missing, "address")
159+ if a.Address == "" && len(a.Program) == 0 {
160+ missing = append(missing, "address or program")
161161 }
162162 if a.AssetId.IsZero() {
163163 missing = append(missing, "asset_id")
--- a/protocol/tx.go
+++ b/protocol/tx.go
@@ -49,6 +49,14 @@ func (c *Chain) validateTx(tx *types.Tx, bh *types.BlockHeader) (bool, error) {
4949 return false, err
5050 }
5151
52+ txVerifyResult := &bc.TxVerifyResult{StatusFail: err != nil}
53+ for _, p := range c.subProtocols {
54+ if err := p.ValidateTx(tx, txVerifyResult); err != nil {
55+ c.txPool.AddErrCache(&tx.ID, err)
56+ return false, err
57+ }
58+ }
59+
5260 if err != nil {
5361 log.WithFields(log.Fields{"module": logModule, "tx_id": tx.Tx.ID.String(), "error": err}).Info("transaction status fail")
5462 }
Show on old repository browser