2021-06-25 11:02:11 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/api"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/api/gateway"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/flags"
|
|
|
|
ethpbalpha "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
2021-06-25 11:02:11 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MuxConfig contains configuration that should be used when registering the beacon node in the gateway.
|
|
|
|
type MuxConfig struct {
|
2021-10-12 15:13:52 +00:00
|
|
|
EthPbMux *gateway.PbMux
|
|
|
|
V1AlphaPbMux *gateway.PbMux
|
2021-06-25 11:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultConfig returns a fully configured MuxConfig with standard gateway behavior.
|
2021-09-24 09:25:42 +00:00
|
|
|
func DefaultConfig(enableDebugRPCEndpoints bool, httpModules string) MuxConfig {
|
2021-10-12 15:13:52 +00:00
|
|
|
var v1AlphaPbHandler, ethPbHandler *gateway.PbMux
|
2021-09-24 09:25:42 +00:00
|
|
|
if flags.EnableHTTPPrysmAPI(httpModules) {
|
2021-10-12 15:13:52 +00:00
|
|
|
v1AlphaRegistrations := []gateway.PbHandlerRegistration{
|
2021-09-24 09:25:42 +00:00
|
|
|
ethpbalpha.RegisterNodeHandler,
|
|
|
|
ethpbalpha.RegisterBeaconChainHandler,
|
|
|
|
ethpbalpha.RegisterBeaconNodeValidatorHandler,
|
|
|
|
ethpbalpha.RegisterHealthHandler,
|
|
|
|
}
|
|
|
|
if enableDebugRPCEndpoints {
|
2021-10-12 15:13:52 +00:00
|
|
|
v1AlphaRegistrations = append(v1AlphaRegistrations, ethpbalpha.RegisterDebugHandler)
|
2021-09-24 09:25:42 +00:00
|
|
|
}
|
2021-10-12 15:13:52 +00:00
|
|
|
v1AlphaMux := gwruntime.NewServeMux(
|
2021-09-24 09:25:42 +00:00
|
|
|
gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.HTTPBodyMarshaler{
|
|
|
|
Marshaler: &gwruntime.JSONPb{
|
|
|
|
MarshalOptions: protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
},
|
|
|
|
UnmarshalOptions: protojson.UnmarshalOptions{
|
|
|
|
DiscardUnknown: true,
|
|
|
|
},
|
2021-06-25 11:02:11 +00:00
|
|
|
},
|
2021-09-24 09:25:42 +00:00
|
|
|
}),
|
|
|
|
gwruntime.WithMarshalerOption(
|
2024-01-18 14:27:41 +00:00
|
|
|
api.EventStreamMediaType, &gwruntime.EventSourceJSONPb{},
|
2021-09-24 09:25:42 +00:00
|
|
|
),
|
|
|
|
)
|
2021-10-12 15:13:52 +00:00
|
|
|
v1AlphaPbHandler = &gateway.PbMux{
|
|
|
|
Registrations: v1AlphaRegistrations,
|
|
|
|
Patterns: []string{"/eth/v1alpha1/", "/eth/v1alpha2/"},
|
|
|
|
Mux: v1AlphaMux,
|
2021-09-24 09:25:42 +00:00
|
|
|
}
|
2021-06-25 11:02:11 +00:00
|
|
|
}
|
2021-09-24 09:25:42 +00:00
|
|
|
if flags.EnableHTTPEthAPI(httpModules) {
|
2023-11-28 23:20:02 +00:00
|
|
|
ethRegistrations := []gateway.PbHandlerRegistration{}
|
2021-09-24 09:25:42 +00:00
|
|
|
ethMux := gwruntime.NewServeMux(
|
|
|
|
gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.HTTPBodyMarshaler{
|
|
|
|
Marshaler: &gwruntime.JSONPb{
|
|
|
|
MarshalOptions: protojson.MarshalOptions{
|
|
|
|
UseProtoNames: true,
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
},
|
|
|
|
UnmarshalOptions: protojson.UnmarshalOptions{
|
|
|
|
DiscardUnknown: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
ethPbHandler = &gateway.PbMux{
|
|
|
|
Registrations: ethRegistrations,
|
|
|
|
Patterns: []string{"/internal/eth/v1/", "/internal/eth/v2/"},
|
|
|
|
Mux: ethMux,
|
|
|
|
}
|
2021-06-25 11:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MuxConfig{
|
2021-10-12 15:13:52 +00:00
|
|
|
EthPbMux: ethPbHandler,
|
|
|
|
V1AlphaPbMux: v1AlphaPbHandler,
|
2021-06-25 11:02:11 +00:00
|
|
|
}
|
|
|
|
}
|