Comments (1)
package http
import (
"context"
"math/big"
"net/http"
"os"
"github.com/ethereum/go-ethereum/core/types"
"github.com/labstack/echo/v4/middleware"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/taikol2"
echo "github.com/labstack/echo/v4"
)
type ethClient interface {
BlockNumber(ctx context.Context) (uint64, error)
ChainID(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
}
// @title Taiko Relayer API
// @Version 1.0
// @termsofservice http://swagger.io/terms/
// @contact.name API Support
// @contact.url https://community.taiko.xyz/
// @contact.email [email protected]
// @license.name MIT
// @host relayer.katla.taiko.xyz
// Server represents an relayer http server instance.
type Server struct {
echo *echo.Echo
eventRepo relayer.EventRepository
srcEthClient ethClient
destEthClient ethClient
processingFeeMultiplier float64
taikoL2 *taikol2.TaikoL2
}
type NewServerOpts struct {
Echo *echo.Echo
EventRepo relayer.EventRepository
CorsOrigins []string
SrcEthClient ethClient
DestEthClient ethClient
ProcessingFeeMultiplier float64
TaikoL2 *taikol2.TaikoL2
}
func (opts NewServerOpts) Validate() error {
if opts.Echo == nil {
return ErrNoHTTPFramework
}
if opts.EventRepo == nil {
return relayer.ErrNoEventRepository
}
if opts.CorsOrigins == nil {
return relayer.ErrNoCORSOrigins
}
if opts.SrcEthClient == nil {
return relayer.ErrNoEthClient
}
if opts.DestEthClient == nil {
return relayer.ErrNoEthClient
}
return nil
}
func NewServer(opts NewServerOpts) (*Server, error) {
if err := opts.Validate(); err != nil {
return nil, err
}
srv := &Server{
echo: opts.Echo,
eventRepo: opts.EventRepo,
srcEthClient: opts.SrcEthClient,
destEthClient: opts.DestEthClient,
processingFeeMultiplier: opts.ProcessingFeeMultiplier,
taikoL2: opts.TaikoL2,
}
corsOrigins := opts.CorsOrigins
if corsOrigins == nil {
corsOrigins = []string{"*"}
}
srv.configureMiddleware(corsOrigins)
srv.configureRoutes()
return srv, nil
}
// Start starts the HTTP server
func (srv *Server) Start(address string) error {
return srv.echo.Start(address)
}
// Shutdown shuts down the HTTP server
func (srv *Server) Shutdown(ctx context.Context) error {
return srv.echo.Shutdown(ctx)
}
// ServeHTTP implements the http.Handler
interface which serves HTTP requests
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
srv.echo.ServeHTTP(w, r)
}
// Health endpoints for probes
func (srv *Server) Health(c echo.Context) error {
return c.NoContent(http.StatusOK)
}
func LogSkipper(c echo.Context) bool {
switch c.Request().URL.Path {
case "/healthz":
return true
case "/metrics":
return true
default:
return true
}
}
func (srv *Server) configureMiddleware(corsOrigins []string) {
srv.echo.Use(middleware.RequestID())
srv.echo.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Skipper: LogSkipper,
Format: `{"time":"${time_rfc3339_nano}","level":"INFO","message":{"id":"${id}","remote_ip":"${remote_ip}",` + //nolint:lll
`"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` + //nolint:lll
`"response_status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}",` +
`"bytes_in":${bytes_in},"bytes_out":${bytes_out}}}` + "\n",
Output: os.Stdout,
}))
srv.echo.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: corsOrigins,
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
AllowMethods: []string{http.MethodGet, http.MethodHead},
}))
}
from taiko-mono.
Related Issues (20)
- RPC ERROR
- RPC didn't work HOT 1
- Error when deploying smart contract HOT 7
- Trustwallet erreur HOT 1
- explication du projet HOT 1
- Mục đích sử dụng
- airdrop
- i think my account is bugged for airdrop eligbility.
- Side bar (right) not showing information information
- Taiko
- Wallet not eligble HOT 1
- transaction taking to long HOT 3
- Steps Appear Incomplete After Register your wallet Process on Trailblazers Website HOT 2
- bridge relayer did not pick up a message HOT 3
- bridge UI should show both source and destination transactions HOT 3
- feat(taiko-client): specific `txmgr`'s log HOT 1
- feat(taiko-client): choose cheaper way to `proposeBlock`(calldata or blob)
- feat(taiko-client): use estimated blob price instead of bumping HOT 1
- feat(taiko-client): introduce AccountAccessList
- High Gas Fees Issues: Write Contract Burn on TaikoScan. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taiko-mono.