Commit graph

133 commits

Author SHA1 Message Date
David Hill
9e3269e67c Initial work towards BIP0037 bloom filtering API. 2014-07-09 13:28:57 -05:00
Josh Rickmar
e0adcd5f70 Make amount constants untyped.
Since these constants can be useful for int64, Amount, and float64
math, it doesn't make sense to make them just one type, and require
type conversions for the rest.

ok @davecgh
2014-07-08 11:13:12 -05:00
Dave Collins
6c4b5928ab goimports -w . 2014-07-02 19:29:48 -05:00
Josh Rickmar
52be380fd1 Update test coverage report. 2014-06-24 18:46:12 -05:00
Josh Rickmar
b3e031c1f9 Add NewBlockFromReader and NewTxFromReader.
While here, remove the serializedTx field from Tx.  This field was
originally intended to be used to cache the bytes of the serialized
transaction, but it was never used and can effectively leak memory if
the Tx was created with a call to NewTxFromBytes.

ok @davecgh
2014-06-24 18:46:06 -05:00
Josh Rickmar
9a3f83d493 Switch bytes.Buffer to Reader where possible.
bytes.Reader is a little bit more efficient than a bytes.Buffer when
just reading, so in situations where only an io.Reader is needed (for
Block and Tx deserialization), switch to a bytes.Reader.

ok @davecgh
2014-06-23 21:39:04 -05:00
Josh Rickmar
c54649be41 Update test coverage report. 2014-06-23 12:05:49 -05:00
Josh Rickmar
2847c14f06 Add Amount.MulF64.
ok @davecgh, @jcvernaleo
2014-06-23 12:05:00 -05:00
Josh Rickmar
fb4c64910d Make Address a fmt.Stringer. 2014-06-12 20:11:36 -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
Owain G. Ainsworth
973174daa4 Add entrypoint to get the pubkey out AddressPubKey 2014-04-24 01:41:01 +01:00
Francis Lam
3e403ed6c0 Updated coinset interfaces to use btcutil.Amount for coin value 2014-04-23 20:04:03 -04: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
David Hill
190c86b2bf Preallocate space for the answer in Base58Encode.
Benchmarks show this makes Base58Encode twice as fast.
2014-04-16 20:43:01 -04: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
7ec063aebc Fix issues found by golint. 2014-04-12 12:02:54 -05:00
Josh Rickmar
4465e71837 Remove dead code.
Found by go vet.
2014-04-12 11:57:52 -05:00
David Hill
9bd84d007a gofmt 2014-04-12 09:08:49 -04:00
Josh Rickmar
3a2bf60941 Rename AmountUnit constants.
Besides being shorter, using "BTC" rather than "Bitcoin" in the
AmountUnit constants is deemed to be better for these units as BTC is
already a recognized monetary unit.

AmountBaseBitcoin has likewise been renamed to AmountSatoshi as this
is consistant with how it is returned as a string.  The "standard"
part of the comment in the const block has been removed, as Satoshi is
technically not a standard term for this unit.

ok @davecgh
2014-04-11 23:23:27 -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
Owain G. Ainsworth
4d8920c4dd Fix up for recent btcec changes. 2014-04-09 19:32:24 +01:00
Dave Collins
050373543d Correct a few comments for available nets.
Originally the various NewAddressX family on functions were limited to
only btcwire.MainNet and btcwire.TestNet3.  They were changed a while back
to also support the regression test network however the comments were not
updated.  This commit simply removes the comments which limited the
available choices since all btcwire.BitconNet types are now supported.
2014-03-28 19:33:18 -05:00
David Hill
560355ff92 typo 2014-03-24 22:05:46 -04:00
David Hill
fca025945f whitespace 2014-03-24 22:04:02 -04: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
Dave Collins
9a9b12da00 Remove GPG bits from coinset README.md.
This commit removes the GPG Verification Key section from the new coinset
README.me since the btcutil repo itself is tagged and signed.
2014-03-24 11:10:43 -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
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
d7ea478de2 Remove deprecated address functions.
This commit removes the deprecated address functions which have been
replaced by the Address interface and concrete implementations.
2014-03-18 20:34:24 -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
David Hill
ca515e278d gofmt 2014-02-04 16:15:14 -05:00
Dave Collins
759451c046 Correct and improve cert generation.
This commit changes three things with cert generation.

- The extended key usage field has been removed since specifying the
  extended key usage field prevents the cert from working with firefox
  even when it specifies it can be used as a server
- Creates a random serial number since browsers like firefox and chrome
  won't accept two certificates with the same issuer and serial number
- Adds the digital signature key usage capability since some validators
  like node.js expect that instead of key encipherment
2014-01-29 03:48:46 -06:00
Dave Collins
4edc4ceb9e Update for recent btcwire API changes. 2014-01-18 20:59:07 -06:00
Josh Rickmar
b651766231 Add NewTLSCertPair to generate a certificate pair.
btcd, btcwallet, and an upcomming standalone tool to generate the TLS
certificates all need a way to generate TLS certificate pairs.  This
function, adapted from the cert gen code in btcd, abstracts this logic
so all programs can reuse the code.

Unlike the older btcd certificate generation code, this new function
allows specifying additional hostnames and IPs to add to the list of
addresses for which the cert is valid.
2014-01-10 15:35:55 -05:00
Dave Collins
2af3c8263a Add 2014 to copyright dates. 2014-01-08 23:46:05 -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
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
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
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
Dave Collins
fdb279f482 Use fastsha256 in Hash160.
Rather than using the stdlib sha256, use the Conformal fastsha256 package
for faster hashing.
2014-01-04 22:23:01 -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
Josh Rickmar
32f63f3abc Add Hash160 func to calculate ripemd160(sha256(data)). 2014-01-03 00:17:35 -05:00
Dave Collins
f3d39524ce Update test coverage report. 2014-01-02 11:39:32 -06:00
Francis Lam
13fec7735c Fixed comments and added tests for scriptHash encoding
Fixed bad comments on new scriptHash constants and encoding function.

Added encodeScriptHashTests to addrconvs_test.go to check correctness of
output.
2014-01-02 12:09:47 -05:00