@@ -105,15 +105,31 @@ func NewBeaconNodeClient(apiEndpoint string) (*BeaconNodeClient, error) {
105105 }, nil
106106}
107107
108+ func (c * BeaconNodeClient ) getBlobsPath (slot uint64 , versionedHash common.Hash ) (string , error ) {
109+ basePath , err := url .JoinPath (c .apiEndpoint , beaconNodeBlobEndpoint , fmt .Sprintf ("%d" , slot ))
110+ if err != nil {
111+ return "" , fmt .Errorf ("failed to join path, err: %w" , err )
112+ }
113+ u , err := url .Parse (basePath )
114+ if err != nil {
115+ return "" , fmt .Errorf ("failed to parse path, err: %w" , err )
116+ }
117+ q := u .Query ()
118+ q .Set ("versioned_hashes" , fmt .Sprintf ("[%s]" , versionedHash .Hex ()))
119+ u .RawQuery = q .Encode ()
120+ queryPath := u .String ()
121+ return queryPath , nil
122+ }
123+
108124func (c * BeaconNodeClient ) GetBlobByVersionedHashAndBlockTime (ctx context.Context , versionedHash common.Hash , blockTime uint64 ) (* kzg4844.Blob , error ) {
109125 slot := (blockTime - c .genesisTime ) / c .secondsPerSlot
110126
111- // get blob sidecar for slot
112- blobSidecarPath , err := url . JoinPath ( c . apiEndpoint , beaconNodeBlobEndpoint , fmt . Sprintf ( "%d?versioned_hashes=[%s]" , slot , versionedHash ) )
127+ // get blob by slot and versioned hash
128+ getBlobsPath , err := c . getBlobsPath ( slot , versionedHash )
113129 if err != nil {
114- return nil , fmt .Errorf ("failed to join path, err: %w" , err )
130+ return nil , fmt .Errorf ("failed to create getBlobs path, err: %w" , err )
115131 }
116- req , err := http .NewRequestWithContext (ctx , "GET" , blobSidecarPath , nil )
132+ req , err := http .NewRequestWithContext (ctx , "GET" , getBlobsPath , nil )
117133 if err != nil {
118134 return nil , fmt .Errorf ("failed to create request, err: %w" , err )
119135 }
0 commit comments