OSDN Git Service

fix: add CrossChainInput in NewTxVMContext (#124)
[bytom/vapor.git] / protocol / validation / vmcontext.go
index 356dc7c..10b77d8 100644 (file)
@@ -25,20 +25,30 @@ func NewTxVMContext(vs *validationState, entry bc.Entry, prog *bc.Program, args
        )
 
        switch e := entry.(type) {
-       case *bc.Issuance:
+       case *bc.CrossChainInput:
                a1 := e.Value.AssetId.Bytes()
                assetID = &a1
                amount = &e.Value.Amount
                destPos = &e.WitnessDestination.Position
 
        case *bc.Spend:
-               spentOutput := tx.Entries[*e.SpentOutputId].(*bc.IntraChainOutput)
-               a1 := spentOutput.Source.Value.AssetId.Bytes()
-               assetID = &a1
-               amount = &spentOutput.Source.Value.Amount
-               destPos = &e.WitnessDestination.Position
-               s := e.SpentOutputId.Bytes()
-               spentOutputID = &s
+               switch spentOutput := tx.Entries[*e.SpentOutputId].(type) {
+               case *bc.IntraChainOutput:
+                       a1 := spentOutput.Source.Value.AssetId.Bytes()
+                       assetID = &a1
+                       amount = &spentOutput.Source.Value.Amount
+                       destPos = &e.WitnessDestination.Position
+                       s := e.SpentOutputId.Bytes()
+                       spentOutputID = &s
+
+               case *bc.VoteOutput:
+                       a1 := spentOutput.Source.Value.AssetId.Bytes()
+                       assetID = &a1
+                       amount = &spentOutput.Source.Value.Amount
+                       destPos = &e.WitnessDestination.Position
+                       s := e.SpentOutputId.Bytes()
+                       spentOutputID = &s
+               }
        }
 
        var txSigHash *[]byte
@@ -116,6 +126,9 @@ func (ec *entryContext) checkOutput(index uint64, amount uint64, assetID []byte,
                case *bc.IntraChainOutput:
                        return check(e.ControlProgram, e.Source.Value), nil
 
+               case *bc.VoteOutput:
+                       return check(e.ControlProgram, e.Source.Value), nil
+
                case *bc.Retirement:
                        var prog bc.Program
                        if expansion {
@@ -148,19 +161,6 @@ func (ec *entryContext) checkOutput(index uint64, amount uint64, assetID []byte,
        case *bc.Mux:
                return checkMux(e)
 
-       case *bc.Issuance:
-               d, ok := ec.entries[*e.WitnessDestination.Ref]
-               if !ok {
-                       return false, errors.Wrapf(bc.ErrMissingEntry, "entry for issuance destination %x not found", e.WitnessDestination.Ref.Bytes())
-               }
-               if m, ok := d.(*bc.Mux); ok {
-                       return checkMux(m)
-               }
-               if index != 0 {
-                       return false, errors.Wrapf(vm.ErrBadValue, "index %d >= 1", index)
-               }
-               return checkEntry(d)
-
        case *bc.Spend:
                d, ok := ec.entries[*e.WitnessDestination.Ref]
                if !ok {