Skip to content

Commit

Permalink
refactor: rename client -> SimpleCommitmentClient and add comments (#201
Browse files Browse the repository at this point in the history
)

* refactor: rename client -> SimpleCommitmentClient and add comments

* style: rename client/client.go -> client/simple.go
  • Loading branch information
samlaf authored Nov 20, 2024
1 parent 315910f commit 0121434
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions client/client.go → client/simple.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

0 comments on commit 0121434

Please sign in to comment.