HomeSource World

common: improve printing of Hash and Address (#21834)

Description

common: improve printing of Hash and Address (#21834)

Both Hash and Address have a String method, which returns the value as
hex with 0x prefix. They also had a Format method which tried to print
the value using printf of []byte. The way Format worked was at odds with
String though, leading to a situation where fmt.Sprintf("%v", hash)
returned the decimal notation and hash.String() returned a hex string.

This commit makes it consistent again. Both types now support the %v,
%s, %q format verbs for 0x-prefixed hex output. %x, %X creates
unprefixed hex output. %d is also supported and returns the decimal
notation "[1 2 3...]".

For Address, the case of hex characters in %v, %s, %q output is
determined using the EIP-55 checksum. Using %x, %X with Address
disables checksumming.

Co-authored-by: Felix Lange <fjl@twurst.com>

Details

Provenance
Li, Cheng <lob4tt@gmail.com>Authored on Dec 8 2020, 6:19 PM
GitHub <noreply@github.com>Committed on Dec 8 2020, 6:19 PM
Parents
rGETHed0670cb17a9: accounts/abi/bind: allow specifying signer on transactOpts (#21356)
Branches
Unknown
Tags
Unknown

Event Timeline

GitHub <noreply@github.com> committed rGETHbd848aad7c4e: common: improve printing of Hash and Address (#21834) (authored by Li, Cheng <lob4tt@gmail.com>).Dec 8 2020, 6:19 PM