diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 22:55:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 22:55:37 +0800 |
commit | 94c71c171f6c4de1f6f041bf1aadef2a377e10a3 (patch) | |
tree | dd4a0ddcc1f41268ab22eb50e5d0329855ab1196 /common | |
parent | 5f7826270c9e87509fd7731ec64953a5e4761de0 (diff) | |
parent | b117da2db3e2a7c557fa6f95c49aa041a973a563 (diff) | |
download | dexon-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.gz dexon-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.zst dexon-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.zip |
Merge pull request #3723 from karalabe/logger-updates-2
Logger updates
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) { |