X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fvalidation%2Fvmcontext.go;h=16dd185dd3e817907826debd126e4fb4f7293cfb;hp=c817bc6f66cfd91a1ff8fede1dfcf0f7327f2675;hb=78ef45d4238457b2ad498d738db5a7a7a30df167;hpb=08281341c2cb02ba11d4218576256688854790fc diff --git a/protocol/validation/vmcontext.go b/protocol/validation/vmcontext.go index c817bc6f..16dd185d 100644 --- a/protocol/validation/vmcontext.go +++ b/protocol/validation/vmcontext.go @@ -3,11 +3,11 @@ package validation import ( "bytes" - "github.com/vapor/consensus/segwit" - "github.com/vapor/crypto/sha3pool" - "github.com/vapor/errors" - "github.com/vapor/protocol/bc" - "github.com/vapor/protocol/vm" + "github.com/bytom/vapor/consensus/segwit" + "github.com/bytom/vapor/crypto/sha3pool" + "github.com/bytom/vapor/errors" + "github.com/bytom/vapor/protocol/bc" + "github.com/bytom/vapor/protocol/vm" ) // NewTxVMContext generates the vm.Context for BVM @@ -25,20 +25,32 @@ func NewTxVMContext(vs *validationState, entry bc.Entry, prog *bc.Program, args ) switch e := entry.(type) { - case *bc.Issuance: - a1 := e.Value.AssetId.Bytes() + case *bc.CrossChainInput: + mainchainOutput := tx.Entries[*e.MainchainOutputId].(*bc.IntraChainOutput) + a1 := mainchainOutput.Source.Value.AssetId.Bytes() assetID = &a1 - amount = &e.Value.Amount + amount = &mainchainOutput.Source.Value.Amount destPos = &e.WitnessDestination.Position + s := e.MainchainOutputId.Bytes() + spentOutputID = &s case *bc.Spend: - spentOutput := tx.Entries[*e.SpentOutputId].(*bc.Output) + 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 + + case *bc.VetoInput: + voteOutput := tx.Entries[*e.SpentOutputId].(*bc.VoteOutput) + a1 := voteOutput.Source.Value.AssetId.Bytes() + assetID = &a1 + amount = &voteOutput.Source.Value.Amount + destPos = &e.WitnessDestination.Position + s := e.SpentOutputId.Bytes() + spentOutputID = &s } var txSigHash *[]byte @@ -86,12 +98,17 @@ func NewTxVMContext(vs *validationState, entry bc.Entry, prog *bc.Program, args } func witnessProgram(prog []byte) []byte { - if segwit.IsP2WPKHScript(prog) { - if witnessProg, err := segwit.ConvertP2PKHSigProgram([]byte(prog)); err == nil { + switch { + case segwit.IsP2WPKHScript(prog): + if witnessProg, err := segwit.ConvertP2PKHSigProgram(prog); err == nil { + return witnessProg + } + case segwit.IsP2WSHScript(prog): + if witnessProg, err := segwit.ConvertP2SHProgram(prog); err == nil { return witnessProg } - } else if segwit.IsP2WSHScript(prog) { - if witnessProg, err := segwit.ConvertP2SHProgram([]byte(prog)); err == nil { + case segwit.IsP2WMCScript(prog): + if witnessProg, err := segwit.ConvertP2MCProgram(prog); err == nil { return witnessProg } } @@ -113,7 +130,10 @@ func (ec *entryContext) checkOutput(index uint64, amount uint64, assetID []byte, } switch e := e.(type) { - case *bc.Output: + 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: @@ -148,10 +168,10 @@ func (ec *entryContext) checkOutput(index uint64, amount uint64, assetID []byte, case *bc.Mux: return checkMux(e) - case *bc.Issuance: + case *bc.Spend: 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()) + return false, errors.Wrapf(bc.ErrMissingEntry, "entry for spend destination %x not found", e.WitnessDestination.Ref.Bytes()) } if m, ok := d.(*bc.Mux); ok { return checkMux(m) @@ -161,10 +181,10 @@ func (ec *entryContext) checkOutput(index uint64, amount uint64, assetID []byte, } return checkEntry(d) - case *bc.Spend: + case *bc.VetoInput: d, ok := ec.entries[*e.WitnessDestination.Ref] if !ok { - return false, errors.Wrapf(bc.ErrMissingEntry, "entry for spend destination %x not found", e.WitnessDestination.Ref.Bytes()) + return false, errors.Wrapf(bc.ErrMissingEntry, "entry for vetoInput destination %x not found", e.WitnessDestination.Ref.Bytes()) } if m, ok := d.(*bc.Mux); ok { return checkMux(m)