Skip to content

Commit

Permalink
fix: base64 converted to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
czar0 committed Dec 29, 2023
1 parent 94523de commit e3cf353
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/ethkit/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
Expand Down Expand Up @@ -85,7 +87,7 @@ func printKeyValue(w *tabwriter.Writer, key string, value any) {
}
fmt.Fprintln(w, "\t", "\t")
} else {
fmt.Fprintln(w, "\t", elem)
fmt.Fprintln(w, "\t", customFormat(elem))
}
}
default:
Expand All @@ -101,7 +103,7 @@ func customFormat(value any) string {
case float32, float64:
return formatFloat(v)
default:
return fmt.Sprintf("%v", value)
return fmt.Sprintf("%v", base64ToHex(value))
}
}

Expand All @@ -116,8 +118,21 @@ func formatFloat(f any) string {
return str
}

func base64ToHex(str any) any {
_, ok := str.(string); if !ok {
return str
}
decoded, err := base64.StdEncoding.DecodeString(str.(string))
if err != nil {
return str
}

return "0x" + hex.EncodeToString(decoded)
}

// GetValueByJSONTag returns the value of a struct field matching a JSON tag provided in input.
func GetValueByJSONTag(input any, jsonTag string) any {
// TODO: Refactor to support both nil values and errors when key not found
return findField(reflect.ValueOf(input), jsonTag)
}

Expand Down

0 comments on commit e3cf353

Please sign in to comment.