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).
This commit is contained in:
Dave Collins 2014-01-05 13:47:23 -06:00
parent 8c022bae3a
commit 8928b361d4

View file

@ -180,6 +180,13 @@ func (a *AddressPubKeyHash) Net() btcwire.BitcoinNet {
return a.net 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) // AddressScriptHash is an Address for a pay-to-script-hash (P2SH)
// transaction. // transaction.
type AddressScriptHash struct { type AddressScriptHash struct {
@ -239,3 +246,10 @@ func (a *AddressScriptHash) ScriptAddress() []byte {
func (a *AddressScriptHash) Net() btcwire.BitcoinNet { func (a *AddressScriptHash) Net() btcwire.BitcoinNet {
return a.net 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()
}