• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Révisionde893b48f3fc3c84d27cc79994c59305a2867b1e (tree)
l'heure2020-07-31 16:42:48
Auteurshenao78 <shenao.78@163....>
Commitershenao78

Message de Log

fix determine whether IsP2WMCScript

Change Summary

Modification

--- a/application/mov/contract/contract.go
+++ b/application/mov/contract/contract.go
@@ -3,6 +3,7 @@ package contract
33 import (
44 "encoding/hex"
55
6+ "github.com/bytom/vapor/consensus/segwit"
67 "github.com/bytom/vapor/errors"
78 "github.com/bytom/vapor/protocol/bc/types"
89 "github.com/bytom/vapor/protocol/vm"
@@ -65,3 +66,8 @@ func FeeRate(input *types.TxInput) (int64, error) {
6566 }
6667 return 0, errors.New("invalid trade input")
6768 }
69+
70+// IsP2WMCScript is used to determine whether it is the v1 or v2 P2WMC script or not
71+func IsP2WMCScript(prog []byte) bool {
72+ return segwit.IsP2WMCScriptV2(prog) || segwit.IsP2WMCScript(prog)
73+}
--- a/application/mov/match/engine.go
+++ b/application/mov/match/engine.go
@@ -73,7 +73,7 @@ func addMatchTxFeeOutput(txData *types.TxData, fees []*bc.AssetAmount, rewardPro
7373 func (e *Engine) addReOrder(partialOrders []*common.Order, tx *types.Tx) error {
7474 index := 0
7575 for i, output := range tx.Outputs {
76- if !segwit.IsP2WMCScript(output.ControlProgram()) || output.AssetAmount().Amount == 0 {
76+ if !contract.IsP2WMCScript(output.ControlProgram()) || output.AssetAmount().Amount == 0 {
7777 continue
7878 }
7979
--- a/application/mov/mov_core.go
+++ b/application/mov/mov_core.go
@@ -156,7 +156,7 @@ func (m *Core) InitChainStatus(startHash *bc.Hash) error {
156156 // IsDust block the transaction that are not generated by the match engine
157157 func (m *Core) IsDust(tx *types.Tx) bool {
158158 for _, input := range tx.Inputs {
159- if segwit.IsP2WMCScript(input.ControlProgram()) && !contract.IsCancelClauseSelector(input) {
159+ if contract.IsP2WMCScript(input.ControlProgram()) && !contract.IsCancelClauseSelector(input) {
160160 return true
161161 }
162162 }
@@ -205,7 +205,7 @@ func (m *Core) ValidateTx(tx *types.Tx, verifyResult *bc.TxVerifyResult, blockHe
205205 }
206206
207207 for _, output := range tx.Outputs {
208- if !segwit.IsP2WMCScript(output.ControlProgram()) {
208+ if !contract.IsP2WMCScript(output.ControlProgram()) {
209209 continue
210210 }
211211
@@ -239,7 +239,7 @@ func calcFeeAmount(matchedTx *types.Tx) (map[bc.AssetID]*matchedTxFee, error) {
239239
240240 for _, output := range matchedTx.Outputs {
241241 assetAmount := output.AssetAmount()
242- if _, ok := dealProgMaps[hex.EncodeToString(output.ControlProgram())]; ok || segwit.IsP2WMCScript(output.ControlProgram()) {
242+ if _, ok := dealProgMaps[hex.EncodeToString(output.ControlProgram())]; ok || contract.IsP2WMCScript(output.ControlProgram()) {
243243 assetFeeMap[*assetAmount.AssetId].amount -= assetAmount.Amount
244244 if assetFeeMap[*assetAmount.AssetId].amount <= 0 {
245245 delete(assetFeeMap, *assetAmount.AssetId)
@@ -255,7 +255,7 @@ func calcFeeAmount(matchedTx *types.Tx) (map[bc.AssetID]*matchedTxFee, error) {
255255
256256 func validateCancelOrderTx(tx *types.Tx) error {
257257 for _, input := range tx.Inputs {
258- if !segwit.IsP2WMCScript(input.ControlProgram()) {
258+ if !contract.IsP2WMCScript(input.ControlProgram()) {
259259 return errInputProgramMustP2WMCScript
260260 }
261261
@@ -290,7 +290,7 @@ func validateMatchedTx(tx *types.Tx, blockHeight uint64) error {
290290 fromAssetIDMap := make(map[string]bool)
291291 toAssetIDMap := make(map[string]bool)
292292 for i, input := range tx.Inputs {
293- if !segwit.IsP2WMCScript(input.ControlProgram()) {
293+ if !contract.IsP2WMCScript(input.ControlProgram()) {
294294 return errInputProgramMustP2WMCScript
295295 }
296296
@@ -482,7 +482,7 @@ func buildOrderBook(store database.MovStore, txs []*Tx) (*match.OrderBook, error
482482 func parseAddOrdersFromTx(tx *Tx) ([]*common.Order, error) {
483483 var orders []*common.Order
484484 for i, output := range tx.rawTx.Outputs {
485- if output.OutputType() != types.IntraChainOutputType || !segwit.IsP2WMCScript(output.ControlProgram()) {
485+ if output.OutputType() != types.IntraChainOutputType || !contract.IsP2WMCScript(output.ControlProgram()) {
486486 continue
487487 }
488488
@@ -503,7 +503,7 @@ func parseAddOrdersFromTx(tx *Tx) ([]*common.Order, error) {
503503 func parseDeleteOrdersFromTx(tx *types.Tx) ([]*common.Order, error) {
504504 var orders []*common.Order
505505 for i, input := range tx.Inputs {
506- if input.InputType() != types.SpendInputType || !segwit.IsP2WMCScript(input.ControlProgram()) {
506+ if input.InputType() != types.SpendInputType || !contract.IsP2WMCScript(input.ControlProgram()) {
507507 continue
508508 }
509509
Afficher sur ancien navigateur de dépôt.