OSDN Git Service

fix(cross_chain): add asset_id check in cross_chain_in request (#177)
[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         SpendCommitmentSuffix []byte   // The unconsumed suffix of the spend commitment
10         Arguments             [][]byte // Witness
11         SpendCommitment
12
13         VMVersion       uint64
14         AssetDefinition []byte
15         IssuanceProgram []byte
16 }
17
18 // NewCrossChainInput create a new CrossChainInput struct.
19 // The source is created/issued by trusted federation and hence there is no need
20 // to refer to it.
21 func NewCrossChainInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos, vmVersion uint64, assetDefinition, issuanceProgram []byte) *TxInput {
22         sc := SpendCommitment{
23                 AssetAmount: bc.AssetAmount{
24                         AssetId: &assetID,
25                         Amount:  amount,
26                 },
27                 SourceID:       sourceID,
28                 SourcePosition: sourcePos,
29                 VMVersion:      1,
30         }
31         return &TxInput{
32                 AssetVersion: 1,
33                 TypedInput: &CrossChainInput{
34                         SpendCommitment: sc,
35                         Arguments:       arguments,
36                         VMVersion:       vmVersion,
37                         AssetDefinition: assetDefinition,
38                         IssuanceProgram: issuanceProgram,
39                 },
40         }
41 }
42
43 // InputType is the interface function for return the input type.
44 func (si *CrossChainInput) InputType() uint8 { return CrossChainInputType }