@@ -2,69 +2,32 @@ package governance
2
2
3
3
import (
4
4
"std"
5
- "strconv"
6
5
7
6
"gno.land/p/demo/ufmt"
8
-
9
7
"gno.land/r/gnoswap/v1/common"
10
8
)
11
9
12
- // Helper function to validate and get vote information
13
- func getVoteInfoFromKey(voteKey string) (voteWithWeight, bool) {
14
- _, exists := votes.Get(voteKey)
15
- if !exists {
16
- panic(addDetailToError(
17
- errDataNotFound,
18
- ufmt.Sprintf("voteKey(%s) not found", voteKey),
19
- ))
20
- }
21
-
22
- pid, addr := divideVoteKeyToProposalIdAndUser(voteKey)
23
-
24
- voteInfo, exists := getUserVote(addr, pid)
25
- if !exists {
26
- panic(addDetailToError(
27
- errDataNotFound,
28
- ufmt.Sprintf("voteKey(%s) not found", voteKey),
29
- ))
30
- }
31
-
32
- return voteInfo, true
33
- }
34
-
35
10
func GetVoteByVoteKey(voteKey string) bool {
36
- vote, exist := votes.Get(voteKey)
37
- if !exist {
38
- panic(addDetailToError(
39
- errDataNotFound,
40
- ufmt.Sprintf("voteKey(%s) not found", voteKey),
41
- ))
42
- }
43
-
44
- return vote.(bool)
11
+ return mustGetVote(voteKey)
45
12
}
46
13
47
14
func GetVoteYesByVoteKey(voteKey string) bool {
48
- voteInfo, _ := getVoteInfoFromKey(voteKey)
49
- return voteInfo.Yes
15
+ return mustGetVoteInfo(voteKey).Yes
50
16
}
51
17
52
18
func GetVoteWeightByVoteKey(voteKey string) uint64 {
53
- voteInfo, _ := getVoteInfoFromKey(voteKey)
54
- return voteInfo.Weight
19
+ return mustGetVoteInfo(voteKey).Weight
55
20
}
56
21
57
22
func GetVotedHeightByVoteKey(voteKey string) uint64 {
58
- voteInfo, _ := getVoteInfoFromKey(voteKey)
59
- return voteInfo.VotedHeight
23
+ return mustGetVoteInfo(voteKey).VotedHeight
60
24
}
61
25
62
26
func GetVotedAtByVoteKey(voteKey string) uint64 {
63
- voteInfo, _ := getVoteInfoFromKey(voteKey)
64
- return voteInfo.VotedAt
27
+ return mustGetVoteInfo(voteKey).VotedAt
65
28
}
66
29
67
- func divideVoteKeyToProposalIdAndUser(voteKey string) (uint64, std.Address) {
30
+ func divideVoteKeyToProposalIdAndUser(voteKey string) (proposalId uint64, user std.Address) {
68
31
parts, err := common.Split(voteKey, ":", 2)
69
32
if err != nil {
70
33
panic(addDetailToError(
@@ -73,13 +36,5 @@ func divideVoteKeyToProposalIdAndUser(voteKey string) (uint64, std.Address) {
73
36
))
74
37
}
75
38
76
- proposalId, err := strconv.ParseUint(parts[0], 10, 64)
77
- if err != nil {
78
- panic(addDetailToError(
79
- errInvalidInput,
80
- ufmt.Sprintf("proposalId(%s) is invalid", parts[0]),
81
- ))
82
- }
83
-
84
- return proposalId, std.Address(parts[1])
39
+ return parseUint64(parts[0]), std.Address(parts[1])
85
40
}
0 commit comments