2023-01-27 07:58:37 -08:00
|
|
|
package wormscan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gofiber/fiber/v2/middleware/cache"
|
|
|
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
2023-04-12 11:51:33 -07:00
|
|
|
addrsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/address"
|
2023-01-27 07:58:37 -08:00
|
|
|
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"
|
2023-09-13 06:23:10 -07:00
|
|
|
relayssvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/relays"
|
2023-03-07 11:25:42 -08:00
|
|
|
trxsvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/transactions"
|
2023-01-27 07:58:37 -08:00
|
|
|
vaasvc "github.com/wormhole-foundation/wormhole-explorer/api/handlers/vaa"
|
2023-04-12 11:51:33 -07:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/address"
|
2023-01-27 07:58:37 -08:00
|
|
|
"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"
|
2023-09-13 06:23:10 -07:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/relays"
|
2023-03-07 11:25:42 -08:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/transactions"
|
2023-01-27 07:58:37 -08:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan/vaa"
|
2023-09-13 06:23:10 -07:00
|
|
|
|
2023-01-27 07:58:37 -08:00
|
|
|
"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,
|
2023-04-12 11:51:33 -07:00
|
|
|
addressService *addrsvc.Service,
|
2023-01-27 07:58:37 -08:00
|
|
|
vaaService *vaasvc.Service,
|
|
|
|
obsService *obssvc.Service,
|
|
|
|
governorService *govsvc.Service,
|
|
|
|
infrastructureService *infrasvc.Service,
|
2023-03-07 11:25:42 -08:00
|
|
|
transactionsService *trxsvc.Service,
|
2023-09-13 06:23:10 -07:00
|
|
|
relaysService *relayssvc.Service,
|
2023-01-27 07:58:37 -08:00
|
|
|
) {
|
|
|
|
|
|
|
|
// Set up controllers
|
2023-04-12 11:51:33 -07:00
|
|
|
addressCtrl := address.NewController(addressService, rootLogger)
|
2023-01-27 07:58:37 -08:00
|
|
|
vaaCtrl := vaa.NewController(vaaService, rootLogger)
|
|
|
|
observationsCtrl := observations.NewController(obsService, rootLogger)
|
|
|
|
governorCtrl := governor.NewController(governorService, rootLogger)
|
|
|
|
infrastructureCtrl := infrastructure.NewController(infrastructureService)
|
2023-03-07 11:25:42 -08:00
|
|
|
transactionCtrl := transactions.NewController(transactionsService, rootLogger)
|
2023-09-13 06:23:10 -07:00
|
|
|
relaysCtrl := relays.NewController(relaysService, rootLogger)
|
2023-01-27 07:58:37 -08:00
|
|
|
|
|
|
|
// 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)
|
2023-02-01 05:46:22 -08:00
|
|
|
api.Get("/version", infrastructureCtrl.Version)
|
2023-01-27 07:58:37 -08:00
|
|
|
|
2023-04-12 11:51:33 -07:00
|
|
|
// 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
|
2023-04-20 12:01:10 -07:00
|
|
|
api.Get("/global-tx/:chain/:emitter/:sequence", transactionCtrl.FindGlobalTransactionByID)
|
2023-03-07 11:25:42 -08:00
|
|
|
api.Get("/last-txs", transactionCtrl.GetLastTransactions)
|
2023-04-20 12:01:10 -07:00
|
|
|
api.Get("/scorecards", transactionCtrl.GetScorecards)
|
2023-03-07 11:25:42 -08:00
|
|
|
api.Get("/x-chain-activity", transactionCtrl.GetChainActivity)
|
2023-05-12 09:05:18 -07:00
|
|
|
api.Get("/top-assets-by-volume", transactionCtrl.GetTopAssets)
|
|
|
|
api.Get("/top-chain-pairs-by-num-transfers", transactionCtrl.GetTopChainPairs)
|
2023-05-31 06:29:16 -07:00
|
|
|
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)
|
2023-07-12 08:51:52 -07:00
|
|
|
api.Get("/transactions/:chain/:emitter/:sequence", transactionCtrl.GetTransactionByID)
|
2023-03-07 11:25:42 -08:00
|
|
|
|
2023-01-27 07:58:37 -08:00
|
|
|
// 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)
|
2023-08-10 07:02:14 -07:00
|
|
|
vaas.Post("/parse", vaaCtrl.ParseVaa)
|
2023-01-27 07:58:37 -08:00
|
|
|
|
|
|
|
// 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")
|
2023-02-10 09:31:33 -08:00
|
|
|
enqueueVaas.Get("/", governorCtrl.GetEnqueuedVaas)
|
2023-01-27 07:58:37 -08:00
|
|
|
enqueueVaas.Get("/:chain", governorCtrl.GetEnqueuedVaasByChainID)
|
2023-09-13 06:23:10 -07:00
|
|
|
|
|
|
|
relays := api.Group("/relays")
|
|
|
|
relays.Get("/:chain/:emitter/:sequence", relaysCtrl.FindOne)
|
2023-01-27 07:58:37 -08:00
|
|
|
}
|