OSDN Git Service

feature: add cross-chain input (#61)
[bytom/vapor.git] / protocol / bc / types / spend.go
1 package types
2
3 import (
4         "github.com/vapor/protocol/bc"
5 )
6
7 // SpendInput satisfies the TypedInput interface and represents a spend transaction.
8 type SpendInput struct {
9         SpendCommitmentSuffix []byte   // The unconsumed suffix of the spend commitment
10         Arguments             [][]byte // Witness
11         SpendCommitment
12 }
13
14 // NewSpendInput create a new SpendInput struct.
15 func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput {
16         sc := SpendCommitment{
17                 AssetAmount: bc.AssetAmount{
18                         AssetId: &assetID,
19                         Amount:  amount,
20                 },
21                 SourceID:       sourceID,
22                 SourcePosition: sourcePos,
23                 VMVersion:      1,
24                 ControlProgram: controlProgram,
25         }
26         return &TxInput{
27                 AssetVersion: 1,
28                 TypedInput: &SpendInput{
29                         SpendCommitment: sc,
30                         Arguments:       arguments,
31                 },
32         }
33 }
34
35 // InputType is the interface function for return the input type.
36 func (si *SpendInput) InputType() uint8 { return SpendInputType }