Golang implemented sidechain for Bytom
Revision | de893b48f3fc3c84d27cc79994c59305a2867b1e (tree) |
---|---|
Time | 2020-07-31 16:42:48 |
Author | shenao78 <shenao.78@163....> |
Commiter | shenao78 |
fix determine whether IsP2WMCScript
@@ -3,6 +3,7 @@ package contract | ||
3 | 3 | import ( |
4 | 4 | "encoding/hex" |
5 | 5 | |
6 | + "github.com/bytom/vapor/consensus/segwit" | |
6 | 7 | "github.com/bytom/vapor/errors" |
7 | 8 | "github.com/bytom/vapor/protocol/bc/types" |
8 | 9 | "github.com/bytom/vapor/protocol/vm" |
@@ -65,3 +66,8 @@ func FeeRate(input *types.TxInput) (int64, error) { | ||
65 | 66 | } |
66 | 67 | return 0, errors.New("invalid trade input") |
67 | 68 | } |
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 | +} |
@@ -73,7 +73,7 @@ func addMatchTxFeeOutput(txData *types.TxData, fees []*bc.AssetAmount, rewardPro | ||
73 | 73 | func (e *Engine) addReOrder(partialOrders []*common.Order, tx *types.Tx) error { |
74 | 74 | index := 0 |
75 | 75 | 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 { | |
77 | 77 | continue |
78 | 78 | } |
79 | 79 |
@@ -156,7 +156,7 @@ func (m *Core) InitChainStatus(startHash *bc.Hash) error { | ||
156 | 156 | // IsDust block the transaction that are not generated by the match engine |
157 | 157 | func (m *Core) IsDust(tx *types.Tx) bool { |
158 | 158 | for _, input := range tx.Inputs { |
159 | - if segwit.IsP2WMCScript(input.ControlProgram()) && !contract.IsCancelClauseSelector(input) { | |
159 | + if contract.IsP2WMCScript(input.ControlProgram()) && !contract.IsCancelClauseSelector(input) { | |
160 | 160 | return true |
161 | 161 | } |
162 | 162 | } |
@@ -205,7 +205,7 @@ func (m *Core) ValidateTx(tx *types.Tx, verifyResult *bc.TxVerifyResult, blockHe | ||
205 | 205 | } |
206 | 206 | |
207 | 207 | for _, output := range tx.Outputs { |
208 | - if !segwit.IsP2WMCScript(output.ControlProgram()) { | |
208 | + if !contract.IsP2WMCScript(output.ControlProgram()) { | |
209 | 209 | continue |
210 | 210 | } |
211 | 211 |
@@ -239,7 +239,7 @@ func calcFeeAmount(matchedTx *types.Tx) (map[bc.AssetID]*matchedTxFee, error) { | ||
239 | 239 | |
240 | 240 | for _, output := range matchedTx.Outputs { |
241 | 241 | 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()) { | |
243 | 243 | assetFeeMap[*assetAmount.AssetId].amount -= assetAmount.Amount |
244 | 244 | if assetFeeMap[*assetAmount.AssetId].amount <= 0 { |
245 | 245 | delete(assetFeeMap, *assetAmount.AssetId) |
@@ -255,7 +255,7 @@ func calcFeeAmount(matchedTx *types.Tx) (map[bc.AssetID]*matchedTxFee, error) { | ||
255 | 255 | |
256 | 256 | func validateCancelOrderTx(tx *types.Tx) error { |
257 | 257 | for _, input := range tx.Inputs { |
258 | - if !segwit.IsP2WMCScript(input.ControlProgram()) { | |
258 | + if !contract.IsP2WMCScript(input.ControlProgram()) { | |
259 | 259 | return errInputProgramMustP2WMCScript |
260 | 260 | } |
261 | 261 |
@@ -290,7 +290,7 @@ func validateMatchedTx(tx *types.Tx, blockHeight uint64) error { | ||
290 | 290 | fromAssetIDMap := make(map[string]bool) |
291 | 291 | toAssetIDMap := make(map[string]bool) |
292 | 292 | for i, input := range tx.Inputs { |
293 | - if !segwit.IsP2WMCScript(input.ControlProgram()) { | |
293 | + if !contract.IsP2WMCScript(input.ControlProgram()) { | |
294 | 294 | return errInputProgramMustP2WMCScript |
295 | 295 | } |
296 | 296 |
@@ -482,7 +482,7 @@ func buildOrderBook(store database.MovStore, txs []*Tx) (*match.OrderBook, error | ||
482 | 482 | func parseAddOrdersFromTx(tx *Tx) ([]*common.Order, error) { |
483 | 483 | var orders []*common.Order |
484 | 484 | 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()) { | |
486 | 486 | continue |
487 | 487 | } |
488 | 488 |
@@ -503,7 +503,7 @@ func parseAddOrdersFromTx(tx *Tx) ([]*common.Order, error) { | ||
503 | 503 | func parseDeleteOrdersFromTx(tx *types.Tx) ([]*common.Order, error) { |
504 | 504 | var orders []*common.Order |
505 | 505 | 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()) { | |
507 | 507 | continue |
508 | 508 | } |
509 | 509 |