diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 19:35:17 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 21:03:20 +0800 |
commit | e588e0ca2b3b615af0ecfd5679c42df8f1cc4272 (patch) | |
tree | c37e95792ed9f17209b7de26a5d6047ac915db2a /common | |
parent | d4f60d362b8fcf82db1accf89c146a2a71375841 (diff) | |
download | dexon-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.tar.gz dexon-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.tar.zst dexon-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.zip |
all: next batch of log polishes to contextual versions
Diffstat (limited to 'common')
-rw-r--r-- | common/types.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/common/types.go b/common/types.go index 1585d878c..0c9e68903 100644 --- a/common/types.go +++ b/common/types.go @@ -47,8 +47,6 @@ func StringToHash(s string) Hash { return BytesToHash([]byte(s)) } func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) } func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) } -// Don't use the default 'String' method in case we want to overwrite - // Get the string representation of the underlying hash func (h Hash) Str() string { return string(h[:]) } func (h Hash) Bytes() []byte { return h[:] } @@ -144,6 +142,17 @@ func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) } func (a Address) Hash() Hash { return BytesToHash(a[:]) } func (a Address) Hex() string { return hexutil.Encode(a[:]) } +// String implements the stringer interface and is used also by the logger. +func (a Address) String() string { + return a.Hex() +} + +// Format implements fmt.Formatter, forcing the byte slice to be formatted as is, +// without going through the stringer interface used for logging. +func (a Address) Format(s fmt.State, c rune) { + fmt.Fprintf(s, "%"+string(c), a[:]) +} + // Sets the address to the value of b. If b is larger than len(a) it will panic func (a *Address) SetBytes(b []byte) { if len(b) > len(a) { |