Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions go/coinstacks/mayachain/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type API struct {
httpClient *mayachain.HTTPClient
}

func New(cfg cosmossdk.Config, httpClient *mayachain.HTTPClient, wsClient *mayachain.WSClient, blockService *cosmossdk.BlockService, indexer *mayachain.AffiliateFeeIndexer, swaggerPath string, swaggeruiPath string, prometheus *metrics.Prometheus) *API {
func New(cfg cosmossdk.Config, httpClient *mayachain.HTTPClient, wsClient *mayachain.WSClient, blockService *cosmossdk.BlockService, swaggerPath string, swaggeruiPath string, prometheus *metrics.Prometheus) *API {
r := mux.NewRouter()

handler := &Handler{
Expand All @@ -76,7 +76,6 @@ func New(cfg cosmossdk.Config, httpClient *mayachain.HTTPClient, wsClient *mayac
HTTPClient: httpClient,
WSClient: wsClient,
},
indexer: indexer,
}

manager := websocket.NewManager(prometheus)
Expand Down Expand Up @@ -140,9 +139,6 @@ func New(cfg cosmossdk.Config, httpClient *mayachain.HTTPClient, wsClient *mayac
v1Gas := v1.PathPrefix("/gas").Subrouter()
v1Gas.HandleFunc("/estimate", a.EstimateGas).Methods("POST")

v1Affiliate := v1.PathPrefix("/affiliate").Subrouter()
v1Affiliate.HandleFunc("/fees", a.AffiliateFees).Methods("GET")

// proxy endpoints
r.PathPrefix("/lcd").HandlerFunc(a.LCD).Methods("GET")
r.PathPrefix("/rpc").HandlerFunc(a.RPC).Methods("GET", "POST")
Expand Down Expand Up @@ -243,45 +239,6 @@ func (a *API) EstimateGas(w http.ResponseWriter, r *http.Request) {
a.API.EstimateGas(w, r)
}

// swagger:parameters GetAffiliateFees
type GetAffiliateFeesParams struct {
// Start timestamp
// in: query
Start string `json:"start"`
// End timestamp
// in: query
End string `json:"end"`
}

// swagger:route Get /api/v1/affiliate/fees v1 GetAffiliateFees
//
// Get ss affiliate fee history.
//
// responses:
//
// 200: AffiliateFees
// 400: BadRequestError
// 500: InternalServerError
func (a *API) AffiliateFees(w http.ResponseWriter, r *http.Request) {
start, err := strconv.Atoi(r.URL.Query().Get("start"))
if err != nil {
start = 0
}

end, err := strconv.Atoi(r.URL.Query().Get("end"))
if err != nil {
end = int(time.Now().UnixMilli())
}

affiliateFees, err := a.handler.GetAffiliateFees(start, end)
if err != nil {
api.HandleError(w, http.StatusInternalServerError, err.Error())
return
}

api.HandleResponse(w, http.StatusOK, affiliateFees)
}

// swagger:route GET /lcd Proxy LCD
//
// Mayachain lcd rest api endpoints.
Expand Down
24 changes: 0 additions & 24 deletions go/coinstacks/mayachain/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

type Handler struct {
*mayachain.Handler
indexer *mayachain.AffiliateFeeIndexer
}

// Contains info about the running coinstack
Expand Down Expand Up @@ -52,29 +51,6 @@ func (h *Handler) GetTxHistory(pubkey string, cursor string, pageSize int) (api.
return mayachain.GetTxHistory(h.Handler, pubkey, cursor, pageSize)
}

// Contains info about affiliate fee history
// swagger:model AffiliateFees
type AffiliateFees struct {
// Affiliate fees
// required: true
Fees []*mayachain.AffiliateFee `json:"fees"`
}

func (h *Handler) GetAffiliateFees(start int, end int) (*AffiliateFees, error) {
fees := []*mayachain.AffiliateFee{}
for _, fee := range h.indexer.AffiliateFees {
if fee.Timestamp >= int64(start) && fee.Timestamp <= int64(end) {
fees = append(fees, fee)
}
}

a := &AffiliateFees{
Fees: fees,
}

return a, nil
}

func (h *Handler) ParseMessages(msgs []sdk.Msg, events cosmossdk.EventsByMsgIndex) []cosmossdk.Message {
return mayachain.ParseMessages(msgs, events)
}
Expand Down
99 changes: 0 additions & 99 deletions go/coinstacks/mayachain/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,51 +122,6 @@
}
}
},
"/api/v1/affiliate/fees": {
"get": {
"tags": [
"v1"
],
"summary": "Get ss affiliate fee history.",
"operationId": "GetAffiliateFees",
"parameters": [
{
"type": "string",
"x-go-name": "Start",
"description": "Start timestamp",
"name": "start",
"in": "query"
},
{
"type": "string",
"x-go-name": "End",
"description": "End timestamp",
"name": "end",
"in": "query"
}
],
"responses": {
"200": {
"description": "AffiliateFees",
"schema": {
"$ref": "#/definitions/AffiliateFees"
}
},
"400": {
"description": "BadRequestError",
"schema": {
"$ref": "#/definitions/BadRequestError"
}
},
"500": {
"description": "InternalServerError",
"schema": {
"$ref": "#/definitions/InternalServerError"
}
}
}
}
},
"/api/v1/gas/estimate": {
"post": {
"tags": [
Expand Down Expand Up @@ -384,60 +339,6 @@
],
"x-go-package": "github.com/shapeshift/unchained/coinstacks/mayachain/api"
},
"AffiliateFee": {
"type": "object",
"properties": {
"address": {
"type": "string",
"x-go-name": "Address"
},
"amount": {
"type": "string",
"x-go-name": "Amount"
},
"asset": {
"type": "string",
"x-go-name": "Asset"
},
"blockHash": {
"type": "string",
"x-go-name": "BlockHash"
},
"blockHeight": {
"type": "integer",
"format": "int64",
"x-go-name": "BlockHeight"
},
"timestamp": {
"type": "integer",
"format": "int64",
"x-go-name": "Timestamp"
},
"txId": {
"type": "string",
"x-go-name": "TxID"
}
},
"x-go-package": "github.com/shapeshift/unchained/pkg/mayachain"
},
"AffiliateFees": {
"description": "Contains info about affiliate fee history",
"type": "object",
"required": [
"fees"
],
"properties": {
"fees": {
"description": "Affiliate fees",
"type": "array",
"items": {
"$ref": "#/definitions/AffiliateFee"
},
"x-go-name": "Fees"
}
},
"x-go-package": "github.com/shapeshift/unchained/coinstacks/mayachain/api"
},
"ApiError": {
"description": "Generic api error for handling failed requests",
"type": "object",
Expand Down
7 changes: 1 addition & 6 deletions go/coinstacks/mayachain/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ func main() {
logger.Panicf("failed to create new websocket client: %+v", err)
}

indexer := mayachain.NewAffiliateFeeIndexer(httpClient, wsClient)
if err := indexer.Sync(); err != nil {
logger.Panicf("failed to index affiliate fees: %+v", err)
}

api := api.New(cfg.Config, httpClient, wsClient, blockService, indexer, *swaggerPath, *swaggeruiPath, prometheus)
api := api.New(cfg.Config, httpClient, wsClient, blockService, *swaggerPath, *swaggeruiPath, prometheus)
defer api.Shutdown()

go api.Serve(errChan)
Expand Down
85 changes: 1 addition & 84 deletions go/coinstacks/thorchain/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type API struct {
httpClient *thorchain.HTTPClient
}

func New(cfg thorchain.Config, httpClient *thorchain.HTTPClient, wsClient *thorchain.WSClient, blockService *cosmossdk.BlockService, indexer *thorchain.AffiliateFeeIndexer, swaggerPath string, swaggeruiPath string, prometheus *metrics.Prometheus) *API {
func New(cfg thorchain.Config, httpClient *thorchain.HTTPClient, wsClient *thorchain.WSClient, blockService *cosmossdk.BlockService, swaggerPath string, swaggeruiPath string, prometheus *metrics.Prometheus) *API {
r := mux.NewRouter()

handler := &Handler{
Expand All @@ -76,7 +76,6 @@ func New(cfg thorchain.Config, httpClient *thorchain.HTTPClient, wsClient *thorc
HTTPClient: httpClient,
WSClient: wsClient,
},
indexer: indexer,
}

manager := websocket.NewManager(prometheus)
Expand Down Expand Up @@ -140,10 +139,6 @@ func New(cfg thorchain.Config, httpClient *thorchain.HTTPClient, wsClient *thorc
v1Gas := v1.PathPrefix("/gas").Subrouter()
v1Gas.HandleFunc("/estimate", a.EstimateGas).Methods("POST")

v1Affiliate := v1.PathPrefix("/affiliate").Subrouter()
v1Affiliate.HandleFunc("/revenue", a.AffiliateRevenue).Methods("GET")
v1Affiliate.HandleFunc("/fees", a.AffiliateFees).Methods("GET")

// proxy endpoints
r.PathPrefix("/lcd").HandlerFunc(a.LCD).Methods("GET")
r.PathPrefix("/rpc").HandlerFunc(a.RPC).Methods("GET", "POST")
Expand Down Expand Up @@ -244,84 +239,6 @@ func (a *API) EstimateGas(w http.ResponseWriter, r *http.Request) {
a.API.EstimateGas(w, r)
}

// swagger:parameters GetAffiliateRevenue
type GetAffiliateRevenueParams struct {
// Start timestamp
// in: query
Start string `json:"start"`
// End timestamp
// in: query
End string `json:"end"`
}

// swagger:route Get /api/v1/affiliate/revenue v1 GetAffiliateRevenue
//
// Get total ss affiliate revenue earned.
//
// responses:
//
// 200: AffiliateRevenue
// 400: BadRequestError
// 500: InternalServerError
func (a *API) AffiliateRevenue(w http.ResponseWriter, r *http.Request) {
start, err := strconv.Atoi(r.URL.Query().Get("start"))
if err != nil {
start = 0
}

end, err := strconv.Atoi(r.URL.Query().Get("end"))
if err != nil {
end = int(time.Now().UnixMilli())
}

affiliateRevenue, err := a.handler.GetAffiliateRevenue(start, end)
if err != nil {
api.HandleError(w, http.StatusInternalServerError, err.Error())
return
}

api.HandleResponse(w, http.StatusOK, affiliateRevenue)
}

// swagger:parameters GetAffiliateFees
type GetAffiliateFeesParams struct {
// Start timestamp
// in: query
Start string `json:"start"`
// End timestamp
// in: query
End string `json:"end"`
}

// swagger:route Get /api/v1/affiliate/fees v1 GetAffiliateFees
//
// Get ss affiliate fee history.
//
// responses:
//
// 200: AffiliateFees
// 400: BadRequestError
// 500: InternalServerError
func (a *API) AffiliateFees(w http.ResponseWriter, r *http.Request) {
start, err := strconv.Atoi(r.URL.Query().Get("start"))
if err != nil {
start = 0
}

end, err := strconv.Atoi(r.URL.Query().Get("end"))
if err != nil {
end = int(time.Now().UnixMilli())
}

affiliateFees, err := a.handler.GetAffiliateFees(start, end)
if err != nil {
api.HandleError(w, http.StatusInternalServerError, err.Error())
return
}

api.HandleResponse(w, http.StatusOK, affiliateFees)
}

// swagger:route GET /lcd Proxy LCD
//
// Thorchain lcd rest api endpoints.
Expand Down
Loading
Loading