-
Notifications
You must be signed in to change notification settings - Fork 2
/
contracts.go
103 lines (82 loc) · 2.96 KB
/
contracts.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
99
100
101
102
103
package api
import (
"log"
"net/http"
"github.com/archway-network/cosmologger/block"
"github.com/archway-network/valuter/configs"
"github.com/archway-network/valuter/contracts"
"github.com/archway-network/valuter/participants"
"github.com/archway-network/valuter/tools"
routing "github.com/julienschmidt/httprouter"
)
/*----------------------*/
/*
* This function implements GET /challenges/contracts/max-net-rewards
*/
func GetMaxNetworkRewardsWinners(resp http.ResponseWriter, req *http.Request, params routing.Params) {
contractsList, err := contracts.GetMaxNetworkRewardsTopContracts(
uint64(configs.Configs.Tasks.ContractsMaxRewards.MaxWinners),
configs.Configs.Tasks.ContractsMaxRewards.Condition.StartHight,
configs.Configs.Tasks.ContractsMaxRewards.Condition.EndHight,
)
if err != nil {
log.Printf("API Call Error: %v", err)
http.Error(resp, "Internal Server Error: "+err.Error(), http.StatusInternalServerError)
return
}
type Output struct {
block.ContractRecord
participants.ParticipantRecord
}
var output []Output
for i := range contractsList {
pRec, _ := participants.GetParticipantByAddress(contractsList[i].DeveloperAddress)
// Some participant might use their main account address as the reward address instead of developer address
if pRec.AccountAddress == "" && contractsList[i].DeveloperAddress != contractsList[i].RewardAddress {
pRec, _ = participants.GetParticipantByAddress(contractsList[i].RewardAddress)
}
contractsList[i].MetadataJson = ""
output = append(output,
Output{
ContractRecord: contractsList[i],
ParticipantRecord: pRec,
})
}
tools.SendJSON(resp, output)
}
/*-------------*/
/*
* This function implements GET /challenges/contracts/max-net-rewards
*/
func GetContractsSubsidizeUsersFeesWinners(resp http.ResponseWriter, req *http.Request, params routing.Params) {
contractsList, err := contracts.GetSubsidizeUsersFeesTopContracts(
uint64(configs.Configs.Tasks.ContractsMaxRewards.MaxWinners),
configs.Configs.Tasks.ContractsMaxRewards.Condition.StartHight,
configs.Configs.Tasks.ContractsMaxRewards.Condition.EndHight,
)
if err != nil {
log.Printf("API Call Error: %v", err)
http.Error(resp, "Internal Server Error: "+err.Error(), http.StatusInternalServerError)
return
}
type Output struct {
block.ContractRecord
participants.ParticipantRecord
}
var output []Output
for i := range contractsList {
pRec, _ := participants.GetParticipantByAddress(contractsList[i].DeveloperAddress)
// Some participant might use their main account address as the reward address instead of developer address
if pRec.AccountAddress == "" && contractsList[i].DeveloperAddress != contractsList[i].RewardAddress {
pRec, _ = participants.GetParticipantByAddress(contractsList[i].RewardAddress)
}
contractsList[i].MetadataJson = ""
output = append(output,
Output{
ContractRecord: contractsList[i],
ParticipantRecord: pRec,
})
}
tools.SendJSON(resp, output)
}
/*-------------*/