OSDN Git Service

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