Skip to content

Commit 88ce33c

Browse files
authored
refactor: replace interface{} with any for clarity and modernization (#2781)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> This change replaces occurrences of interface{} with the predeclared identifier any, introduced in Go 1.18 as an alias for interface{}. As noted in the [Go 1.18 Release Notes](https://go.dev/doc/go1.18#language): This improves readability and aligns the codebase with modern Go conventions. Signed-off-by: reddaisyy <reddaisy@outlook.jp>
1 parent c6dd42c commit 88ce33c

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

pkg/rpc/server/da_visualization.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (s *DAVisualizationServer) handleDASubmissions(w http.ResponseWriter, r *ht
118118

119119
// If not an aggregator, return empty submissions with a message
120120
if !s.isAggregator {
121-
response := map[string]interface{}{
121+
response := map[string]any{
122122
"is_aggregator": false,
123123
"submissions": []DASubmissionInfo{},
124124
"total": 0,
@@ -139,7 +139,7 @@ func (s *DAVisualizationServer) handleDASubmissions(w http.ResponseWriter, r *ht
139139
}
140140

141141
// Build response
142-
response := map[string]interface{}{
142+
response := map[string]any{
143143
"submissions": reversed,
144144
"total": len(reversed),
145145
}
@@ -192,7 +192,7 @@ func (s *DAVisualizationServer) handleDABlobDetails(w http.ResponseWriter, r *ht
192192
}
193193

194194
blob := blobs[0]
195-
response := map[string]interface{}{
195+
response := map[string]any{
196196
"id": blobID,
197197
"height": height,
198198
"commitment": hex.EncodeToString(commitment),
@@ -215,7 +215,7 @@ func (s *DAVisualizationServer) handleDAStats(w http.ResponseWriter, r *http.Req
215215

216216
// If not an aggregator, return empty stats
217217
if !s.isAggregator {
218-
stats := map[string]interface{}{
218+
stats := map[string]any{
219219
"is_aggregator": false,
220220
"total_submissions": 0,
221221
"message": "This node is not an aggregator and does not submit to the DA layer",
@@ -264,15 +264,15 @@ func (s *DAVisualizationServer) handleDAStats(w http.ResponseWriter, r *http.Req
264264
lastSubmission = &s.submissions[len(s.submissions)-1].Timestamp
265265
}
266266

267-
stats := map[string]interface{}{
267+
stats := map[string]any{
268268
"total_submissions": totalSubmissions,
269269
"success_count": successCount,
270270
"error_count": errorCount,
271271
"success_rate": fmt.Sprintf("%.2f%%", successRate),
272272
"total_blob_size": totalBlobSize,
273273
"avg_blob_size": avgBlobSize,
274274
"avg_gas_price": avgGasPrice,
275-
"time_range": map[string]interface{}{
275+
"time_range": map[string]any{
276276
"first": firstSubmission,
277277
"last": lastSubmission,
278278
},
@@ -292,7 +292,7 @@ func (s *DAVisualizationServer) handleDAHealth(w http.ResponseWriter, r *http.Re
292292

293293
// If not an aggregator, return simplified health status
294294
if !s.isAggregator {
295-
health := map[string]interface{}{
295+
health := map[string]any{
296296
"is_aggregator": false,
297297
"status": "n/a",
298298
"message": "This node is not an aggregator and does not submit to the DA layer",
@@ -409,12 +409,12 @@ func (s *DAVisualizationServer) handleDAHealth(w http.ResponseWriter, r *http.Re
409409
}
410410
}
411411

412-
health := map[string]interface{}{
412+
health := map[string]any{
413413
"status": healthStatus,
414414
"is_healthy": isHealthy,
415415
"connection_status": connectionStatus,
416416
"connection_healthy": connectionHealthy,
417-
"metrics": map[string]interface{}{
417+
"metrics": map[string]any{
418418
"recent_error_rate": fmt.Sprintf("%.1f%%", errorRate),
419419
"recent_errors": recentErrors,
420420
"recent_successes": recentSuccesses,
@@ -454,7 +454,7 @@ func (s *DAVisualizationServer) handleDAVisualizationHTML(w http.ResponseWriter,
454454
}
455455
return s[start:end]
456456
},
457-
"len": func(items interface{}) int {
457+
"len": func(items any) int {
458458
// Handle different types gracefully
459459
switch v := items.(type) {
460460
case []DASubmissionInfo:

pkg/rpc/server/da_visualization_non_aggregator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func TestNonAggregatorHandleDASubmissions(t *testing.T) {
4343
assert.Equal(t, http.StatusOK, rr.Code)
4444
assert.Equal(t, "application/json", rr.Header().Get("Content-Type"))
4545

46-
var response map[string]interface{}
46+
var response map[string]any
4747
err = json.Unmarshal(rr.Body.Bytes(), &response)
4848
require.NoError(t, err)
4949

5050
assert.Equal(t, false, response["is_aggregator"])
5151
assert.Equal(t, float64(0), response["total"])
5252
assert.Contains(t, response["message"], "not an aggregator")
5353

54-
submissions, ok := response["submissions"].([]interface{})
54+
submissions, ok := response["submissions"].([]any)
5555
require.True(t, ok)
5656
assert.Equal(t, 0, len(submissions))
5757
}
@@ -73,7 +73,7 @@ func TestNonAggregatorHandleDAStats(t *testing.T) {
7373
assert.Equal(t, http.StatusOK, rr.Code)
7474
assert.Equal(t, "application/json", rr.Header().Get("Content-Type"))
7575

76-
var response map[string]interface{}
76+
var response map[string]any
7777
err = json.Unmarshal(rr.Body.Bytes(), &response)
7878
require.NoError(t, err)
7979

@@ -99,7 +99,7 @@ func TestNonAggregatorHandleDAHealth(t *testing.T) {
9999
assert.Equal(t, http.StatusOK, rr.Code)
100100
assert.Equal(t, "application/json", rr.Header().Get("Content-Type"))
101101

102-
var response map[string]interface{}
102+
var response map[string]any
103103
err = json.Unmarshal(rr.Body.Bytes(), &response)
104104
require.NoError(t, err)
105105

pkg/rpc/server/da_visualization_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ func TestHandleDASubmissions(t *testing.T) {
136136
assert.Equal(t, http.StatusOK, rr.Code)
137137
assert.Equal(t, "application/json", rr.Header().Get("Content-Type"))
138138

139-
var response map[string]interface{}
139+
var response map[string]any
140140
err = json.Unmarshal(rr.Body.Bytes(), &response)
141141
require.NoError(t, err)
142142

143143
assert.Equal(t, float64(1), response["total"])
144-
submissions, ok := response["submissions"].([]interface{})
144+
submissions, ok := response["submissions"].([]any)
145145
require.True(t, ok)
146146
assert.Equal(t, 1, len(submissions))
147147

148-
submission := submissions[0].(map[string]interface{})
148+
submission := submissions[0].(map[string]any)
149149
assert.Equal(t, float64(100), submission["height"])
150150
assert.Equal(t, float64(1024), submission["blob_size"])
151151
assert.Equal(t, 0.5, submission["gas_price"])

tools/blob-decoder/main.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ var templatesFS embed.FS
2525

2626
// DecodedBlob represents the result of decoding a blob
2727
type DecodedBlob struct {
28-
Type string `json:"type"`
29-
Data interface{} `json:"data"`
30-
RawHex string `json:"rawHex"`
31-
Size int `json:"size"`
32-
Timestamp time.Time `json:"timestamp"`
33-
Error string `json:"error,omitempty"`
28+
Type string `json:"type"`
29+
Data any `json:"data"`
30+
RawHex string `json:"rawHex"`
31+
Size int `json:"size"`
32+
Timestamp time.Time `json:"timestamp"`
33+
Error string `json:"error,omitempty"`
3434
}
3535

3636
func main() {
@@ -164,7 +164,7 @@ func decodeBlob(data []byte) DecodedBlob {
164164
}
165165

166166
// Check if it's JSON
167-
var jsonData interface{}
167+
var jsonData any
168168
if err := json.Unmarshal(data, &jsonData); err == nil {
169169
return DecodedBlob{
170170
Type: "JSON",
@@ -175,14 +175,14 @@ func decodeBlob(data []byte) DecodedBlob {
175175
// Return as unknown binary
176176
return DecodedBlob{
177177
Type: "Unknown",
178-
Data: map[string]interface{}{
178+
Data: map[string]any{
179179
"message": "Unable to decode blob format",
180180
"preview": hex.EncodeToString(data[:min(100, len(data))]),
181181
},
182182
}
183183
}
184184

185-
func tryDecodeHeader(data []byte) interface{} {
185+
func tryDecodeHeader(data []byte) any {
186186
var headerPb pb.SignedHeader
187187
if err := proto.Unmarshal(data, &headerPb); err != nil {
188188
return nil
@@ -199,14 +199,14 @@ func tryDecodeHeader(data []byte) interface{} {
199199
}
200200

201201
// Return a map with the actual header fields
202-
return map[string]interface{}{
202+
return map[string]any{
203203
// BaseHeader fields
204204
"height": signedHeader.Height(),
205205
"time": signedHeader.Time().Format(time.RFC3339Nano),
206206
"chainId": signedHeader.ChainID(),
207207

208208
// Version
209-
"version": map[string]interface{}{
209+
"version": map[string]any{
210210
"block": signedHeader.Version.Block,
211211
"app": signedHeader.Version.App,
212212
},
@@ -222,30 +222,30 @@ func tryDecodeHeader(data []byte) interface{} {
222222

223223
// Signature fields
224224
"signature": bytesToHex(signedHeader.Signature),
225-
"signer": map[string]interface{}{
225+
"signer": map[string]any{
226226
"address": bytesToHex(signedHeader.Signer.Address),
227227
"pubKey": "",
228228
},
229229
}
230230
}
231231

232-
func tryDecodeSignedData(data []byte) interface{} {
232+
func tryDecodeSignedData(data []byte) any {
233233
var signedData types.SignedData
234234
if err := signedData.UnmarshalBinary(data); err != nil {
235235
return nil
236236
}
237237

238238
// Create transaction list
239-
transactions := make([]map[string]interface{}, len(signedData.Txs))
239+
transactions := make([]map[string]any, len(signedData.Txs))
240240
for i, tx := range signedData.Txs {
241-
transactions[i] = map[string]interface{}{
241+
transactions[i] = map[string]any{
242242
"index": i,
243243
"size": len(tx),
244244
"data": bytesToHex(tx),
245245
}
246246
}
247247

248-
result := map[string]interface{}{
248+
result := map[string]any{
249249
"transactions": transactions,
250250
"transactionCount": len(signedData.Txs),
251251
"signature": bytesToHex(signedData.Signature),
@@ -273,7 +273,7 @@ func bytesToHex(b []byte) string {
273273
return hex.EncodeToString(b)
274274
}
275275

276-
func sendJSONResponse(w http.ResponseWriter, data interface{}) {
276+
func sendJSONResponse(w http.ResponseWriter, data any) {
277277
w.Header().Set("Content-Type", "application/json")
278278
if err := json.NewEncoder(w).Encode(data); err != nil {
279279
http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)