OSDN Git Service

Test crossin (#213) test_vote
authorwz <mars@bytom.io>
Thu, 20 Jun 2019 08:48:58 +0000 (16:48 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 20 Jun 2019 08:48:58 +0000 (16:48 +0800)
* fix crossin

* fix review

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..f701548 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,17 @@ func CalculateTxFee(tx *types.Tx) (fee uint64) {
        fee = totalInputBTM - totalOutputBTM
        return
 }
+
+func checkGasInputIDs(tx *types.Tx) error {
+       for _, inp := range tx.Inputs {
+               switch inp.InputType() {
+               case types.CrossChainInputType:
+                       return nil
+               }
+       }
+
+       if len(tx.GasInputIDs) == 0 {
+               return ErrNoGasInput
+       }
+       return nil
+}
index 957ab6a..32d3f6d 100644 (file)
@@ -194,10 +194,15 @@ func (tp *TxPool) HaveTransaction(txHash *bc.Hash) bool {
 
 func isTransactionNoBtmInput(tx *types.Tx) bool {
        for _, input := range tx.TxData.Inputs {
+               switch input.InputType() {
+               case types.CrossChainInputType:
+                       return false
+               }
                if input.AssetID() == *consensus.BTMAssetID {
                        return false
                }
        }
+
        return true
 }