wormhole-explorer/api/routes/wormscan/routes.go

151 lines
6.7 KiB
Go
Raw Normal View History

package wormscan
import (
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/cors"
addrsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/address"
govsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/governor"
infrasvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/infrastructure"
obssvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/observations"
opsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/operations"
[Issue:1052] Create job for fetching contributor stats and storing in db (#1144) * [Issue:1052] Create job for fetching contributor stats and storing in db revert unnecessary changes on api/handlers/stats revert changes in go.mod and go.sum revert change in go.work add schedule for contributors stats job change response parsing order changes due to draft-pr review move on with contributors activity implementation change to every hour fix typo change contributor stats implementation to do a single write transaction normalize to UTC contributors activity timestamp add cronjob schedule for contributors [Issue:1052][Part 2] Create endpoint to expose contributors stats and activities (#1123) * add endpoint for retrieving stats and activity * remove model.go file and move types to service file * add unit tests to contributors service * integrate new contributors controller * fix more stuff fix unit-tests changes due to pr review fix query fix unit-tests fix total_value_secure move constantes to common pkg remove extra changes rename contributor to protocols finish renames Changes for deployment adjust different response types from different protocols contributors fix controller test big refactor in activty job and stats job since protocols are returning different formats api responding fine remove uneccessary generics target dbconsts fix Delete deploy/common/env/staging-mainnet.env undo unwanted changes readd staging-mainnet.env fix unit-tests add missing protocols_stats/activity_version remove property protocols_json fix JOB_ID env var in protocols-activity.yaml fix typos in env vars configs change tu numbers changes due to own review add new line * add swagger docs
2024-02-22 09:58:45 -08:00
protocolssvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/protocols"
relayssvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/relays"
statssvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/stats"
trxsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/transactions"
vaasvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/vaa"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/address"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/governor"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/infrastructure"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/observations"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/operations"
[Issue:1052] Create job for fetching contributor stats and storing in db (#1144) * [Issue:1052] Create job for fetching contributor stats and storing in db revert unnecessary changes on api/handlers/stats revert changes in go.mod and go.sum revert change in go.work add schedule for contributors stats job change response parsing order changes due to draft-pr review move on with contributors activity implementation change to every hour fix typo change contributor stats implementation to do a single write transaction normalize to UTC contributors activity timestamp add cronjob schedule for contributors [Issue:1052][Part 2] Create endpoint to expose contributors stats and activities (#1123) * add endpoint for retrieving stats and activity * remove model.go file and move types to service file * add unit tests to contributors service * integrate new contributors controller * fix more stuff fix unit-tests changes due to pr review fix query fix unit-tests fix total_value_secure move constantes to common pkg remove extra changes rename contributor to protocols finish renames Changes for deployment adjust different response types from different protocols contributors fix controller test big refactor in activty job and stats job since protocols are returning different formats api responding fine remove uneccessary generics target dbconsts fix Delete deploy/common/env/staging-mainnet.env undo unwanted changes readd staging-mainnet.env fix unit-tests add missing protocols_stats/activity_version remove property protocols_json fix JOB_ID env var in protocols-activity.yaml fix typos in env vars configs change tu numbers changes due to own review add new line * add swagger docs
2024-02-22 09:58:45 -08:00
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/protocols"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/relays"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/stats"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/transactions"
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/vaa"
"go.uber.org/zap"
)
var cacheConfig = cache.Config{
Next: func(c *fiber.Ctx) bool {
return c.Query("refresh") == "true"
},
Expiration: 1 * time.Second,
CacheControl: true,
StoreResponseHeaders: true,
}
// RegisterRoutes sets up the handlers for the Wormscan API.
func RegisterRoutes(
app *fiber.App,
rootLogger *zap.Logger,
addressService *addrsvc.Service,
vaaService *vaasvc.Service,
obsService *obssvc.Service,
governorService *govsvc.Service,
infrastructureService *infrasvc.Service,
transactionsService *trxsvc.Service,
relaysService *relayssvc.Service,
operationsService *opsvc.Service,
statsService *statssvc.Service,
[Issue:1052] Create job for fetching contributor stats and storing in db (#1144) * [Issue:1052] Create job for fetching contributor stats and storing in db revert unnecessary changes on api/handlers/stats revert changes in go.mod and go.sum revert change in go.work add schedule for contributors stats job change response parsing order changes due to draft-pr review move on with contributors activity implementation change to every hour fix typo change contributor stats implementation to do a single write transaction normalize to UTC contributors activity timestamp add cronjob schedule for contributors [Issue:1052][Part 2] Create endpoint to expose contributors stats and activities (#1123) * add endpoint for retrieving stats and activity * remove model.go file and move types to service file * add unit tests to contributors service * integrate new contributors controller * fix more stuff fix unit-tests changes due to pr review fix query fix unit-tests fix total_value_secure move constantes to common pkg remove extra changes rename contributor to protocols finish renames Changes for deployment adjust different response types from different protocols contributors fix controller test big refactor in activty job and stats job since protocols are returning different formats api responding fine remove uneccessary generics target dbconsts fix Delete deploy/common/env/staging-mainnet.env undo unwanted changes readd staging-mainnet.env fix unit-tests add missing protocols_stats/activity_version remove property protocols_json fix JOB_ID env var in protocols-activity.yaml fix typos in env vars configs change tu numbers changes due to own review add new line * add swagger docs
2024-02-22 09:58:45 -08:00
protocolsService *protocolssvc.Service,
) {
// Set up controllers
addressCtrl := address.NewController(addressService, rootLogger)
vaaCtrl := vaa.NewController(vaaService, rootLogger)
observationsCtrl := observations.NewController(obsService, rootLogger)
governorCtrl := governor.NewController(governorService, rootLogger)
infrastructureCtrl := infrastructure.NewController(infrastructureService)
transactionCtrl := transactions.NewController(transactionsService, rootLogger)
relaysCtrl := relays.NewController(relaysService, rootLogger)
opsCtrl := operations.NewController(operationsService, rootLogger)
[Issue:1052] Create job for fetching contributor stats and storing in db (#1144) * [Issue:1052] Create job for fetching contributor stats and storing in db revert unnecessary changes on api/handlers/stats revert changes in go.mod and go.sum revert change in go.work add schedule for contributors stats job change response parsing order changes due to draft-pr review move on with contributors activity implementation change to every hour fix typo change contributor stats implementation to do a single write transaction normalize to UTC contributors activity timestamp add cronjob schedule for contributors [Issue:1052][Part 2] Create endpoint to expose contributors stats and activities (#1123) * add endpoint for retrieving stats and activity * remove model.go file and move types to service file * add unit tests to contributors service * integrate new contributors controller * fix more stuff fix unit-tests changes due to pr review fix query fix unit-tests fix total_value_secure move constantes to common pkg remove extra changes rename contributor to protocols finish renames Changes for deployment adjust different response types from different protocols contributors fix controller test big refactor in activty job and stats job since protocols are returning different formats api responding fine remove uneccessary generics target dbconsts fix Delete deploy/common/env/staging-mainnet.env undo unwanted changes readd staging-mainnet.env fix unit-tests add missing protocols_stats/activity_version remove property protocols_json fix JOB_ID env var in protocols-activity.yaml fix typos in env vars configs change tu numbers changes due to own review add new line * add swagger docs
2024-02-22 09:58:45 -08:00
statsCtrl := stats.NewController(statsService, rootLogger)
contributorsCtrl := protocols.NewController(rootLogger, protocolsService)
// Set up route handlers
api := app.Group("/api/v1")
api.Use(cors.New()) // TODO CORS restrictions?
// monitoring
api.Get("/health", infrastructureCtrl.HealthCheck)
api.Get("/ready", infrastructureCtrl.ReadyCheck)
api.Get("/version", infrastructureCtrl.Version)
// accounts resource
api.Get("/address/:id", addressCtrl.FindById)
Add endpoint `GET /api/v1/transactions` (#388) ### Summary Tracking issue: https://github.com/wormhole-foundation/wormhole-explorer/issues/385 This pull request implements a new endpoint, `GET /api/v1/transactions`, which will be consumed by the wormhole explorer UI. The endpoint returns a paginated list of transactions, in which each element contains a brief overview of the transaction (ID, txHash, status, etc.). It exposes offset-based pagination via the parameters `page` and `pageSize`. Also, results can be obtained for a specific address by using the `address` query parameter. The response model looks like this: ```json { "transactions": [ { "id": "1/5ec18c34b47c63d17ab43b07b9b2319ea5ee2d163bce2e467000174e238c8e7f/12965", "timestamp": "2023-06-08T19:30:19Z", "txHash": "a302c4ab2d6b9a6003951d2e91f8fdbb83cfa20f6ffb588b95ef0290aab37066", "originChain": 1, "status": "ongoing" }, { "id": "22/0000000000000000000000000000000000000000000000000000000000000001/18308", "timestamp": "2023-06-08T19:17:14Z", "txHash": "00000000000000000000000000000000000000000000000000000000000047e7", "originChain": 22, "destinationAddress": "0x00000000000000000000000067e8a40816a983fbe3294aaebd0cc2391815b86b", "destinationChain": 5, "tokenAmount": "0.12", "usdAmount": "0.12012", "symbol": "USDC", "status": "completed" }, ... ] } ``` ### Limitations of the current implementation 1. Doesn't return the total number of results (this may result in a performance issue when we filter by address) 2. Can only filter by receiver address (we don't have sender information in the database yet)
2023-06-12 07:43:48 -07:00
// analytics, transactions, custom endpoints
api.Get("/global-tx/:chain/:emitter/:sequence", transactionCtrl.FindGlobalTransactionByID)
api.Get("/last-txs", transactionCtrl.GetLastTransactions)
api.Get("/scorecards", transactionCtrl.GetScorecards)
api.Get("/x-chain-activity", transactionCtrl.GetChainActivity)
2024-04-25 05:49:55 -07:00
api.Get("/x-chain-activity/tops", transactionCtrl.GetChainActivityTops)
api.Get("/top-assets-by-volume", transactionCtrl.GetTopAssets)
api.Get("/top-chain-pairs-by-num-transfers", transactionCtrl.GetTopChainPairs)
api.Get("token/:chain/:token_address", transactionCtrl.GetTokenByChainAndAddress)
Add endpoint `GET /api/v1/transactions` (#388) ### Summary Tracking issue: https://github.com/wormhole-foundation/wormhole-explorer/issues/385 This pull request implements a new endpoint, `GET /api/v1/transactions`, which will be consumed by the wormhole explorer UI. The endpoint returns a paginated list of transactions, in which each element contains a brief overview of the transaction (ID, txHash, status, etc.). It exposes offset-based pagination via the parameters `page` and `pageSize`. Also, results can be obtained for a specific address by using the `address` query parameter. The response model looks like this: ```json { "transactions": [ { "id": "1/5ec18c34b47c63d17ab43b07b9b2319ea5ee2d163bce2e467000174e238c8e7f/12965", "timestamp": "2023-06-08T19:30:19Z", "txHash": "a302c4ab2d6b9a6003951d2e91f8fdbb83cfa20f6ffb588b95ef0290aab37066", "originChain": 1, "status": "ongoing" }, { "id": "22/0000000000000000000000000000000000000000000000000000000000000001/18308", "timestamp": "2023-06-08T19:17:14Z", "txHash": "00000000000000000000000000000000000000000000000000000000000047e7", "originChain": 22, "destinationAddress": "0x00000000000000000000000067e8a40816a983fbe3294aaebd0cc2391815b86b", "destinationChain": 5, "tokenAmount": "0.12", "usdAmount": "0.12012", "symbol": "USDC", "status": "completed" }, ... ] } ``` ### Limitations of the current implementation 1. Doesn't return the total number of results (this may result in a performance issue when we filter by address) 2. Can only filter by receiver address (we don't have sender information in the database yet)
2023-06-12 07:43:48 -07:00
api.Get("/transactions", transactionCtrl.ListTransactions)
api.Get("/transactions/:chain/:emitter/:sequence", transactionCtrl.GetTransactionByID)
// stats custom endpoints
[Issue:1052] Create job for fetching contributor stats and storing in db (#1144) * [Issue:1052] Create job for fetching contributor stats and storing in db revert unnecessary changes on api/handlers/stats revert changes in go.mod and go.sum revert change in go.work add schedule for contributors stats job change response parsing order changes due to draft-pr review move on with contributors activity implementation change to every hour fix typo change contributor stats implementation to do a single write transaction normalize to UTC contributors activity timestamp add cronjob schedule for contributors [Issue:1052][Part 2] Create endpoint to expose contributors stats and activities (#1123) * add endpoint for retrieving stats and activity * remove model.go file and move types to service file * add unit tests to contributors service * integrate new contributors controller * fix more stuff fix unit-tests changes due to pr review fix query fix unit-tests fix total_value_secure move constantes to common pkg remove extra changes rename contributor to protocols finish renames Changes for deployment adjust different response types from different protocols contributors fix controller test big refactor in activty job and stats job since protocols are returning different formats api responding fine remove uneccessary generics target dbconsts fix Delete deploy/common/env/staging-mainnet.env undo unwanted changes readd staging-mainnet.env fix unit-tests add missing protocols_stats/activity_version remove property protocols_json fix JOB_ID env var in protocols-activity.yaml fix typos in env vars configs change tu numbers changes due to own review add new line * add swagger docs
2024-02-22 09:58:45 -08:00
api.Get("/top-symbols-by-volume", statsCtrl.GetTopSymbolsByVolume)
api.Get("/top-100-corridors", statsCtrl.GetTopCorridors)
api.Get("/protocols/stats", contributorsCtrl.GetProtocolsTotalValues)
// operations resource
operations := api.Group("/operations")
operations.Get("/", opsCtrl.FindAll)
operations.Get("/:chain/:emitter/:sequence", opsCtrl.FindById)
// vaas resource
vaas := api.Group("/vaas")
vaas.Use(cache.New(cacheConfig))
vaas.Get("/vaa-counts", vaaCtrl.GetVaaCount)
vaas.Get("/", vaaCtrl.FindAll)
vaas.Get("/:chain", vaaCtrl.FindByChain)
vaas.Get("/:chain/:emitter", vaaCtrl.FindByEmitter)
vaas.Get("/:chain/:emitter/:sequence", vaaCtrl.FindById)
vaas.Get("/:chain/:emitter/:sequence/duplicated", vaaCtrl.FindDuplicatedById)
vaas.Post("/parse", vaaCtrl.ParseVaa)
// oservations resource
observations := api.Group("/observations")
observations.Get("/", observationsCtrl.FindAll)
observations.Get("/:chain", observationsCtrl.FindAllByChain)
observations.Get("/:chain/:emitter", observationsCtrl.FindAllByEmitter)
observations.Get("/:chain/:emitter/:sequence", observationsCtrl.FindAllByVAA)
observations.Get("/:chain/:emitter/:sequence/:signer/:hash", observationsCtrl.FindOne)
// governor resources
governor := api.Group("/governor")
governorLimit := governor.Group("/limit")
governorLimit.Get("/", governorCtrl.GetGovernorLimit)
governorConfigs := governor.Group("/config")
governorConfigs.Get("/", governorCtrl.FindGovernorConfigurations)
governorConfigs.Get("/:guardian_address", governorCtrl.FindGovernorConfigurationByGuardianAddress)
governorStatus := governor.Group("/status")
governorStatus.Get("/", governorCtrl.FindGovernorStatus)
governorStatus.Get("/:guardian_address", governorCtrl.FindGovernorStatusByGuardianAddress)
governorNotional := governor.Group("/notional")
governorNotional.Get("/limit/", governorCtrl.FindNotionalLimit)
governorNotional.Get("/limit/:chain", governorCtrl.GetNotionalLimitByChainID)
governorNotional.Get("/available/", governorCtrl.GetAvailableNotional)
governorNotional.Get("/available/:chain", governorCtrl.GetAvailableNotionalByChainID)
governorNotional.Get("/max_available/:chain", governorCtrl.GetMaxNotionalAvailableByChainID)
enqueueVaas := governor.Group("/enqueued_vaas")
enqueueVaas.Get("/", governorCtrl.GetEnqueuedVaas)
enqueueVaas.Get("/:chain", governorCtrl.GetEnqueuedVaasByChainID)
relays := api.Group("/relays")
relays.Get("/:chain/:emitter/:sequence", relaysCtrl.FindOne)
}