@@ -5,9 +5,6 @@ package eth2wrap
55import (
66 "context"
77 "encoding/hex"
8- "encoding/json"
9- "fmt"
10- "io"
118 "net/http"
129 "sync"
1310 "testing"
@@ -24,11 +21,6 @@ import (
2421 "github.com/obolnetwork/charon/eth2util"
2522)
2623
27- // NodeIdentity represents the identity of a beacon node.
28- type NodeIdentity struct {
29- PeerID string `json:"peer_id"`
30- }
31-
3224// NewHTTPAdapterForT returns a http adapter for testing non-eth2service methods as it is nil.
3325func NewHTTPAdapterForT (_ * testing.T , address string , headers map [string ]string , timeout time.Duration ) Client {
3426 return newHTTPAdapter (nil , address , headers , timeout )
@@ -206,51 +198,3 @@ func (h *httpAdapter) ClientForAddress(_ string) Client {
206198func (h * httpAdapter ) Headers () map [string ]string {
207199 return h .headers
208200}
209-
210- // NodeIdentity fetches the node identity from the beacon node.
211- func (h * httpAdapter ) NodeIdentity (ctx context.Context ) (* NodeIdentity , error ) {
212- url := fmt .Sprintf ("%s/eth/v1/node/identity" , h .address )
213-
214- req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
215- if err != nil {
216- return nil , errors .Wrap (err , "create request" )
217- }
218-
219- // Add custom headers
220- for k , v := range h .headers {
221- req .Header .Set (k , v )
222- }
223-
224- client := & http.Client {
225- Timeout : h .timeout ,
226- }
227-
228- resp , err := client .Do (req )
229- if err != nil {
230- return nil , errors .Wrap (err , "fetch node identity" )
231- }
232- defer resp .Body .Close ()
233-
234- if resp .StatusCode != http .StatusOK {
235- body , _ := io .ReadAll (resp .Body )
236- return nil , errors .New ("node identity request failed" ,
237- z .Int ("status_code" , resp .StatusCode ),
238- z .Str ("body" , string (body )),
239- )
240- }
241-
242- body , err := io .ReadAll (resp .Body )
243- if err != nil {
244- return nil , errors .Wrap (err , "read response" )
245- }
246-
247- var result struct {
248- Data NodeIdentity `json:"data"`
249- }
250-
251- if err := json .Unmarshal (body , & result ); err != nil {
252- return nil , errors .Wrap (err , "unmarshal node identity" )
253- }
254-
255- return & result .Data , nil
256- }
0 commit comments