OSDN Git Service

fix
authorwz <mars@bytom.io>
Wed, 23 Oct 2019 11:38:19 +0000 (19:38 +0800)
committerwz <mars@bytom.io>
Wed, 23 Oct 2019 11:38:19 +0000 (19:38 +0800)
blockchain/txbuilder/actions.go
common/crossin_asset.go
config/genesis.go
protocol/validation/tx.go

index b88da89..7e5b951 100644 (file)
@@ -10,7 +10,6 @@ import (
        "github.com/vapor/common"
        cfg "github.com/vapor/config"
        "github.com/vapor/consensus"
-       "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/encoding/json"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -263,13 +262,11 @@ func DecodeCrossInAction(data []byte) (Action, error) {
 
 type crossInAction struct {
        bc.AssetAmount
-       SourceID            bc.Hash        `json:"source_id"`
-       SourcePos           uint64         `json:"source_pos"`
-       VMVersion           uint64         `json:"vm_version"`
-       RawDefinitionByte   json.HexBytes  `json:"raw_definition_byte"`
-       IssuanceProgram     json.HexBytes  `json:"issuance_program"`
-       OpenFederationXpubs []chainkd.XPub `json:"open_federation_xpubs"`
-       Quorum              int            `json:"quorum"`
+       SourceID          bc.Hash       `json:"source_id"`
+       SourcePos         uint64        `json:"source_pos"`
+       VMVersion         uint64        `json:"vm_version"`
+       RawDefinitionByte json.HexBytes `json:"raw_definition_byte"`
+       IssuanceProgram   json.HexBytes `json:"issuance_program"`
 }
 
 func (c *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) error {
@@ -296,18 +293,12 @@ func (c *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) err
        txin := types.NewCrossChainInput(nil, c.SourceID, *c.AssetId, c.Amount, c.SourcePos, c.VMVersion, c.RawDefinitionByte, c.IssuanceProgram)
        tplIn := &SigningInstruction{}
        fed := cfg.CommonConfig.Federation
-       isCrossChain, err := common.IsCrossChainAssetOfNoBytom(c.RawDefinitionByte)
-       if err != nil {
-               return err
-       }
 
-       if isCrossChain {
-               fed.Xpubs = c.OpenFederationXpubs
-               fed.Quorum = c.Quorum
+       if !common.IsCrossChainAssetOfNoBytom(c.RawDefinitionByte) {
+               tplIn.AddRawWitnessKeys(fed.Xpubs, cfg.FedAddressPath, fed.Quorum)
+               tplIn.AddDataWitness(cfg.FederationPMultiSigScript(fed))
        }
 
-       tplIn.AddRawWitnessKeys(fed.Xpubs, cfg.FedAddressPath, fed.Quorum)
-       tplIn.AddDataWitness(cfg.FederationPMultiSigScript(fed))
        return builder.AddInput(txin, tplIn)
 }
 
index 7fd182d..3db41db 100644 (file)
@@ -2,27 +2,24 @@ package common
 
 import (
        "encoding/json"
-       "errors"
 )
 
-func IsCrossChainAssetOfNoBytom(rawDefinitionByte []byte) (bool, error) {
+func IsCrossChainAssetOfNoBytom(rawDefinitionByte []byte) bool {
        var defMap map[string]interface{}
-       if err := json.Unmarshal(rawDefinitionByte, &defMap); err != nil {
-               return false, err
-       }
+       json.Unmarshal(rawDefinitionByte, &defMap)
 
        description, ok := defMap["description"].(map[string]interface{})
        if !ok {
-               return false, nil
+               return false
        }
 
        issueAssetAction, ok := description["issue_asset_action"].(string)
        if !ok {
-               return false, nil
+               return false
        }
 
        if issueAssetAction != "cross_chain" {
-               return false, errors.New("issueAssetAction is error")
+               return false
        }
-       return true, nil
+       return true
 }
index 85ca145..3239f5a 100644 (file)
@@ -7,7 +7,6 @@ import (
 
        "github.com/vapor/consensus"
        "github.com/vapor/crypto"
-       "github.com/vapor/crypto/ed25519"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -45,21 +44,6 @@ func FederationWScript(c *FederationConfig) []byte {
        return wscript
 }
 
-func FederationWScriptFromPubs(pubkeys []ed25519.PublicKey, quorum int) []byte {
-       program, err := vmutil.P2SPMultiSigProgram(pubkeys, quorum)
-       if err != nil {
-               log.Panicf("fail to generate federation scirpt for federation: %v", err)
-       }
-
-       scriptHash := crypto.Sha256(program)
-       wscript, err := vmutil.P2WSHProgram(scriptHash)
-       if err != nil {
-               log.Panicf("Fail converts scriptHash to witness: %v", err)
-       }
-
-       return wscript
-}
-
 func GenesisTx() *types.Tx {
        contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
        if err != nil {
index ccbe7f2..6f60b25 100644 (file)
@@ -8,7 +8,6 @@ import (
        "github.com/vapor/common"
        "github.com/vapor/config"
        "github.com/vapor/consensus"
-       "github.com/vapor/consensus/segwit"
        "github.com/vapor/errors"
        "github.com/vapor/math/checked"
        "github.com/vapor/protocol/bc"
@@ -281,17 +280,8 @@ func checkValid(vs *validationState, e bc.Entry) (err error) {
 
                code := config.FederationWScript(config.CommonConfig.Federation)
 
-               isCrossChainOfNoBytom, err := common.IsCrossChainAssetOfNoBytom(e.RawDefinitionByte)
-               if err != nil {
-                       return err
-               }
-
-               if isCrossChainOfNoBytom {
-                       pubs, required, err := segwit.GetXpubsAndRequiredFromProg(e.AssetDefinition.IssuanceProgram.Code)
-                       if err != nil {
-                               return err
-                       }
-                       code = config.FederationWScriptFromPubs(pubs, required)
+               if common.IsCrossChainAssetOfNoBytom(e.RawDefinitionByte) {
+                       code = e.AssetDefinition.IssuanceProgram.Code
                }
 
                prog := &bc.Program{