Commit graph

26 commits

Author SHA1 Message Date
Josh Rickmar
52be380fd1 Update test coverage report. 2014-06-24 18:46:12 -05:00
Josh Rickmar
c54649be41 Update test coverage report. 2014-06-23 12:05:49 -05:00
Josh Rickmar
5bcc7790a0 Update Address and WIF APIs to use btcnet.
This change removes all occurances of btcwire.BitcoinNet from exported
APIs, replacing each with *btcnet.Params.  This simplifies the logic
for verifying string encodings of addresses and WIF private keys which
use leading identifier numbers to differentiate between address types
and the network they are intended for.  It also allows the use of this
package for non-standard networks (not mainnet, regtest, or testnet3)
and future proofs it for the possible addition of future testnet
networks.

To update across this change, replace each btcwire.BitcoinNet
parameter with the associated *btcnet.Params.  For the standard
networks, these changes are:

  btcwire.MainNet  -> &btcnet.MainNetParams
  btcwire.TestNet  -> &btcnet.RegressionNetParams
  btcwire.TestNet3 -> &btcnet.TestNet3Params

ok @davecgh
2014-05-27 17:08:45 -05:00
Josh Rickmar
bff18e5a93 Introduce better WIF API.
The old functions DecodePrivateKey and EncodePrivateKey have been
removed in favor of the DecodeWIF function and the String method of
the new WIF type.

ok @davecgh
2014-05-21 17:49:37 -05:00
Josh Rickmar
bcb009075b Add method to access P2PKH and P2SH hash arrays.
This change adds the Hash160 methods to AddressPubKeyHash and
AddressScriptHash so the hash may be accessed as an array, rather than
a byte slice with the ScriptAddress method of the Address interface.
In situations where arrays are more appropiate than slices (such as
for map keys), accessing the array directly this way can significantly
improve performance by reducing copying into local arrays.
2014-04-20 18:18:34 -05:00
Josh Rickmar
e622fde7e7 Remove bounds check for NewAmount.
Amount should still be a usable type even if the monetary amount being
described is not an amount at a single instance in time, for example,
the total of all BTC received by an address.  Therefore, the bounds
checks that the amount is within the total amount of bitcoin ever
producable have been removed.

The checks for NaN and +-Infinity remain.
2014-04-12 16:20:11 -05:00
Josh Rickmar
80b1f232bc Make Amount a fmt.Stringer. 2014-04-11 23:16:41 -05:00
Josh Rickmar
fc6f0dee54 Add Amount type to represent a monetary value.
ok @davecgh
2014-04-11 22:43:47 -05:00
Dave Collins
2db41b1f56 Remove deprecated TxShas func from btcutil.Block.
This commit removes the previously deprecated TxShas function from
btcutil.Block.  The preferred method to access transaction hashes is via
the Sha function on each btcutil.Tx contained within the block.

For example, the following illustrates how convert the old TxShas approach
to the new method:

OLD:

for i, sha := range block.TxShas() {
	// use sha
}

NEW:

for i, tx := range block.Transactions() {
	// use tx.Sha()
}

This commit also updates the tests for the removed function.
2014-03-24 13:56:43 -05:00
Dave Collins
c8b172c394 Bring test coverage report up-to-date. 2014-03-24 13:55:09 -05:00
Francis Lam
02a1584784 Added CoinSelector interface and a few simple algos as a sub-package
This commit contains a basic definition for CoinSelector along with some
utility classes and some basic algos to make creating transactions from
a set of available unspent outpoints easier.

Thanks to @dajohi, @davec, @jrick for all the feedback and suggestions
regarding interfaces, organization, optimization, comments and
documentation.
2014-03-22 23:25:33 -04:00
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
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
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
Dave Collins
f3d39524ce Update test coverage report. 2014-01-02 11:39:32 -06:00
Dave Collins
aa81187165 Update test coverage report. 2013-11-11 10:54:32 -06:00
Dave Collins
29f1bf4ae1 Add tests for new Tx type.
This commit adds both positive and negative tests for the new Tx type to
bring its coverage to 100%.

This is part of the ongoing transaction hash optimization effort noted
in conformal/btcd#25.
2013-10-27 14:00:39 -05:00
Josh Rickmar
f72ab9cfce Update test coverage file 2013-10-08 13:14:04 -04:00
Josh Rickmar
e4925b4abe Add functions to encode and decode payment addresses. 2013-09-12 11:20:34 -04:00
John C. Vernaleo
5eda8b95af Add Base58Encode and Base58Decode functions. ok davec@ 2013-06-13 13:01:46 -04:00
Dave Collins
05d31cdc7a Add negative test for TxLoc. 2013-05-30 11:50:58 -05:00
Dave Collins
3ffe28e364 Add test for OutOfRangeError. 2013-05-30 11:12:29 -05:00
Dave Collins
a5bb254ac6 Add negative tests for TxSha. 2013-05-30 11:06:09 -05:00
Dave Collins
f8fc23a541 Add negative test for NewBlockFromBytes. 2013-05-30 10:45:38 -05:00
Dave Collins
b90727cc8a Add tests for TxLoc. 2013-05-30 10:30:04 -05:00
Dave Collins
ef6c01960f Initial implementation. 2013-05-28 18:21:26 -05:00