-
Notifications
You must be signed in to change notification settings - Fork 1
/
bids.go
44 lines (38 loc) · 942 Bytes
/
bids.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
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/chainbing/node/api/parsers"
"github.com/chainbing/node/db/historydb"
)
func (a *API) getBids(c *gin.Context) {
filters, err := parsers.ParseBidsFilters(c, a.validate)
if err != nil {
retBadReq(&apiError{
Err: err,
Code: ErrParamValidationFailedCode,
Type: ErrParamValidationFailedType,
}, c)
return
}
bids, pendingItems, err := a.h.GetBidsAPI(historydb.GetBidsAPIRequest{
SlotNum: filters.SlotNum,
BidderAddr: filters.BidderAddr,
FromItem: filters.FromItem,
Limit: filters.Limit,
Order: filters.Order,
})
if err != nil {
retSQLErr(err, c)
return
}
// Build successful response
type bidsResponse struct {
Bids []historydb.BidAPI `json:"bids"`
PendingItems uint64 `json:"pendingItems"`
}
c.JSON(http.StatusOK, &bidsResponse{
Bids: bids,
PendingItems: pendingItems,
})
}