OSDN Git Service

276d9e55da5bf7d698a8afaa2957532750f95933
[bytom/vapor.git] / protocol / bc / types / dpos.go
1 package types
2
3 import (
4         "fmt"
5
6         "github.com/vapor/protocol/bc"
7 )
8
9 type DposTx struct {
10         SpendCommitmentSuffix []byte
11         Type                  TxType
12         From                  string
13         To                    string
14         Amount                uint64
15         Stake                 uint64
16         Arguments             [][]byte
17         Info                  string
18         SpendCommitment
19 }
20
21 func NewDpos(arguments [][]byte, from, to string, sourceID bc.Hash, assetID bc.AssetID, stake, amount, sourcePos uint64, controlProgram []byte, t TxType, height uint64) *TxInput {
22         var vote string
23         switch t {
24         case LoginCandidate:
25         case LogoutCandidate:
26         case Delegate:
27                 vote = "vapor:1:event:vote"
28         case UnDelegate:
29         case ConfirmTx:
30                 vote = fmt.Sprintf("vapor:1:event:confirm:%d", height)
31         }
32         sc := SpendCommitment{
33                 AssetAmount: bc.AssetAmount{
34                         AssetId: &assetID,
35                         Amount:  amount,
36                 },
37                 SourceID:       sourceID,
38                 SourcePosition: sourcePos,
39                 VMVersion:      1,
40                 ControlProgram: controlProgram,
41         }
42
43         return &TxInput{
44                 AssetVersion: 1,
45                 TypedInput: &DposTx{
46                         SpendCommitment: sc,
47                         Type:            t,
48                         Amount:          amount,
49                         Arguments:       arguments,
50                         Info:            vote,
51                         Stake:           stake,
52                         From:            from,
53                         To:              to,
54                 },
55         }
56 }
57
58 // InputType is the interface function for return the input type.
59 func (si *DposTx) InputType() uint8 { return DposInputType }