forked from archway-network/valuter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gov.go
98 lines (72 loc) · 2.18 KB
/
gov.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package tasks
import (
"fmt"
"github.com/celestiaorg/cosmologger/database"
cosmoLogTx "github.com/celestiaorg/cosmologger/tx"
"github.com/celestiaorg/valuter/configs"
"github.com/celestiaorg/valuter/participants"
"github.com/celestiaorg/valuter/winners"
)
func GetGovWinnersPerProposal(proposalId uint64) (winners.WinnersList, error) {
var winnersList winners.WinnersList
if configs.Configs.Tasks.Gov.MaxWinners == 0 {
return winnersList, nil
}
// If someone has done the task more than once, there will be more than a record here,
// But that's not a problem, as winners list is distinct
SQL := fmt.Sprintf(`
SELECT "%s", "%s"
FROM "%s"
WHERE
"%s" = $1 AND
"%s" = $2
ORDER BY "%s" ASC`, // >= 2 is because we want the participants to delegate at least to two validators
database.FIELD_TX_EVENTS_SENDER,
database.FIELD_TX_EVENTS_HEIGHT,
database.TABLE_TX_EVENTS,
database.FIELD_TX_EVENTS_ACTION,
database.FIELD_TX_EVENTS_PROPOSAL_ID,
database.FIELD_TX_EVENTS_HEIGHT,
)
rows, err := database.DB.Query(SQL,
database.QueryParams{
cosmoLogTx.ACTION_VOTE,
proposalId,
})
if err != nil {
return winnersList, err
}
for i := range rows {
address := rows[i][database.FIELD_TX_EVENTS_SENDER].(string)
pRecord, err := participants.GetParticipantByAddress(address)
if err != nil {
return winnersList, err
}
// If the participant is not verified by KYC provider, just ignore it
if !pRecord.KycVerified {
continue
}
newWinner := winners.Winner{
Address: address,
Rewards: configs.Configs.Tasks.Gov.Reward,
ParticipantData: pRecord,
}
winnersList.Append(newWinner)
if winnersList.Length() >= configs.Configs.Tasks.Gov.MaxWinners {
break // Max winners reached
}
}
return winnersList, nil
}
func GetGovWinners() (winners.WinnersList, error) {
var winnersList winners.WinnersList
for i := range configs.Configs.Tasks.Gov.Proposals {
proposalId := uint64(configs.Configs.Tasks.Gov.Proposals[i])
proposalWinnerList, err := GetGovWinnersPerProposal(proposalId)
if err != nil {
return winnersList, err
}
winnersList.MergeWithAggregateRewards(proposalWinnerList)
}
return winnersList, nil
}