@@ -24,6 +24,7 @@ import (
24
24
"io"
25
25
"net/http"
26
26
"net/url"
27
+ "strconv"
27
28
"sync"
28
29
"time"
29
30
@@ -121,8 +122,8 @@ func NewBeaconLightApi(url string, customHeaders map[string]string) *BeaconLight
121
122
}
122
123
}
123
124
124
- func (api * BeaconLightApi ) httpGet (path string ) ([]byte , error ) {
125
- uri , err := api .buildURL (path , nil )
125
+ func (api * BeaconLightApi ) httpGet (path string , params url. Values ) ([]byte , error ) {
126
+ uri , err := api .buildURL (path , params )
126
127
if err != nil {
127
128
return nil , err
128
129
}
@@ -150,17 +151,16 @@ func (api *BeaconLightApi) httpGet(path string) ([]byte, error) {
150
151
}
151
152
}
152
153
153
- func (api * BeaconLightApi ) httpGetf (format string , params ... any ) ([]byte , error ) {
154
- return api .httpGet (fmt .Sprintf (format , params ... ))
155
- }
156
-
157
154
// GetBestUpdatesAndCommittees fetches and validates LightClientUpdate for given
158
155
// period and full serialized committee for the next period (committee root hash
159
156
// equals update.NextSyncCommitteeRoot).
160
157
// Note that the results are validated but the update signature should be verified
161
158
// by the caller as its validity depends on the update chain.
162
159
func (api * BeaconLightApi ) GetBestUpdatesAndCommittees (firstPeriod , count uint64 ) ([]* types.LightClientUpdate , []* types.SerializedSyncCommittee , error ) {
163
- resp , err := api .httpGetf ("/eth/v1/beacon/light_client/updates?start_period=%d&count=%d" , firstPeriod , count )
160
+ resp , err := api .httpGet ("/eth/v1/beacon/light_client/updates" , map [string ][]string {
161
+ "start_period" : {strconv .FormatUint (firstPeriod , 10 )},
162
+ "count" : {strconv .FormatUint (count , 10 )},
163
+ })
164
164
if err != nil {
165
165
return nil , nil , err
166
166
}
@@ -197,7 +197,7 @@ func (api *BeaconLightApi) GetBestUpdatesAndCommittees(firstPeriod, count uint64
197
197
// See data structure definition here:
198
198
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate
199
199
func (api * BeaconLightApi ) GetOptimisticUpdate () (types.OptimisticUpdate , error ) {
200
- resp , err := api .httpGet ("/eth/v1/beacon/light_client/optimistic_update" )
200
+ resp , err := api .httpGet ("/eth/v1/beacon/light_client/optimistic_update" , nil )
201
201
if err != nil {
202
202
return types.OptimisticUpdate {}, err
203
203
}
@@ -250,7 +250,7 @@ func decodeOptimisticUpdate(enc []byte) (types.OptimisticUpdate, error) {
250
250
// See data structure definition here:
251
251
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientfinalityupdate
252
252
func (api * BeaconLightApi ) GetFinalityUpdate () (types.FinalityUpdate , error ) {
253
- resp , err := api .httpGet ("/eth/v1/beacon/light_client/finality_update" )
253
+ resp , err := api .httpGet ("/eth/v1/beacon/light_client/finality_update" , nil )
254
254
if err != nil {
255
255
return types.FinalityUpdate {}, err
256
256
}
@@ -316,7 +316,7 @@ func (api *BeaconLightApi) GetHeader(blockRoot common.Hash) (types.Header, bool,
316
316
} else {
317
317
blockId = blockRoot .Hex ()
318
318
}
319
- resp , err := api .httpGetf ( "/eth/v1/beacon/headers/%s" , blockId )
319
+ resp , err := api .httpGet ( fmt . Sprintf ( "/eth/v1/beacon/headers/%s" , blockId ), nil )
320
320
if err != nil {
321
321
return types.Header {}, false , false , err
322
322
}
@@ -347,7 +347,7 @@ func (api *BeaconLightApi) GetHeader(blockRoot common.Hash) (types.Header, bool,
347
347
348
348
// GetCheckpointData fetches and validates bootstrap data belonging to the given checkpoint.
349
349
func (api * BeaconLightApi ) GetCheckpointData (checkpointHash common.Hash ) (* types.BootstrapData , error ) {
350
- resp , err := api .httpGetf ( "/eth/v1/beacon/light_client/bootstrap/0x%x" , checkpointHash [:])
350
+ resp , err := api .httpGet ( fmt . Sprintf ( "/eth/v1/beacon/light_client/bootstrap/0x%x" , checkpointHash [:]), nil )
351
351
if err != nil {
352
352
return nil , err
353
353
}
@@ -389,7 +389,7 @@ func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types
389
389
}
390
390
391
391
func (api * BeaconLightApi ) GetBeaconBlock (blockRoot common.Hash ) (* types.BeaconBlock , error ) {
392
- resp , err := api .httpGetf ( "/eth/v2/beacon/blocks/0x%x" , blockRoot )
392
+ resp , err := api .httpGet ( fmt . Sprintf ( "/eth/v2/beacon/blocks/0x%x" , blockRoot ), nil )
393
393
if err != nil {
394
394
return nil , err
395
395
}
0 commit comments