@@ -4,12 +4,15 @@ import (
4
4
"encoding/hex"
5
5
"encoding/json"
6
6
"fmt"
7
- "io/ioutil "
7
+ "io"
8
8
"net/http"
9
+ "slices"
9
10
10
11
"github.com/hyperledger-labs/yui-relayer/log"
11
12
)
12
13
14
+ var SupportedVersions = []string {"deneb" , "electra" }
15
+
13
16
type Client struct {
14
17
endpoint string
15
18
}
@@ -18,8 +21,8 @@ func NewClient(endpoint string) Client {
18
21
return Client {endpoint : endpoint }
19
22
}
20
23
21
- func ( Client ) SupportedVersion () string {
22
- return "deneb"
24
+ func IsSupportedVersion ( v string ) bool {
25
+ return slices . Contains ( SupportedVersions , v )
23
26
}
24
27
25
28
func (cl Client ) GetGenesis () (* Genesis , error ) {
@@ -57,7 +60,7 @@ func (cl Client) GetBootstrap(finalizedRoot []byte) (*LightClientBootstrapRespon
57
60
if err := cl .get (fmt .Sprintf ("/eth/v1/beacon/light_client/bootstrap/0x%v" , hex .EncodeToString (finalizedRoot [:])), & res ); err != nil {
58
61
return nil , err
59
62
}
60
- if res .Version != cl . SupportedVersion ( ) {
63
+ if ! IsSupportedVersion ( res .Version ) {
61
64
return nil , fmt .Errorf ("unsupported version: %v" , res .Version )
62
65
}
63
66
return & res , nil
@@ -72,7 +75,7 @@ func (cl Client) GetLightClientUpdates(period uint64, count uint64) (LightClient
72
75
return nil , fmt .Errorf ("unexpected response length: expected=%v actual=%v" , count , len (res ))
73
76
}
74
77
for i := range res {
75
- if res [i ].Version != cl . SupportedVersion ( ) {
78
+ if ! IsSupportedVersion ( res [i ].Version ) {
76
79
return nil , fmt .Errorf ("unsupported version: %v" , res [i ].Version )
77
80
}
78
81
}
@@ -92,7 +95,7 @@ func (cl Client) GetLightClientFinalityUpdate() (*LightClientFinalityUpdateRespo
92
95
if err := cl .get ("/eth/v1/beacon/light_client/finality_update" , & res ); err != nil {
93
96
return nil , err
94
97
}
95
- if res .Version != cl . SupportedVersion ( ) {
98
+ if ! IsSupportedVersion ( res .Version ) {
96
99
return nil , fmt .Errorf ("unsupported version: %v" , res .Version )
97
100
}
98
101
return & res , nil
@@ -105,7 +108,7 @@ func (cl Client) get(path string, res any) error {
105
108
return err
106
109
}
107
110
defer r .Body .Close ()
108
- bz , err := ioutil .ReadAll (r .Body )
111
+ bz , err := io .ReadAll (r .Body )
109
112
if err != nil {
110
113
return err
111
114
}
0 commit comments