common: document Address conversion functions

The documentation is especially supposed to clarify which function users
should call to convert a string containing an address into an Address
struct.
This commit is contained in:
Lorenzo Manacorda 2018-03-15 20:00:13 +01:00
parent a063876749
commit c64a460ba0

View file

@ -143,9 +143,15 @@ func BytesToAddress(b []byte) Address {
a.SetBytes(b) a.SetBytes(b)
return a return a
} }
// StringToAddress converts an arbitrary string into an Address.
func StringToAddress(s string) Address { return BytesToAddress([]byte(s)) } func StringToAddress(s string) Address { return BytesToAddress([]byte(s)) }
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) } // BigToAddress converts an arbitary *big.Int into an Address.
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
// HexToAddress converts a string containing an address into an Address.
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
// IsHexAddress verifies whether a string can represent a valid hex-encoded // IsHexAddress verifies whether a string can represent a valid hex-encoded
// Ethereum address or not. // Ethereum address or not.