-
Notifications
You must be signed in to change notification settings - Fork 180
/
vote.go
50 lines (40 loc) · 1.33 KB
/
vote.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
package types
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Votes is the alias of sdk.Dec to represent the number of votes for multi-voting function
type Votes = sdk.Dec
// MustUnmarshalVote unmarshals the vote bytes and return it
func MustUnmarshalVote(cdc *codec.Codec, bytes []byte) Votes {
var vote Votes
cdc.MustUnmarshalBinaryLengthPrefixed(bytes, &vote)
return vote
}
// VoteResponse is the struct for query all the votes on a validator
type VoteResponse struct {
VoterAddr sdk.AccAddress `json:"voter_address"`
Votes sdk.Dec `json:"votes"`
}
// NewVoteResponse creates a new instance of VoteResponse
func NewVoteResponse(voterAddr sdk.AccAddress, votes Votes) VoteResponse {
return VoteResponse{
voterAddr,
votes,
}
}
// String returns a human readable string representation of VoteResponse
func (vr VoteResponse) String() string {
return fmt.Sprintf("%s\n Votes: %s", vr.VoterAddr.String(), vr.Votes)
}
// VoteResponses is the type alias of VoteResponse slice
type VoteResponses []VoteResponse
// String returns a human readable string representation of VoteResponses
func (vrs VoteResponses) String() (strFormat string) {
for _, vr := range vrs {
strFormat = fmt.Sprintf("%s%s\n", strFormat, vr.String())
}
return strings.TrimSpace(strFormat)
}