Skip to content

Commit 1c2eee0

Browse files
committed
Implement String() function for Hash
We need a `String()` function to serialize Hash automatically in the log messages to a string. By default it will convert the Hash to a hex in the InternalByteOrder. This change required the previous `String` function to be renamed to `Hex`.
1 parent fa62f49 commit 1c2eee0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pkg/bitcoin/hash.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ func NewHash(hash []byte, byteOrder ByteOrder) (Hash, error) {
6161
}
6262

6363
// String returns the unprefixed hexadecimal string representation of the Hash
64+
// in the InternalByteOrder.
65+
func (h Hash) String() string {
66+
return h.Hex(InternalByteOrder)
67+
}
68+
69+
// Hex returns the unprefixed hexadecimal string representation of the Hash
6470
// in the given ByteOrder.
65-
func (h Hash) String(byteOrder ByteOrder) string {
71+
func (h Hash) Hex(byteOrder ByteOrder) string {
6672
switch byteOrder {
6773
case InternalByteOrder:
6874
return hex.EncodeToString(h[:])

0 commit comments

Comments
 (0)