2022-05-14 10:15:45 +02:00
|
|
|
package public
|
|
|
|
|
|
|
|
import (
|
2022-05-19 08:52:34 +02:00
|
|
|
batch_balance "github.com/grassrootseconomics/cic-go/batch_balance"
|
2022-05-23 14:41:24 +02:00
|
|
|
cic_net "github.com/grassrootseconomics/cic-go/net"
|
2022-05-14 10:15:45 +02:00
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/nleof/goyesql"
|
|
|
|
)
|
|
|
|
|
|
|
|
type api struct {
|
|
|
|
db *pgxpool.Pool
|
|
|
|
q goyesql.Queries
|
2022-05-23 14:41:24 +02:00
|
|
|
bb *batch_balance.BatchBalance
|
|
|
|
cn *cic_net.CicNet
|
2022-05-14 10:15:45 +02:00
|
|
|
}
|
|
|
|
|
2022-05-23 14:41:24 +02:00
|
|
|
func InitPublicApi(e *echo.Echo, db *pgxpool.Pool, batchBalance *batch_balance.BatchBalance, cicnet *cic_net.CicNet, queries goyesql.Queries) {
|
2022-05-14 10:15:45 +02:00
|
|
|
g := e.Group("/public")
|
|
|
|
|
|
|
|
g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
c.Set("api", &api{
|
|
|
|
db: db,
|
|
|
|
q: queries,
|
2022-05-23 14:41:24 +02:00
|
|
|
cn: cicnet,
|
|
|
|
bb: batchBalance,
|
2022-05-14 10:15:45 +02:00
|
|
|
})
|
|
|
|
return next(c)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-19 15:24:26 +02:00
|
|
|
// TODO: paginate schema validation
|
|
|
|
|
2022-05-14 10:15:45 +02:00
|
|
|
g.GET("/balances/:address", handleBalancesQuery)
|
2022-05-19 15:24:26 +02:00
|
|
|
g.GET("/tokens-count", handleTokensCountQuery)
|
|
|
|
g.GET("/tokens", handleTokenListQuery)
|
2022-05-23 14:41:24 +02:00
|
|
|
g.GET("/token/:address", handleTokenInfo)
|
|
|
|
g.GET("/token-summary/:address", handleTokenSummary)
|
2022-05-14 10:15:45 +02:00
|
|
|
}
|