OSDN Git Service

add dpos consensus
[bytom/vapor.git] / protocol / bc / types / dpos.go
diff --git a/protocol/bc/types/dpos.go b/protocol/bc/types/dpos.go
new file mode 100644 (file)
index 0000000..9646db9
--- /dev/null
@@ -0,0 +1,65 @@
+package types
+
+import (
+       "github.com/vapor/protocol/bc"
+)
+
+/*
+const (
+       LoginCandidate DposType = iota
+       LogoutCandidate
+       Delegate
+       UnDelegate
+)
+*/
+
+type DposTx struct {
+       SpendCommitmentSuffix []byte
+       Type                  TxType
+       From                  string
+       To                    string
+       Amount                uint64
+       Stake                 uint64
+       PaymentAmount         uint64
+       Arguments             [][]byte
+       Info                  string
+       SpendCommitment
+}
+
+func NewDpos(arguments [][]byte, from, to string, sourceID bc.Hash, assetID bc.AssetID, stake, amount, sourcePos uint64, controlProgram []byte, t TxType) *TxInput {
+       var vote string
+       switch t {
+       case LoginCandidate:
+       case LogoutCandidate:
+       case Delegate:
+               vote = "vapor:1:event:vote"
+       case UnDelegate:
+       }
+       sc := SpendCommitment{
+               AssetAmount: bc.AssetAmount{
+                       AssetId: &assetID,
+                       Amount:  amount,
+               },
+               SourceID:       sourceID,
+               SourcePosition: sourcePos,
+               VMVersion:      1,
+               ControlProgram: controlProgram,
+       }
+
+       return &TxInput{
+               AssetVersion: 1,
+               TypedInput: &DposTx{
+                       SpendCommitment: sc,
+                       Type:            t,
+                       Amount:          amount,
+                       Arguments:       arguments,
+                       Info:            vote,
+                       Stake:           stake,
+                       From:            from,
+                       To:              to,
+               },
+       }
+}
+
+// InputType is the interface function for return the input type.
+func (si *DposTx) InputType() uint8 { return DposInputType }