From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Fri, 17 May 2019 06:58:18 +0000 (+0800) Subject: feature: add cross-chain input (#61) X-Git-Tag: v1.0.5~208^2~116 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=6bf0548429896ef136792b04c6dc21dfe95de016 feature: add cross-chain input (#61) * refactor: rename files * feat: add types.CrossChainInput * feat: add protocol.CrossChainInput * wip: init bc.CrossChainInput * fix: add mainchain output hash * fix: fix letter cases * refactor: fix indent * fix: fix missing value in CrossChainInput * fix: fix NewCrossChainInput() * wip: upgrade MapTx() * refactor: use issue's type indicator for cross-chain input * revert * wip: loop Inputs in mapTx() * wip: add crossIn.SetDestination() in mapTx() * feat: draft mapTx() * refactor: remove ruleAA * feat: add checkValidSrc * wip: init crossIn in checkValid() * wip: add vm.Verify for *bc.CrossChainInput * feat: skip gas for CrossChainInput * refactor: clean up * fix: fix protobuf * fix: fix validate tx * update (t *TxInput) AssetAmount() * add (t *TxInput) Amount() * update * clean * wip: types/txinputs.go * feat: draft types.TxInput * fix: fix test * clean * fix outputID * init assetDefinition * add read/write AssetDefinition * fix the merge issue --- diff --git a/protocol/bc/bc.pb.go b/protocol/bc/bc.pb.go index 619de902..6b0a50ac 100644 --- a/protocol/bc/bc.pb.go +++ b/protocol/bc/bc.pb.go @@ -25,6 +25,7 @@ It has these top-level messages: VoteOutput Retirement Spend + CrossChainInput */ package bc @@ -624,6 +625,62 @@ func (m *Spend) GetOrdinal() uint64 { return 0 } +type CrossChainInput struct { + MainchainOutputId *Hash `protobuf:"bytes,1,opt,name=mainchain_output_id,json=mainchainOutputId" json:"mainchain_output_id,omitempty"` + Value *AssetAmount `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + WitnessDestination *ValueDestination `protobuf:"bytes,3,opt,name=witness_destination,json=witnessDestination" json:"witness_destination,omitempty"` + ControlProgram *Program `protobuf:"bytes,4,opt,name=control_program,json=controlProgram" json:"control_program,omitempty"` + WitnessArguments [][]byte `protobuf:"bytes,5,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"` + Ordinal uint64 `protobuf:"varint,6,opt,name=ordinal" json:"ordinal,omitempty"` +} + +func (m *CrossChainInput) Reset() { *m = CrossChainInput{} } +func (m *CrossChainInput) String() string { return proto.CompactTextString(m) } +func (*CrossChainInput) ProtoMessage() {} +func (*CrossChainInput) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} } + +func (m *CrossChainInput) GetMainchainOutputId() *Hash { + if m != nil { + return m.MainchainOutputId + } + return nil +} + +func (m *CrossChainInput) GetValue() *AssetAmount { + if m != nil { + return m.Value + } + return nil +} + +func (m *CrossChainInput) GetWitnessDestination() *ValueDestination { + if m != nil { + return m.WitnessDestination + } + return nil +} + +func (m *CrossChainInput) GetControlProgram() *Program { + if m != nil { + return m.ControlProgram + } + return nil +} + +func (m *CrossChainInput) GetWitnessArguments() [][]byte { + if m != nil { + return m.WitnessArguments + } + return nil +} + +func (m *CrossChainInput) GetOrdinal() uint64 { + if m != nil { + return m.Ordinal + } + return 0 +} + func init() { proto.RegisterType((*Hash)(nil), "bc.Hash") proto.RegisterType((*Program)(nil), "bc.Program") @@ -642,63 +699,67 @@ func init() { proto.RegisterType((*VoteOutput)(nil), "bc.VoteOutput") proto.RegisterType((*Retirement)(nil), "bc.Retirement") proto.RegisterType((*Spend)(nil), "bc.Spend") + proto.RegisterType((*CrossChainInput)(nil), "bc.CrossChainInput") } func init() { proto.RegisterFile("bc.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 835 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x6f, 0xe4, 0x34, - 0x14, 0xd6, 0x4c, 0xd2, 0x49, 0xfa, 0xa6, 0xdb, 0xe9, 0x78, 0x77, 0x21, 0x5a, 0x81, 0xa8, 0x22, - 0x2d, 0x5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0c, 0xe9, 0x2f, 0x6f, - 0xf6, 0xb7, 0x1e, 0xac, 0x9d, 0x96, 0xbc, 0xc8, 0xc8, 0x1e, 0x8c, 0x74, 0xc9, 0x0b, 0x93, 0x48, - 0xdc, 0xf7, 0xe2, 0x83, 0xb9, 0x78, 0x1c, 0x1e, 0x61, 0x41, 0xa3, 0xcb, 0x24, 0xbb, 0xef, 0xa6, - 0xf6, 0xff, 0xe1, 0x4d, 0xbd, 0xd3, 0x29, 0xde, 0xdd, 0x4e, 0xe9, 0xee, 0xc4, 0x5f, 0xda, 0xc9, - 0x74, 0x80, 0x7f, 0x6a, 0x0e, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0xc7, 0x32, 0xe6, 0x29, 0xe0, - 0x08, 0x00, 0x00, + // 886 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x6f, 0xe3, 0x44, + 0x14, 0x57, 0x6c, 0x37, 0x49, 0x5f, 0xba, 0x4d, 0x33, 0xdd, 0x05, 0x6b, 0x05, 0xa2, 0xb2, 0xb4, + 0x74, 0x11, 0x52, 0xd5, 0x3f, 0x8b, 0xe0, 0xc0, 0x81, 0xd2, 0xb2, 0x6c, 0x0e, 0xab, 0x45, 0xd3, + 0xaa, 0x57, 0x6b, 0x62, 0x4f, 0x9b, 0x11, 0x8e, 0x27, 0xcc, 0x8c, 0x4d, 0xb7, 0x5f, 0x81, 0x33, + 0x07, 0xbe, 0x08, 0x5f, 0x81, 0x13, 0x9f, 0x09, 0x34, 0xcf, 0xe3, 0xc4, 0x69, 0xd2, 0x76, 0x57, + 0x08, 0xc1, 0xcd, 0xef, 0xdf, 0xef, 0xbd, 0xf7, 0x9b, 0xf7, 0x66, 0x0c, 0xdd, 0x51, 0xb2, 0x37, + 0x55, 0xd2, 0x48, 0xe2, 0x8d, 0x92, 0xe8, 0x25, 0x04, 0xaf, 0x98, 0x1e, 0x93, 0x4d, 0xf0, 0xca, + 0xfd, 0xb0, 0xb5, 0xd3, 0x7a, 0xde, 0xa6, 0x5e, 0xb9, 0x8f, 0xf2, 0x41, 0xe8, 0x39, 0xf9, 0x00, + 0xe5, 0xc3, 0xd0, 0x77, 0xf2, 0x21, 0xca, 0x47, 0x61, 0xe0, 0xe4, 0xa3, 0xe8, 0x6b, 0xe8, 0xfc, + 0xa0, 0xe4, 0x95, 0x62, 0x13, 0xf2, 0x31, 0x40, 0x39, 0x89, 0x4b, 0xae, 0xb4, 0x90, 0x39, 0x42, + 0x06, 0x74, 0xbd, 0x9c, 0x5c, 0x54, 0x0a, 0x42, 0x20, 0x48, 0x64, 0xca, 0x11, 0x7b, 0x83, 0xe2, + 0x77, 0x34, 0x84, 0xce, 0xb1, 0xd6, 0xdc, 0x0c, 0x4f, 0xff, 0x71, 0x21, 0xaf, 0xa1, 0x87, 0x50, + 0xc7, 0x13, 0x59, 0xe4, 0x86, 0x7c, 0x0a, 0x5d, 0x66, 0xc5, 0x58, 0xa4, 0x08, 0xda, 0x3b, 0xec, + 0xed, 0x8d, 0x92, 0x3d, 0x97, 0x8d, 0x76, 0xd0, 0x38, 0x4c, 0xc9, 0x07, 0xd0, 0x66, 0x18, 0x81, + 0xa9, 0x02, 0xea, 0xa4, 0x28, 0x83, 0xde, 0x05, 0xcb, 0x0a, 0x7e, 0x26, 0x0b, 0x95, 0x70, 0xf2, + 0x14, 0x7c, 0xc5, 0x2f, 0x1d, 0x52, 0xd7, 0x22, 0x59, 0xf6, 0xa8, 0x55, 0x92, 0x67, 0xb0, 0x56, + 0x5a, 0x57, 0x44, 0xe8, 0x1d, 0xf6, 0x67, 0x79, 0xaa, 0x52, 0x68, 0x65, 0x25, 0x4f, 0xa1, 0x3b, + 0x95, 0x5a, 0x18, 0x4b, 0x8e, 0x8f, 0xb9, 0x66, 0x72, 0xf4, 0x13, 0x6c, 0x61, 0xb6, 0x53, 0xae, + 0x8d, 0xc8, 0x99, 0x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6b, 0x30, 0x73, 0x9a, 0xf5, 0xf6, 0x8e, 0x2f, 0xeb, 0x1d, 0x14, + 0xf8, 0xef, 0x49, 0xc1, 0x8a, 0xd1, 0x09, 0x1e, 0x1e, 0x9d, 0x95, 0xc4, 0xad, 0x3d, 0x4c, 0x5c, + 0x7b, 0x81, 0xb8, 0x51, 0x1b, 0xff, 0x06, 0x8f, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x41, + 0xe2, 0x4f, 0x19, 0x0a, 0x00, 0x00, } diff --git a/protocol/bc/bc.proto b/protocol/bc/bc.proto index 254285ff..fd25c9e9 100644 --- a/protocol/bc/bc.proto +++ b/protocol/bc/bc.proto @@ -111,4 +111,13 @@ message Spend { ValueDestination witness_destination = 2; repeated bytes witness_arguments = 3; uint64 ordinal = 4; +} + +message CrossChainInput { + Hash mainchain_output_id = 1; + AssetAmount value = 2; + ValueDestination witness_destination = 3; + Program control_program = 4; + repeated bytes witness_arguments = 5; + uint64 ordinal = 6; } \ No newline at end of file diff --git a/protocol/bc/crosschain_input.go b/protocol/bc/crosschain_input.go new file mode 100644 index 00000000..0ce867d8 --- /dev/null +++ b/protocol/bc/crosschain_input.go @@ -0,0 +1,30 @@ +package bc + +import "io" + +// crosschaininput is the result of a transfer of value. The value it contains +// comes from the main chain. It satisfies the Entry interface. + +func (CrossChainInput) typ() string { return "crosschaininput1" } + +func (cci *CrossChainInput) writeForHash(w io.Writer) { + mustWriteForHash(w, cci.MainchainOutputId) +} + +// SetDestination will link the CrossChainInput to the output +func (cci *CrossChainInput) SetDestination(id *Hash, val *AssetAmount, pos uint64) { + cci.WitnessDestination = &ValueDestination{ + Ref: id, + Value: val, + Position: pos, + } +} + +// NewCrossChainInput creates a new CrossChainInput. +func NewCrossChainInput(mainchainOutputID *Hash, value *AssetAmount, ordinal uint64) *CrossChainInput { + return &CrossChainInput{ + MainchainOutputId: mainchainOutputID, + Value: value, + Ordinal: ordinal, + } +} diff --git a/protocol/bc/types/crosschain_input.go b/protocol/bc/types/crosschain_input.go new file mode 100644 index 00000000..a08cfd6c --- /dev/null +++ b/protocol/bc/types/crosschain_input.go @@ -0,0 +1,40 @@ +package types + +import ( + "github.com/vapor/protocol/bc" +) + +// CrossChainInput satisfies the TypedInput interface and represents a cross-chain transaction. +type CrossChainInput struct { + AssetDefinition []byte + SpendCommitmentSuffix []byte // The unconsumed suffix of the spend commitment + Arguments [][]byte // Witness + SpendCommitment +} + +// NewCrossChainInput create a new CrossChainInput struct. +// The source is created/issued by trusted federation and hence there is no need +// to refer to it. +func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram, assetDefinition []byte) *TxInput { + sc := SpendCommitment{ + AssetAmount: bc.AssetAmount{ + AssetId: &assetID, + Amount: amount, + }, + SourceID: sourceID, + SourcePosition: sourcePos, + VMVersion: 1, + ControlProgram: controlProgram, + } + return &TxInput{ + AssetVersion: 1, + TypedInput: &CrossChainInput{ + AssetDefinition: assetDefinition, + SpendCommitment: sc, + Arguments: arguments, + }, + } +} + +// InputType is the interface function for return the input type. +func (si *CrossChainInput) InputType() uint8 { return CrossChainInputType } diff --git a/protocol/bc/types/crosschain_txoutput.go b/protocol/bc/types/crosschain_output.go similarity index 100% rename from protocol/bc/types/crosschain_txoutput.go rename to protocol/bc/types/crosschain_output.go diff --git a/protocol/bc/types/intrachain_txoutput.go b/protocol/bc/types/intrachain_output.go similarity index 100% rename from protocol/bc/types/intrachain_txoutput.go rename to protocol/bc/types/intrachain_output.go diff --git a/protocol/bc/types/map.go b/protocol/bc/types/map.go index 348c203d..8ec61676 100644 --- a/protocol/bc/types/map.go +++ b/protocol/bc/types/map.go @@ -24,6 +24,12 @@ func MapTx(oldTx *TxData) *bc.Tx { for id, e := range entries { var ord uint64 switch e := e.(type) { + case *bc.CrossChainInput: + ord = e.Ordinal + if *e.WitnessDestination.Value.AssetId == *consensus.BTMAssetID { + tx.GasInputIDs = append(tx.GasInputIDs, id) + } + case *bc.Spend: ord = e.Ordinal spentOutputIDs[*e.SpentOutputId] = true @@ -61,6 +67,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash var ( spends []*bc.Spend + crossIns []*bc.CrossChainInput coinbase *bc.Coinbase ) @@ -100,7 +107,6 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash } case *UnvoteInput: - // create entry for prevout prog := &bc.Program{VmVersion: inp.VMVersion, Code: inp.ControlProgram} src := &bc.ValueSource{ Ref: &inp.SourceID, @@ -120,6 +126,24 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash } spends = append(spends, spend) + case *CrossChainInput: + prog := &bc.Program{VmVersion: inp.VMVersion, Code: inp.ControlProgram} + src := &bc.ValueSource{ + Ref: &inp.SourceID, + Value: &inp.AssetAmount, + Position: inp.SourcePosition, + } + prevout := bc.NewCrossChainOutput(src, prog, 0) // ordinal doesn't matter + outputID := bc.EntryID(prevout) + crossIn := bc.NewCrossChainInput(&outputID, &inp.AssetAmount, uint64(i)) + crossIn.WitnessArguments = inp.Arguments + crossInID := addEntry(crossIn) + muxSources[i] = &bc.ValueSource{ + Ref: &crossInID, + Value: &inp.AssetAmount, + } + crossIns = append(crossIns, crossIn) + } } @@ -132,6 +156,10 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash spend.SetDestination(&muxID, spentOutput.Source.Value, spend.Ordinal) } + for _, crossIn := range crossIns { + crossIn.SetDestination(&muxID, crossIn.Value, crossIn.Ordinal) + } + if coinbase != nil { coinbase.SetDestination(&muxID, mux.Sources[0].Value, 0) } diff --git a/protocol/bc/types/spend.go b/protocol/bc/types/spend.go index 8642d35a..15b2b69f 100644 --- a/protocol/bc/types/spend.go +++ b/protocol/bc/types/spend.go @@ -6,7 +6,7 @@ import ( // SpendInput satisfies the TypedInput interface and represents a spend transaction. type SpendInput struct { - SpendCommitmentSuffix []byte // The unconsumed suffix of the output commitment + SpendCommitmentSuffix []byte // The unconsumed suffix of the spend commitment Arguments [][]byte // Witness SpendCommitment } diff --git a/protocol/bc/types/txinput.go b/protocol/bc/types/txinput.go index 2da01345..c9fa0a06 100644 --- a/protocol/bc/types/txinput.go +++ b/protocol/bc/types/txinput.go @@ -11,7 +11,7 @@ import ( // serflag variables for input types. const ( - IssuanceInputType uint8 = iota + CrossChainInputType uint8 = iota SpendInputType CoinbaseInputType UnvoteInputType @@ -40,9 +40,13 @@ func (t *TxInput) AssetAmount() bc.AssetAmount { case *SpendInput: return inp.AssetAmount + case *CrossChainInput: + return inp.AssetAmount + case *UnvoteInput: return inp.AssetAmount } + return bc.AssetAmount{} } @@ -52,8 +56,12 @@ func (t *TxInput) AssetID() bc.AssetID { case *SpendInput: return *inp.AssetId + case *CrossChainInput: + return *inp.AssetAmount.AssetId + case *UnvoteInput: return *inp.AssetId + } return bc.AssetID{} } @@ -64,8 +72,12 @@ func (t *TxInput) Amount() uint64 { case *SpendInput: return inp.Amount + case *CrossChainInput: + return inp.AssetAmount.Amount + case *UnvoteInput: return inp.Amount + } return 0 } @@ -76,8 +88,12 @@ func (t *TxInput) ControlProgram() []byte { case *SpendInput: return inp.ControlProgram + case *CrossChainInput: + return inp.ControlProgram + case *UnvoteInput: return inp.ControlProgram + } return nil @@ -89,6 +105,9 @@ func (t *TxInput) Arguments() [][]byte { case *SpendInput: return inp.Arguments + case *CrossChainInput: + return inp.Arguments + case *UnvoteInput: return inp.Arguments } @@ -101,6 +120,9 @@ func (t *TxInput) SetArguments(args [][]byte) { case *SpendInput: inp.Arguments = args + case *CrossChainInput: + inp.Arguments = args + case *UnvoteInput: inp.Arguments = args } @@ -132,6 +154,7 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { if _, err = io.ReadFull(r, icType[:]); err != nil { return errors.Wrap(err, "reading input commitment type") } + switch icType[0] { case SpendInputType: si := new(SpendInput) @@ -147,10 +170,18 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { return err } + case CrossChainInputType: + ci := new(CrossChainInput) + t.TypedInput = ci + if ci.SpendCommitmentSuffix, err = ci.SpendCommitment.readFrom(r, 1); err != nil { + return err + } + case UnvoteInputType: ui := new(UnvoteInput) t.TypedInput = ui if ui.UnvoteCommitmentSuffix, err = ui.SpendCommitment.readFrom(r, 1); err != nil { + return err } @@ -174,6 +205,11 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { return err } + case *CrossChainInput: + if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil { + return err + } + case *UnvoteInput: if inp.Arguments, err = blockchain.ReadVarstrList(r); err != nil { return err @@ -185,8 +221,18 @@ func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { } return nil }) + if err != nil { + return err + } + + switch inp := t.TypedInput.(type) { + case *CrossChainInput: + if inp.AssetDefinition, err = blockchain.ReadVarstr31(r); err != nil { + return err + } + } - return err + return nil } func (t *TxInput) writeTo(w io.Writer) error { @@ -198,8 +244,18 @@ func (t *TxInput) writeTo(w io.Writer) error { return errors.Wrap(err, "writing input commitment") } - _, err := blockchain.WriteExtensibleString(w, t.WitnessSuffix, t.writeInputWitness) - return errors.Wrap(err, "writing input witness") + if _, err := blockchain.WriteExtensibleString(w, t.WitnessSuffix, t.writeInputWitness); err != nil { + return errors.Wrap(err, "writing input witness") + } + + switch inp := t.TypedInput.(type) { + case *CrossChainInput: + if _, err := blockchain.WriteVarstr31(w, inp.AssetDefinition); err != nil { + return errors.Wrap(err, "writing AssetDefinition") + } + } + + return nil } func (t *TxInput) writeInputCommitment(w io.Writer) (err error) { @@ -214,6 +270,12 @@ func (t *TxInput) writeInputCommitment(w io.Writer) (err error) { } return inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion) + case *CrossChainInput: + if _, err = w.Write([]byte{SpendInputType}); err != nil { + return err + } + return inp.SpendCommitment.writeExtensibleString(w, inp.SpendCommitmentSuffix, t.AssetVersion) + case *CoinbaseInput: if _, err = w.Write([]byte{CoinbaseInputType}); err != nil { return err @@ -241,6 +303,9 @@ func (t *TxInput) writeInputWitness(w io.Writer) error { _, err := blockchain.WriteVarstrList(w, inp.Arguments) return err + case *CrossChainInput: + _, err := blockchain.WriteVarstrList(w, inp.Arguments) + return err case *UnvoteInput: if _, err := blockchain.WriteVarstrList(w, inp.Arguments); err != nil { return err diff --git a/protocol/validation/tx.go b/protocol/validation/tx.go index 058b736d..6e0acd24 100644 --- a/protocol/validation/tx.go +++ b/protocol/validation/tx.go @@ -238,6 +238,18 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { return errors.Wrap(err, "checking retirement source") } + case *bc.CrossChainInput: + _, err := vm.Verify(NewTxVMContext(vs, e, e.ControlProgram, e.WitnessArguments), consensus.DefaultGasCredit) + if err != nil { + return errors.Wrap(err, "checking cross-chain input control program") + } + + vs2 := *vs + vs2.destPos = 0 + if err = checkValidDest(&vs2, e.WitnessDestination); err != nil { + return errors.Wrap(err, "checking cross-chain input destination") + } + case *bc.Spend: if e.SpentOutputId == nil { return errors.Wrap(ErrMissingField, "spend without spent output ID") @@ -246,7 +258,6 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { if err != nil { return errors.Wrap(err, "getting spend prevout") } - gasLeft, err := vm.Verify(NewTxVMContext(vs, e, spentOutput.ControlProgram, e.WitnessArguments), vs.gasStatus.GasLeft) if err != nil { return errors.Wrap(err, "checking control program") @@ -254,7 +265,6 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { if err = vs.gasStatus.updateUsage(gasLeft); err != nil { return err } - eq, err := spentOutput.Source.Value.Equal(e.WitnessDestination.Value) if err != nil { return err @@ -269,7 +279,6 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { e.WitnessDestination.Value.AssetId.Bytes(), ) } - vs2 := *vs vs2.destPos = 0 if err = checkValidDest(&vs2, e.WitnessDestination); err != nil { @@ -333,6 +342,12 @@ func checkValidSrc(vstate *validationState, vs *bc.ValueSource) error { } dest = ref.WitnessDestination + case *bc.CrossChainInput: + if vs.Position != 0 { + return errors.Wrapf(ErrPosition, "invalid position %d for cross-chain input source", vs.Position) + } + dest = ref.WitnessDestination + case *bc.Spend: if vs.Position != 0 { return errors.Wrapf(ErrPosition, "invalid position %d for spend source", vs.Position) @@ -346,7 +361,7 @@ func checkValidSrc(vstate *validationState, vs *bc.ValueSource) error { dest = ref.WitnessDestinations[vs.Position] default: - return errors.Wrapf(bc.ErrEntryType, "value source is %T, should be coinbase, issuance, spend, or mux", e) + return errors.Wrapf(bc.ErrEntryType, "value source is %T, should be coinbase, cross-chain input, spend, or mux", e) } if dest.Ref == nil || *dest.Ref != vstate.entryID {