2022-06-01 15:12:15 +00:00
|
|
|
package builder
|
|
|
|
|
|
|
|
import (
|
2022-09-06 18:29:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/api/client/builder"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
|
2022-06-01 15:12:15 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Option func(s *Service) error
|
|
|
|
|
|
|
|
// FlagOptions for builder service flag configurations.
|
|
|
|
func FlagOptions(c *cli.Context) ([]Option, error) {
|
|
|
|
endpoint := c.String(flags.MevRelayEndpoint.Name)
|
2022-09-06 18:29:44 +00:00
|
|
|
var client *builder.Client
|
|
|
|
if endpoint != "" {
|
|
|
|
var err error
|
|
|
|
client, err = builder.NewClient(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 15:12:15 +00:00
|
|
|
opts := []Option{
|
2022-09-06 18:29:44 +00:00
|
|
|
WithBuilderClient(client),
|
2022-06-01 15:12:15 +00:00
|
|
|
}
|
|
|
|
return opts, nil
|
|
|
|
}
|
|
|
|
|
2022-09-06 18:29:44 +00:00
|
|
|
// WithBuilderClient sets the builder client for the beacon chain builder service.
|
|
|
|
func WithBuilderClient(client builder.BuilderClient) Option {
|
2022-06-01 15:12:15 +00:00
|
|
|
return func(s *Service) error {
|
2022-09-06 18:29:44 +00:00
|
|
|
s.cfg.builderClient = client
|
2022-06-01 15:12:15 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 20:44:27 +00:00
|
|
|
// WithHeadFetcher gets the head info from chain service.
|
2022-09-06 18:29:44 +00:00
|
|
|
func WithHeadFetcher(svc blockchain.HeadFetcher) Option {
|
2022-06-06 22:38:49 +00:00
|
|
|
return func(s *Service) error {
|
2022-06-23 20:44:27 +00:00
|
|
|
s.cfg.headFetcher = svc
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithDatabase for head access.
|
|
|
|
func WithDatabase(beaconDB db.HeadAccessDatabase) Option {
|
|
|
|
return func(s *Service) error {
|
|
|
|
s.cfg.beaconDB = beaconDB
|
2022-06-06 22:38:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|