From 8928b361d4c6b284068c22048856c1eec0d5c93c Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 5 Jan 2014 13:47:23 -0600 Subject: [PATCH] Add a String function to each address. This allows the addresses to be treated as fmt.Stringer for easy printing. There is no difference between String and EncodeAddress (in fact String just calls EncodeAddress). --- address.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/address.go b/address.go index 3915e4e..5836102 100644 --- a/address.go +++ b/address.go @@ -180,6 +180,13 @@ func (a *AddressPubKeyHash) Net() btcwire.BitcoinNet { return a.net } +// String returns a human-readable string for the pay-to-pubkey-hash address. +// This is equivalent to calling EncodeAddress, but is provided so the type can +// be used as a fmt.Stringer. +func (a *AddressPubKeyHash) String() string { + return a.EncodeAddress() +} + // AddressScriptHash is an Address for a pay-to-script-hash (P2SH) // transaction. type AddressScriptHash struct { @@ -239,3 +246,10 @@ func (a *AddressScriptHash) ScriptAddress() []byte { func (a *AddressScriptHash) Net() btcwire.BitcoinNet { return a.net } + +// String returns a human-readable string for the pay-to-script-hash address. +// This is equivalent to calling EncodeAddress, but is provided so the type can +// be used as a fmt.Stringer. +func (a *AddressScriptHash) String() string { + return a.EncodeAddress() +}