Skip to content

Commit 31cbb9f

Browse files
committed
chore: update
1 parent 822f3cb commit 31cbb9f

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

cmd/sequence/config.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,10 @@ func calculateImageHash(params *ConfigImageHashParams) (string, error) {
483483
return "0x" + common.Bytes2Hex(imageHash.Bytes()), nil
484484
}
485485

486-
// encodeConfig encodes a configuration into a signature format
487-
func encodeConfig(params *ConfigEncodeParams) (string, error) {
486+
func handleRawConfig(input []byte) (map[string]interface{}, error) {
488487
var rawConfig map[string]interface{}
489-
if err := json.Unmarshal(params.Input, &rawConfig); err != nil {
490-
return "", fmt.Errorf("failed to parse raw config: %w", err)
488+
if err := json.Unmarshal(input, &rawConfig); err != nil {
489+
return nil, fmt.Errorf("failed to parse raw config: %w", err)
491490
}
492491

493492
// Check if the config is nested under an "input" field
@@ -498,32 +497,32 @@ func encodeConfig(params *ConfigEncodeParams) (string, error) {
498497
// Convert topology array to tree structure matching TypeScript
499498
if topology, ok := rawConfig["topology"].([]interface{}); ok {
500499
if len(topology) != 2 {
501-
return "", fmt.Errorf("expected exactly two rows in topology")
500+
return nil, fmt.Errorf("expected exactly two rows in topology")
502501
}
503502

504503
var subtrees []map[string]interface{}
505504
for i, row := range topology {
506505
rowArray, ok := row.([]interface{})
507506
if !ok || len(rowArray) != 2 {
508-
return "", fmt.Errorf("each topology row must have exactly two elements")
507+
return nil, fmt.Errorf("each topology row must have exactly two elements")
509508
}
510509

511510
leftItem, ok := rowArray[0].(map[string]interface{})
512511
if !ok {
513-
return "", fmt.Errorf("invalid left item in topology row %d", i)
512+
return nil, fmt.Errorf("invalid left item in topology row %d", i)
514513
}
515514
leftNode, err := convertTree(leftItem)
516515
if err != nil {
517-
return "", fmt.Errorf("failed to convert left tree item in row %d: %w", i, err)
516+
return nil, fmt.Errorf("failed to convert left tree item in row %d: %w", i, err)
518517
}
519518

520519
rightItem, ok := rowArray[1].(map[string]interface{})
521520
if !ok {
522-
return "", fmt.Errorf("invalid right item in topology row %d", i)
521+
return nil, fmt.Errorf("invalid right item in topology row %d", i)
523522
}
524523
rightNode, err := convertTree(rightItem)
525524
if err != nil {
526-
return "", fmt.Errorf("failed to convert right tree item in row %d: %w", i, err)
525+
return nil, fmt.Errorf("failed to convert right tree item in row %d: %w", i, err)
527526
}
528527

529528
subtree := map[string]interface{}{
@@ -534,7 +533,7 @@ func encodeConfig(params *ConfigEncodeParams) (string, error) {
534533
}
535534

536535
if len(subtrees) != 2 {
537-
return "", fmt.Errorf("expected exactly two subtrees from topology")
536+
return nil, fmt.Errorf("expected exactly two subtrees from topology")
538537
}
539538

540539
tree := map[string]interface{}{
@@ -546,6 +545,16 @@ func encodeConfig(params *ConfigEncodeParams) (string, error) {
546545
delete(rawConfig, "topology")
547546
}
548547

548+
return rawConfig, nil
549+
}
550+
551+
// encodeConfig encodes a configuration into a signature format
552+
func encodeConfig(params *ConfigEncodeParams) (string, error) {
553+
rawConfig, err := handleRawConfig(params.Input)
554+
if err != nil {
555+
return "", fmt.Errorf("failed to handle raw config: %w", err)
556+
}
557+
549558
config, err := v3.Core.DecodeWalletConfig(rawConfig)
550559
if err != nil {
551560
return "", fmt.Errorf("failed to decode wallet config: %w", err)

0 commit comments

Comments
 (0)