Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename client -> SimpleCommitmentClient and add comments #201

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,26 @@ type Config struct {
URL string
}

// ProxyClient is an interface for communicating with the EigenDA proxy server
type ProxyClient interface {
Health() error
GetData(ctx context.Context, cert []byte) ([]byte, error)
SetData(ctx context.Context, b []byte) ([]byte, error)
}

// client is the implementation of ProxyClient
type client struct {
// SimpleCommitmentClient implements a simple client for the eigenda-proxy
// that can put/get simple commitment data and query the health endpoint.
// It is meant to be used by arbitrum nitro integrations.
// Optimism has its own client: https://github.com/ethereum-optimism/optimism/blob/develop/op-alt-da/daclient.go
// so clients wanting to send op commitment mode data should use that client.
type SimpleCommitmentClient struct {
cfg *Config
httpClient *http.Client
}

var _ ProxyClient = (*client)(nil)

func New(cfg *Config) ProxyClient {
return &client{
func New(cfg *Config) *SimpleCommitmentClient {
return &SimpleCommitmentClient{
cfg,
http.DefaultClient,
}
}

// Health indicates if the server is operational; useful for event based awaits
// when integration testing
func (c *client) Health() error {
func (c *SimpleCommitmentClient) Health() error {
url := c.cfg.URL + "/health"
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil {
Expand All @@ -58,7 +53,7 @@ func (c *client) Health() error {
}

// GetData fetches blob data associated with a DA certificate
func (c *client) GetData(ctx context.Context, comm []byte) ([]byte, error) {
func (c *SimpleCommitmentClient) GetData(ctx context.Context, comm []byte) ([]byte, error) {
url := fmt.Sprintf("%s/get/0x%x?commitment_mode=simple", c.cfg.URL, comm)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
Expand Down Expand Up @@ -87,7 +82,7 @@ func (c *client) GetData(ctx context.Context, comm []byte) ([]byte, error) {
}

// SetData writes raw byte data to DA and returns the respective certificate
func (c *client) SetData(ctx context.Context, b []byte) ([]byte, error) {
func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte, error) {
url := fmt.Sprintf("%s/put?commitment_mode=simple", c.cfg.URL)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(b))
if err != nil {
Expand Down
Loading