Skip to content

Commit

Permalink
closed the response body
Browse files Browse the repository at this point in the history
  • Loading branch information
chandiniv1 committed Aug 23, 2023
1 parent 0712600 commit 6243a29
Showing 1 changed file with 3 additions and 48 deletions.
51 changes: 3 additions & 48 deletions da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,6 @@ func (c *DataAvailabilityLayerClient) SubmitBlocks(ctx context.Context, blocks [

}

// CheckBlockAvailability queries DA layer to check data availability of block.
func (c *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context, dataLayerHeight uint64) da.ResultCheckBlock {

blockNumber := dataLayerHeight
confidenceURL := fmt.Sprintf(c.config.BaseURL+"/confidence/%d", blockNumber)

response, err := http.Get(confidenceURL)
if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: err.Error(),
},
}
}
defer response.Body.Close()

responseData, err := io.ReadAll(response.Body)
if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: err.Error(),
},
}
}

var confidenceObject Confidence
err = json.Unmarshal(responseData, &confidenceObject)
if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: err.Error(),
},
}
}

return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
DAHeight: uint64(confidenceObject.Block),
},
DataAvailable: confidenceObject.Confidence > float64(c.config.Confidence),
}
}

// RetrieveBlocks gets the block from DA layer.

func (c *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, dataLayerHeight uint64) da.ResultRetrieveBlocks {
Expand All @@ -171,7 +124,9 @@ func (c *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, dataLa
},
}
}
defer response.Body.Close()
defer func() {
_ = response.Body.Close()
}()

responseData, err := io.ReadAll(response.Body)
if err != nil {
Expand Down

0 comments on commit 6243a29

Please sign in to comment.