diff --git a/client/simple.go b/client/simple.go index 6079da3..8879743 100644 --- a/client/simple.go +++ b/client/simple.go @@ -8,6 +8,11 @@ import ( "net/http" ) +var ( + // 503 error type informing rollup to failover to other DA location + ErrServiceUnavailable = fmt.Errorf("eigenda service is unavailable") +) + // TODO: Add support for custom http client option type Config struct { URL string @@ -81,7 +86,8 @@ func (c *SimpleCommitmentClient) GetData(ctx context.Context, comm []byte) ([]by return b, nil } -// SetData writes raw byte data to DA and returns the respective certificate +// SetData writes raw byte data to DA and returns the associated certificate +// which should be verified within the proxy 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)) @@ -100,6 +106,10 @@ func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte, return nil, err } + if resp.StatusCode == http.StatusServiceUnavailable { + return nil, ErrServiceUnavailable + } + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to store data: %v, err = %s", resp.StatusCode, string(b)) }