OSDN Git Service

a08cfd6c8aa4d5fff1172eaefbd0fdb4f0d9e5e5
[bytom/vapor.git] / protocol / bc / types / crosschain_input.go
1 package types
2
3 import (
4         "github.com/vapor/protocol/bc"
5 )
6
7 // CrossChainInput satisfies the TypedInput interface and represents a cross-chain transaction.
8 type CrossChainInput struct {
9         AssetDefinition       []byte
10         SpendCommitmentSuffix []byte   // The unconsumed suffix of the spend commitment
11         Arguments             [][]byte // Witness
12         SpendCommitment
13 }
14
15 // NewCrossChainInput create a new CrossChainInput struct.
16 // The source is created/issued by trusted federation and hence there is no need
17 // to refer to it.
18 func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram, assetDefinition []byte) *TxInput {
19         sc := SpendCommitment{
20                 AssetAmount: bc.AssetAmount{
21                         AssetId: &assetID,
22                         Amount:  amount,
23                 },
24                 SourceID:       sourceID,
25                 SourcePosition: sourcePos,
26                 VMVersion:      1,
27                 ControlProgram: controlProgram,
28         }
29         return &TxInput{
30                 AssetVersion: 1,
31                 TypedInput: &CrossChainInput{
32                         AssetDefinition: assetDefinition,
33                         SpendCommitment: sc,
34                         Arguments:       arguments,
35                 },
36         }
37 }
38
39 // InputType is the interface function for return the input type.
40 func (si *CrossChainInput) InputType() uint8 { return CrossChainInputType }