OSDN Git Service

fix(bc): fix TxInput.SpentOutputID() (#242)
[bytom/vapor.git] / protocol / txpool.go
index 7d6bf9f..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
 }
 
@@ -277,12 +282,21 @@ func (tp *TxPool) addTransaction(txD *TxDesc) error {
        txD.Added = time.Now()
        tp.pool[tx.ID] = txD
        for _, id := range tx.ResultIds {
-               output, err := tx.IntraChainOutput(*id)
+               var assetID bc.AssetID
+               outputEntry, err := tx.Entry(*id)
                if err != nil {
-                       // error due to it's a retirement, utxo doesn't care this output type so skip it
+                       return err
+               }
+               switch output := outputEntry.(type) {
+               case *bc.IntraChainOutput:
+                       assetID = *output.Source.Value.AssetId
+               case *bc.VoteOutput:
+                       assetID = *output.Source.Value.AssetId
+               default:
                        continue
                }
-               if !txD.StatusFail || *output.Source.Value.AssetId == *consensus.BTMAssetID {
+
+               if !txD.StatusFail || assetID == *consensus.BTMAssetID {
                        tp.utxo[*id] = tx
                }
        }