Commit graph

5 commits

Author SHA1 Message Date
Dave Collins
e0ce788881 Update addresses to work with regtest network.
The prefix byte (netID) which is used to encode address is the same for
both the public test and regression test networks.  Previously the code
was working under the assumption there was a 1-to-1 mapping of prefix byte
to bitcoin network, however as noted above that assumption was not
correct.

This commit modifies things a bit to choose the prefix byte at address
creation time instead of at encode time and internally stores the prefix
byte instead of the network.  It also adds a new function, IsForNet, to the
Address interface which allows callers to test if an address is valid for
the passed network type.  The end result of this change is that callers
will only need to change their checks from testing if addr.Net() is the
active bitcoin network to instead using addr.IsForNet(activeNet).

Closes #2.
2014-02-26 14:00:47 -06:00
Dave Collins
043e07d57b Add a new concrete Address for pay-to-pubkey.
This commit adds a new concrete Address interface implementation for
pay-to-pubkey addresses.  It supports uncompressed, compressed, and hybrid
pubkeys.  It also provides a convenience method for converting to a
pay-to-pubkey-hash address.
2014-01-07 22:13:13 -06:00
Dave Collins
8928b361d4 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).
2014-01-05 13:48:55 -06:00
Dave Collins
8c022bae3a Refactor some common code in address.go.
Rather than repeating the same code in both the pay-to-pubkey-hash and
pay-to-script-hash encoding, refactor it into separate functions.  This
makes it easier to support new networks, for example, since it can be
changed in one place.
2014-01-05 12:55:21 -06:00
Josh Rickmar
58bae71f61 Implement Address interface.
Address is a generic interface for any type of "address" a
transaction can be sent to, including but not limited to
pay-to-pubkey, pay-to-pubkey-hash, and pay-to-script-hash.

This change implements Address and concrete types for P2PKH and P2SH
addresses with 100% test coverage.  Pay-to-pubkey support will be
added in the future.

This API is intended to replace the old EncodeAddress/DecodeAddress
functions which are now deprecated.
2014-01-03 11:10:25 -05:00