OSDN Git Service

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