Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions block/internal/submitting/da_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,20 @@ func mergeSubmitOptions(baseOptions []byte, signingAddress string) ([]byte, erro
return baseOptions, nil
}

var optionsMap map[string]interface{}
var optionsMap map[string]any

// If base options are provided, try to parse them as JSON
if len(baseOptions) > 0 {
// Try to unmarshal existing options, ignoring errors for non-JSON input
if err := json.Unmarshal(baseOptions, &optionsMap); err != nil {
// Not valid JSON - start with empty map
optionsMap = make(map[string]interface{})
optionsMap = make(map[string]any)
}
}

// Ensure map is initialized even if unmarshal returned nil
if optionsMap == nil {
optionsMap = make(map[string]interface{})
optionsMap = make(map[string]any)
}
Comment on lines +367 to 381
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for initializing optionsMap can be simplified to improve readability. The current implementation has two separate blocks for initializing the map, which can be consolidated into a more straightforward sequence.

	var optionsMap map[string]any
	if len(baseOptions) > 0 {
		// Attempt to unmarshal existing options. We can ignore the error,
		// as we'll create a new map if it fails or if the JSON is `null`.
		_ = json.Unmarshal(baseOptions, &optionsMap)
	}
	if optionsMap == nil {
		optionsMap = make(map[string]any)
	}


// Add or override the signing address
Expand Down
16 changes: 8 additions & 8 deletions block/internal/submitting/da_submitter_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestMergeSubmitOptions_EmptyBaseOptions(t *testing.T) {
result, err := mergeSubmitOptions([]byte{}, signingAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

Expand All @@ -36,7 +36,7 @@ func TestMergeSubmitOptions_ValidJSON(t *testing.T) {
result, err := mergeSubmitOptions(baseOptions, signingAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

Expand All @@ -52,7 +52,7 @@ func TestMergeSubmitOptions_InvalidJSON(t *testing.T) {
result, err := mergeSubmitOptions(baseOptions, signingAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

Expand All @@ -68,7 +68,7 @@ func TestMergeSubmitOptions_OverrideExistingAddress(t *testing.T) {
result, err := mergeSubmitOptions(baseOptions, newAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

Expand All @@ -82,7 +82,7 @@ func TestMergeSubmitOptions_NilBaseOptions(t *testing.T) {
result, err := mergeSubmitOptions(nil, signingAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

Expand All @@ -102,17 +102,17 @@ func TestMergeSubmitOptions_ComplexJSON(t *testing.T) {
result, err := mergeSubmitOptions(baseOptions, signingAddress)
require.NoError(t, err)

var resultMap map[string]interface{}
var resultMap map[string]any
err = json.Unmarshal(result, &resultMap)
require.NoError(t, err)

// Check nested structure is preserved
nested, ok := resultMap["nested"].(map[string]interface{})
nested, ok := resultMap["nested"].(map[string]any)
require.True(t, ok)
assert.Equal(t, "value", nested["key"])

// Check array is preserved
array, ok := resultMap["array"].([]interface{})
array, ok := resultMap["array"].([]any)
require.True(t, ok)
assert.Len(t, array, 3)

Expand Down
Loading