Commit graph

7 commits

Author SHA1 Message Date
Dave Collins
60d4bed78f Modify DecodeAddress to accept serialized pubkeys.
This commit modifies DecodeAddress to accept and decode pay-to-pubkey
addresses (raw serialized public keys).  Since the resulting Address
needs to have a network associated with it, and a raw serialized public
key does not encode the network with it, a new parameter has been added
which requires the caller to specify a default network to use when
decoding addresses.

In the case the address has a network encoded with it such as for
pay-to-pubkey-hash and pay-to-script-hash addresses, the network will be
decoded from the address and the resulting Address instance will have that
network associated with it.  When the address does NOT have a network
encoded with it, such as a pay-to-pubkey address, the provided default
network will be associated with the returned Address instance.

Also, the tests have been updated to test the new functionality.

ok @owainga and @jrick.
2014-03-18 20:41:54 -05:00
Dave Collins
53483d0843 Rename DecodeAddr to DecodeAddress.
Now that the deprecated DecodeAddress has been removed, rename DecodeAddr
to DecodeAddress and remove the comment which warned this change was
coming.
2014-03-18 20:34:45 -05:00
Dave Collins
1c82527b3d Consolidate remaining addrconvs.go to address.go.
Since all of the deprecated address conversion functions have been
removed, consolidate the remaining private key funcs and tests into
address.go and address_test.go, repectively.
2014-03-18 20:34:33 -05:00
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
02bd4b14b1 Add tests for new AddressPubKey type.
More tests are needed and will be completed in future commits.
2014-01-07 23:41:14 -06:00
Dave Collins
de0c59fee1 Add canDecode flag to tests.
This commit adds a new flag to the tests which controls whether or not an
address can be decoded.  This is to support the upcoming public key
address type and possible future addresses which aren't directly
decodable.
2014-01-07 22:09:30 -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