Commit graph

158 commits

Author SHA1 Message Date
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
Francis Lam
592d38d55f Added EncodeScriptHash for BIP-0013 compliance
Implemented address format for pay-to-script-hash
2014-01-02 00:25:00 -05:00
Dave Collins
9759e8dc64 Add support for TravisCI.
Also add TravisCI build status badge to README.md.
2013-12-10 19:14:24 -06:00
Dave Collins
aa81187165 Update test coverage report. 2013-11-11 10:54:32 -06:00
Dave Collins
fcf9b83256 Add new AppDataDir function.
This commit adds a new AppDataDir function that can be used to get an
operating system and application specific directory to be used for storing
application data.

For example:

dir := AppDataDir("myapp", false)

Would result in:

POSIX (Linux/BSD): ~/.myapp
Mac OS: $HOME/Library/Application Support/Myapp
Windows: %LOCALAPPDATA%\Myapp
Plan 9: $home/myapp

This is work toward conformal/btcd#30.
2013-11-11 10:49:48 -06:00
David Hill
ccb6557298 Add compression support to both EncodePrivateKey and DecodePrivateKey 2013-11-06 12:34:57 -05:00
David Hill
cefb048288 update EncodePrivateKey and DecodePrivateKey to take a btcnet parameter 2013-11-01 00:45:38 -04:00
David Hill
7e3c9c1aed Add two new functions: EncodePrivateKey and DecodePrivateKey
EncodePrivateKey encodes a raw private key into Wallet Import Format.
DecodePrivateKey decodes the WIF string to a raw private key.
2013-10-31 23:51:45 -04:00
David Hill
e53f3f5d13 Bring satoshi constants over to btcutil 2013-10-29 16:01:41 -04:00
Dave Collins
93e46b9ffd Add tests for new Block API functions.
This commit adds both positive and negative tests for the new Tx and
Transactions Block API functions.

This is part of the ongoing transaction hash optimization effort noted in
conformal/btcd#25.
2013-10-28 10:55:55 -05:00
Dave Collins
8e97f32e68 Add funcs to Block API for wrapped transactions.
This commit adds two new functions to the Block API for working with the
recently added Tx type from the Block.

These new functions are named Tx and Transactions.  Tx returns a
transactions for the specified index as a Tx and also memoizes it so
subsequent calls are more efficient.  Transactions returns a slice of all
transactions in the Block wrapped in a Tx.

This is part of the ongoing transaction hash optimization effort
noted in conformal/btcd#25.
2013-10-28 10:34:27 -05: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
Dave Collins
e402c62673 Add new Tx wrapper for btcwire.MsgTx.
Currently, transaction hash caching is provided via Block directly, but a
transaction is not always part of a block and there are several cases
where only the transaction needs to be dealt with without wanting to pass
the entire block and transaction index around to be able to get at the
cached hash.

So, this commit adds a new type named Tx which is a wrapper that provides
easier and more efficient manipulation of raw wire protocol transactions.
It memoizes the hash for the transaction on its first access so subsequent
accesses don't have to repeat the relatively expensive hashing operations.
The idea is the callers can pass around pointers to these Tx types instead
of raw btcwire.MsgTx pointers.

For now, the Block API has not been changed, but the plan is to change it
to provide access to these wrapped transactions rather than having it do
the transaction hash caching directly.

This is only the first part of a series of changes working towards
optimizations noted in conformal/btcd#25.
2013-10-27 13:55:51 -05:00
Josh Rickmar
f72ab9cfce Update test coverage file 2013-10-08 13:14:04 -04:00
Josh Rickmar
e433a02e4b Encode and decode addresses with a btcwire.BitcoinNet, not a byte.
While here, fix a couple of append() leaks.
2013-10-08 13:00:41 -04:00
Josh Rickmar
867149f470 Add missing license header and remove extra space. 2013-09-12 11:32:47 -04:00
Josh Rickmar
e4925b4abe Add functions to encode and decode payment addresses. 2013-09-12 11:20:34 -04:00
Dave Collins
8b2fdd9808 Update comments to use proper form. 2013-08-06 12:40:08 -05:00
Dave Collins
ad7e3894c7 Allow var def to infer type from right-hand side.
Found by golint.
2013-08-06 12:37:20 -05:00
Dave Collins
43095c66bc Remove dependency on protocol version.
This commit unfortunately changes the public API of Block which I
ordinarily don't like to do, but in this case, I felt it was necessary.

The blocks used throughout the database and elsewhere should be indepedent
of the protocol version which is used to encode the block to wire format.
Each block has its own Version field which should be the deciding factor
for the serialization and deserialization of blocks.  In practice, they
are currently the same encoding, but that may not always be the case, and
it's important the blocks are stable depending on their own version
regardless of the protocol version.

This makes use of the new Serialize and Deserialize functions on MsgBlock
which are intended for long-term storage as opposed to wire encoding.
2013-08-05 16:28:55 -05:00
John C. Vernaleo
761970e639 Fixed license statment on base58 files. 2013-06-13 13:09:51 -04:00
John C. Vernaleo
5eda8b95af Add Base58Encode and Base58Decode functions. ok davec@ 2013-06-13 13:01:46 -04:00
Dave Collins
7ad8b4787b Update README.md test coverage.
Now that the test coverage is comprehensive. update the README
accordingly.
2013-05-30 12:52:51 -05:00
Dave Collins
05d31cdc7a Add negative test for TxLoc. 2013-05-30 11:50:58 -05:00
Dave Collins
b8843a0fb6 Make TxLoc comment consistent with others. 2013-05-30 11:39:43 -05:00
Dave Collins
e98dc50b69 Convert TxLoc to use normal returns. 2013-05-30 11:31:22 -05:00