OSDN Git Service

fix crossin
authormars <mars@bytom.io>
Thu, 20 Jun 2019 07:30:02 +0000 (15:30 +0800)
committermars <mars@bytom.io>
Thu, 20 Jun 2019 07:30:02 +0000 (15:30 +0800)
blockchain/txbuilder/actions.go
blockchain/txbuilder/finalize.go
protocol/txpool.go

index 1ca9379..e7320f5 100644 (file)
@@ -262,11 +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 []byte  `json:"raw_definition_byte"`
-       IssuanceProgram   []byte  `json:"issuance_program"`
+       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 (a *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) error {
index b9e85bb..bd43f14 100644 (file)
@@ -39,8 +39,8 @@ func FinalizeTx(ctx context.Context, c *protocol.Chain, tx *types.Tx) error {
                return err
        }
 
-       if len(tx.GasInputIDs) == 0 {
-               return ErrNoGasInput
+       if err := checkGasInputIDs(tx); err != nil {
+               return err
        }
 
        // This part is use for prevent tx size  is 0
@@ -151,3 +151,18 @@ func CalculateTxFee(tx *types.Tx) (fee uint64) {
        fee = totalInputBTM - totalOutputBTM
        return
 }
+
+func checkGasInputIDs(tx *types.Tx) error {
+       crossChainInputNum := 0
+       for _, inp := range tx.Inputs {
+               switch inp.InputType() {
+               case types.CrossChainInputType:
+                       crossChainInputNum++
+               }
+       }
+
+       if crossChainInputNum != len(tx.Inputs) && len(tx.GasInputIDs) == 0 {
+               return ErrNoGasInput
+       }
+       return nil
+}
index 957ab6a..e55c2a2 100644 (file)
@@ -193,10 +193,18 @@ func (tp *TxPool) HaveTransaction(txHash *bc.Hash) bool {
 }
 
 func isTransactionNoBtmInput(tx *types.Tx) bool {
+       crossChainInputNum := 0
        for _, input := range tx.TxData.Inputs {
                if input.AssetID() == *consensus.BTMAssetID {
                        return false
                }
+               switch input.InputType() {
+               case types.CrossChainInputType:
+                       crossChainInputNum++
+               }
+       }
+       if crossChainInputNum == len(tx.TxData.Inputs) {
+               return false
        }
        return true
 }