libs/log: format []byte as hexidecimal string (uppercased) (#5960)

Closes: #5806 

Co-authored-by: Lanie Hei <heixx011@umn.edu>
This commit is contained in:
Anton Kaliaev
2021-01-25 16:25:29 +04:00
committed by GitHub
co-authored by Lanie Hei
parent 7e0436c6e6
commit d76add65a6
12 changed files with 130 additions and 39 deletions
+5 -2
View File
@@ -8,7 +8,7 @@ import (
"strings"
)
// The main purpose of HexBytes is to enable HEX-encoding for json/encoding.
// HexBytes enables HEX-encoding for json/encoding.
type HexBytes []byte
var (
@@ -58,7 +58,7 @@ func (bz *HexBytes) UnmarshalJSON(data []byte) error {
return nil
}
// Allow it to fulfill various interfaces in light-client, etc...
// Bytes fulfils various interfaces in light-client, etc...
func (bz HexBytes) Bytes() []byte {
return bz
}
@@ -67,6 +67,9 @@ func (bz HexBytes) String() string {
return strings.ToUpper(hex.EncodeToString(bz))
}
// Format writes either address of 0th element in a slice in base 16 notation,
// with leading 0x (%p), or casts HexBytes to bytes and writes as hexadecimal
// string to s.
func (bz HexBytes) Format(s fmt.State, verb rune) {
switch verb {
case 'p':