@@ -3,7 +3,6 @@ package blob_client
33import (
44 "context"
55 "crypto/sha256"
6- "encoding/hex"
76 "encoding/json"
87 "fmt"
98 "io"
@@ -37,11 +36,13 @@ func NewBeaconNodeClient(apiEndpoint string, l1Client *rollup_sync_service.L1Cli
3736 return nil , fmt .Errorf ("cannot do request, err: %w" , err )
3837 }
3938 defer resp .Body .Close ()
39+
4040 if resp .StatusCode != http .StatusOK {
4141 body , _ := io .ReadAll (resp .Body )
4242 bodyStr := string (body )
4343 return nil , fmt .Errorf ("beacon node request failed, status: %s, body: %s" , resp .Status , bodyStr )
4444 }
45+
4546 var genesisResp GenesisResp
4647 err = json .NewDecoder (resp .Body ).Decode (& genesisResp )
4748 if err != nil {
@@ -59,11 +60,13 @@ func NewBeaconNodeClient(apiEndpoint string, l1Client *rollup_sync_service.L1Cli
5960 return nil , fmt .Errorf ("cannot do request, err: %w" , err )
6061 }
6162 defer resp .Body .Close ()
63+
6264 if resp .StatusCode != http .StatusOK {
6365 body , _ := io .ReadAll (resp .Body )
6466 bodyStr := string (body )
6567 return nil , fmt .Errorf ("beacon node request failed, status: %s, body: %s" , resp .Status , bodyStr )
6668 }
69+
6770 var specResp SpecResp
6871 err = json .NewDecoder (resp .Body ).Decode (& specResp )
6972 if err != nil {
@@ -100,11 +103,13 @@ func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Cont
100103 return nil , fmt .Errorf ("cannot do request, err: %w" , err )
101104 }
102105 defer resp .Body .Close ()
106+
103107 if resp .StatusCode != http .StatusOK {
104108 body , _ := io .ReadAll (resp .Body )
105109 bodyStr := string (body )
106110 return nil , fmt .Errorf ("beacon node request failed, status: %s, body: %s" , resp .Status , bodyStr )
107111 }
112+
108113 var blobSidecarResp BlobSidecarResp
109114 err = json .NewDecoder (resp .Body ).Decode (& blobSidecarResp )
110115 if err != nil {
@@ -114,26 +119,22 @@ func (c *BeaconNodeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Cont
114119 // find blob with desired versionedHash
115120 for _ , blob := range blobSidecarResp .Data {
116121 // calculate blob hash from commitment and check it with desired
117- commitmentBytes , err := hex .DecodeString (blob .KzgCommitment [2 :])
118- if err != nil {
119- return nil , fmt .Errorf ("failed to decode data to bytes, err: %w" , err )
120- }
121- if len (commitmentBytes ) != lenKzgCommitment {
122- return nil , fmt .Errorf ("len of kzg commitment is not correct, expected: %d, got: %d" , lenKzgCommitment , len (commitmentBytes ))
122+ commitmentBytes := common .FromHex (blob .KzgCommitment )
123+ if len (commitmentBytes ) != lenKZGCommitment {
124+ return nil , fmt .Errorf ("len of kzg commitment is not correct, expected: %d, got: %d" , lenKZGCommitment , len (commitmentBytes ))
123125 }
124126 commitment := kzg4844 .Commitment (commitmentBytes )
125127 blobVersionedHash := kzg4844 .CalcBlobHashV1 (sha256 .New (), & commitment )
128+
126129 if blobVersionedHash == versionedHash {
127130 // found desired blob
128- blobBytes , err := hex .DecodeString (blob .Blob [2 :])
129- if err != nil {
130- return nil , fmt .Errorf ("failed to decode data to bytes, err: %w" , err )
131- }
131+ blobBytes := common .FromHex (blob .Blob )
132132 if len (blobBytes ) != lenBlobBytes {
133133 return nil , fmt .Errorf ("len of blob data is not correct, expected: %d, got: %d" , lenBlobBytes , len (blobBytes ))
134134 }
135- blob := kzg4844 .Blob (blobBytes )
136- return & blob , nil
135+
136+ b := kzg4844 .Blob (blobBytes )
137+ return & b , nil
137138 }
138139 }
139140
0 commit comments