OSDN Git Service

01d00f3711aac9b5c0587ea9711a6e765ea5e19e
[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         LoginCandidate
12         LogoutCandidate
13         Delegate
14         UnDelegate
15 )
16
17 // SpendInput satisfies the TypedInput interface and represents a spend transaction.
18 type SpendInput struct {
19         SpendCommitmentSuffix []byte   // The unconsumed suffix of the output commitment
20         Arguments             [][]byte // Witness
21         SpendCommitment
22 }
23
24 // NewSpendInput create a new SpendInput struct.
25 func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount, sourcePos uint64, controlProgram []byte) *TxInput {
26         sc := SpendCommitment{
27                 AssetAmount: bc.AssetAmount{
28                         AssetId: &assetID,
29                         Amount:  amount,
30                 },
31                 SourceID:       sourceID,
32                 SourcePosition: sourcePos,
33                 VMVersion:      1,
34                 ControlProgram: controlProgram,
35         }
36         return &TxInput{
37                 AssetVersion: 1,
38                 TypedInput: &SpendInput{
39                         SpendCommitment: sc,
40                         Arguments:       arguments,
41                 },
42         }
43 }
44
45 // InputType is the interface function for return the input type.
46 func (si *SpendInput) InputType() uint8 { return SpendInputType }