From 626662fb5fe042ad574fb817f0f1cce357fc6446 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 3 Jan 2014 08:32:43 -0600 Subject: [PATCH] Add Stringer to BitcoinNet. --- protocol.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/protocol.go b/protocol.go index ebf166fb..fb10997d 100644 --- a/protocol.go +++ b/protocol.go @@ -5,6 +5,7 @@ package btcwire import ( + "fmt" "strconv" "strings" ) @@ -101,3 +102,20 @@ const ( // TestNet3 represents the test network (version 3). TestNet3 BitcoinNet = 0x0709110b ) + +// bnStrings is a map of bitcoin networks back to their constant names for +// pretty printing. +var bnStrings = map[BitcoinNet]string{ + MainNet: "MainNet", + TestNet: "TestNet", + TestNet3: "TestNet3", +} + +// String returns the BitcoinNet in human-readable form. +func (n BitcoinNet) String() string { + if s, ok := bnStrings[n]; ok { + return s + } + + return fmt.Sprintf("Unknown BitcoinNet (%d)", uint32(n)) +}