-
Notifications
You must be signed in to change notification settings - Fork 6
/
routes.go
171 lines (127 loc) · 5.44 KB
/
routes.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package participation
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/iotaledger/inx-app/pkg/httpserver"
)
const (
APIRoute = "/api/participation/v1"
// RouteParticipationEvents is the route to list all events, returning their ID, the event name and status.
// GET returns a list of all events known to the node. Optional query parameter returns filters events by type (query parameters: "type").
RouteParticipationEvents = "/events"
// RouteParticipationEvent is the route to access a single participation by its ID.
// GET gives a quick overview of the participation. This does not include the current standings.
RouteParticipationEvent = "/events/:" + ParameterParticipationEventID
// RouteParticipationEventStatus is the route to access the status of a single participation by its ID.
// GET returns the amount of tokens participating and accumulated votes for the ballot if the event contains a ballot. Optional query parameter returns the status for the given milestone index (query parameters: "milestoneIndex").
RouteParticipationEventStatus = "/events/:" + ParameterParticipationEventID + "/status"
// RouteOutputStatus is the route to get the vote status for a given outputID.
// GET returns the blockID the participation was included, the starting and ending milestone index this participation was tracked.
RouteOutputStatus = "/outputs/:" + ParameterOutputID
// RouteAddressBech32Status is the route to get the staking rewards for the given bech32 address.
RouteAddressBech32Status = "/addresses/:" + ParameterAddress
// RouteAddressBech32Outputs is the route to get the outputs for the given bech32 address.
RouteAddressBech32Outputs = "/addresses/:" + ParameterAddress + "/outputs"
// RouteAdminCreateEvent is the route the node operator can use to add events.
// POST creates a new event to track.
RouteAdminCreateEvent = "/admin/events"
// RouteAdminDeleteEvent is the route the node operator can use to remove events.
// DELETE removes a tracked participation.
RouteAdminDeleteEvent = "/admin/events/:" + ParameterParticipationEventID
// RouteAdminActiveParticipations is the route the node operator can use to get all the active participations for a certain event.
// GET returns a list of all active participations.
RouteAdminActiveParticipations = "/admin/events/:" + ParameterParticipationEventID + "/active"
// RouteAdminPastParticipations is the route the node operator can use to get all the past participations for a certain event.
// GET returns a list of all past participations.
RouteAdminPastParticipations = "/admin/events/:" + ParameterParticipationEventID + "/past"
// RouteAdminRewards is the route the node operator can use to get the rewards for a staking event.
// GET retrieves the staking event rewards.
RouteAdminRewards = "/admin/events/:" + ParameterParticipationEventID + "/rewards"
// ParameterParticipationEventID is used to identify an event by its ID.
ParameterParticipationEventID = "eventID"
// ParameterAddress is used to identify an address.
ParameterAddress = "address"
// ParameterOutputID is used to identify an output ID.
ParameterOutputID = "outputID"
// ParameterMilestoneIndex is used to identify a milestone by index.
ParameterMilestoneIndex = "milestoneIndex"
)
func setupRoutes(group *echo.Group) {
group.GET(RouteParticipationEvents, func(c echo.Context) error {
resp, err := getEvents(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.POST(RouteAdminCreateEvent, func(c echo.Context) error {
resp, err := createEvent(c)
if err != nil {
return err
}
c.Response().Header().Set(echo.HeaderLocation, resp.EventID)
return httpserver.JSONResponse(c, http.StatusCreated, resp)
})
group.GET(RouteParticipationEvent, func(c echo.Context) error {
resp, err := getEvent(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.DELETE(RouteAdminDeleteEvent, func(c echo.Context) error {
if err := deleteEvent(c); err != nil {
return err
}
return c.NoContent(http.StatusNoContent)
})
group.GET(RouteParticipationEventStatus, func(c echo.Context) error {
resp, err := getEventStatus(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteOutputStatus, func(c echo.Context) error {
resp, err := getOutputStatus(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteAddressBech32Status, func(c echo.Context) error {
resp, err := getRewardsByAddress(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteAddressBech32Outputs, func(c echo.Context) error {
resp, err := getOutputsByAddress(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteAdminActiveParticipations, func(c echo.Context) error {
resp, err := getActiveParticipations(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteAdminPastParticipations, func(c echo.Context) error {
resp, err := getPastParticipations(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
group.GET(RouteAdminRewards, func(c echo.Context) error {
resp, err := getRewards(c)
if err != nil {
return err
}
return httpserver.JSONResponse(c, http.StatusOK, resp)
})
}