/
voteproof.go
69 lines (54 loc) · 1.41 KB
/
voteproof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package base
import (
"time"
"github.com/spikeekips/mitum/util"
)
type Voteproof interface {
util.IsValider
util.HashByter
FinishedAt() time.Time // NOTE if zero, not yet finished
Point() StagePoint
Result() VoteResult
Threshold() Threshold
Majority() BallotFact
SignFacts() []BallotSignFact
ID() string // NOTE ID is only unique in local machine
}
type INITVoteproof interface {
Voteproof
BallotMajority() INITBallotFact
BallotSignFacts() []INITBallotSignFact
}
type ACCEPTVoteproof interface {
Voteproof
BallotMajority() ACCEPTBallotFact
BallotSignFacts() []ACCEPTBallotSignFact
}
type ExpelVoteproof interface {
HasExpels
IsExpelVoteproof() bool // NOTE should be true
}
type StuckVoteproof interface {
HasExpels
IsStuckVoteproof() bool // NOTE should be true
}
func EnsureINITVoteproof(vp Voteproof) (ivp INITVoteproof, _ error) {
e := util.ErrInvalid.Errorf("invalid INITVoteproof")
if vp.Point().Stage() != StageINIT {
return nil, e.Errorf("wrong point stage")
}
if err := util.SetInterfaceValue(vp, &ivp); err != nil {
return nil, e.Wrap(err)
}
return ivp, nil
}
func EnsureACCEPTVoteproof(vp Voteproof) (avp ACCEPTVoteproof, _ error) {
e := util.ErrInvalid.Errorf("invalid ACCEPTVoteproof")
if vp.Point().Stage() != StageACCEPT {
return nil, e.Errorf("wrong point stage")
}
if err := util.SetInterfaceValue(vp, &avp); err != nil {
return nil, e.Wrap(err)
}
return avp, nil
}