Commit graph

200 commits

Author SHA1 Message Date
Dave Collins
5c8fddf4b4 Add deprecated comments to legacy InvVect_* consts.
This makes it a little more obvious in the documentation that they are
deprecated.
2013-10-08 15:51:34 -05:00
Dave Collins
93d86305a2 Deprecate InvVect_* constants in favor of InvType*.
This commit changes the InvVect_* constants, which are not standard Go
style, to the InvType*. In order to preserve backwards compatibility, it
also adds a legacy.go file which maps the old public constant names to the
new ones.

Closes #1.
2013-10-08 15:44:48 -05:00
Dave Collins
95ecbadb8e Ensure readVarInt handles short buf on first byte.
It is technically possible for the Read method on a reader to return zero
bytes read with a nil error even though that behavior is "discouraged" by
the interface documenation.  This commit switches the read of the first
byte to use io.ReadFull which will always error in this case.
2013-10-06 22:06:34 -05:00
Dave Collins
5f971e10e6 Pre-allocate space for slices.
Several of the messages store the parts that have a variable number of
elements as slices.  This commit modifies the code to choose sane defaults
for the backing arrays for the slices so when the entries are actually
appended, a lot of the overhead of growing the backing arrays and copying
the data multiple times is avoided.

Along the same lines, when decoding messages, the actual size is known and
now is pre-allocated instead of dynamically growing the backing array
thereby avoiding some overhead.
2013-09-25 14:38:28 -05:00
Dave Collins
e7f808378e Make max payload for a transaction max block size.
The maximum payload for a transaction is limited to the size of a block
rather than the maximum payload for a given message.
2013-09-19 16:46:14 -05:00
Andrew Tian
8679275090 Fix doc example typo 2013-08-12 22:53:50 -05:00
Dave Collins
335736e59f Add new func NetAddressIPPort.
This function is a convenience method to create a new NetAddress
from a net.IP and uint16 port as opposed to a net.Addr which must be of
type *net.TCPAddr.  This allows callers to support connection types that
don't provide access to a concrete *net.TCPAddr implementation.
2013-08-07 13:05:25 -05:00
Dave Collins
b4b7204a97 Remove BtcDecodeTxLoc since it has been replaced.
BtcDecodeTxLoc is no longer needed since it has been replaced by
DeserializeTxLoc.
2013-08-05 19:18:45 -05:00
Dave Collins
d90740728e Remove protocol version param from BlockSha/Txsha.
Both of these depend on the serialized bytes which are dependent on the
version field in the block/transaction.  They must be independent of the
protocol version so there is no need to require it.
2013-08-05 18:08:57 -05:00
Dave Collins
dea1bac359 Add negative tests for Serialize/Deserialize funcs.
This commit adds tests for the error paths when serializing and
deserializing MsgBlock and MsgTx.
2013-08-05 18:08:40 -05:00
Dave Collins
29eb4d4250 Add tests for new Serialize/Deserialize functions. 2013-08-05 18:08:26 -05:00
Dave Collins
088f3c923d Add Serialize/Deserialize for MsgBlock and MsgTx.
This commit introduces two new functions for MsgBlock and MsgTx named
Serialize and Deserialize.  The functions provide a stable mechanism for
serializing and deserializing blocks and transactions to and from disk
without having to worry about the protocol version.  Instead these
functions use the Version fields in the blocks and transactions.

These new functions differ from BtcEncode and BtcDecode in that the latter
functions are intended to encode/decode blocks and transaction from the
wire which technically can differ depending on the protocol version and
don't even really need to use the same format as the stored data.

Currently, there is no difference between the two, and due to how
intertwined they are in the reference implementaiton, they may not ever
diverge, but there is a difference and the goal for btcwire is to provide
a stable API that is flexible enough to deal with encoding changes.
2013-08-05 18:07:56 -05:00
Dave Collins
81120958f0 Comment inventory vector constants. 2013-07-27 16:42:23 -05:00
Dave Collins
69446009b2 Move TxVersion constant definition to msgtx.go.
This moves the definition closer to the associated type and mirrors the
rest of the package.
2013-07-27 16:34:47 -05:00
Dave Collins
035a9c3dc3 Add several comments for exported constants. 2013-07-27 16:31:47 -05:00
Dave Collins
d6752d8f99 Update comments to fix typos and use proper form. 2013-07-27 16:18:13 -05:00
Dave Collins
bfbc08beed Allow var defs to infer type from right-hand side.
Found by golint.
2013-07-27 16:10:38 -05:00
Dave Collins
99b06f8bce Add format specifier in pong test error output.
The error message did not have a format specifier even though it was
passing an argument to show.  Found by go vet.
2013-07-27 15:56:17 -05:00
Dave Collins
562bde6902 Use byte literals in tests to make go vet happy.
The go vet command complains about untagged struct initializers when
defining a ShaHash directly.  This seems to be a limitation where go vet
does not exclude the warning for types which are a constant size byte array
like it does for normal constant size byte array definition.

This commit simply modifies the tests to use a constant definition cast to a
ShaHash to overcome the limitation of go vet.
2013-07-27 15:55:06 -05:00
Dave Collins
90bf9e7449 Update tests for corrected max block payload size. 2013-07-27 15:32:36 -05:00
Dave Collins
9989865fa2 Use correct max block payload size.
The maximum block payload size is actually 1000000 bytes, not 1MB.
2013-07-27 15:25:05 -05:00
Dave Collins
ea3107d962 Add comments and doco to clairfy test networks.
There was not much documentation about the difference between testnet and
testnet3, so make it clear that testnet is used for regression tests and
testnet3 is the public test network (version 3).
2013-07-25 19:04:58 -05:00
Dave Collins
4e6b649be6 Add constant for regression test netowrk port. 2013-07-25 19:04:02 -05:00
Dave Collins
60dfddc9d0 Use common coinbase transaction for Genesis blocks.
Since the same coinbase transaction is used for the genesis blocks of
all three currently supposed networks, separate it into its own var and
use a reference to it in each of the genesis block defintions.
2013-07-24 09:09:18 -05:00
Dave Collins
ab064fd4d4 Add tests for genesis block of testnet (version 3). 2013-07-24 01:47:11 -05:00
Dave Collins
166123ae79 Add genesis block for the test network (version 3). 2013-07-24 01:45:30 -05:00
Dave Collins
b8f80da512 Add tests for genesis block of regression testnet. 2013-07-24 01:33:24 -05:00
Dave Collins
a90a8bf341 Add genesis block for the regression test network. 2013-07-24 01:32:43 -05:00
Dave Collins
65eae18285 Remove a couple of incorrect comments. 2013-07-24 00:35:16 -05:00
Dave Collins
d54fba85b4 Export the MaxBlockPayload constant.
Although you can technically get at this value via the MaxPayloadLength
function on a block, it is less overhead for any consumers that need to
know the value to simply export it directly.
2013-06-20 13:09:44 -05:00
mischief
7630a95724 fix Stringer interface for ShaHash.
http://golang.org/ref/spec#Method_sets for why this is necessary
2013-05-29 11:51:13 -07:00
Dave Collins
14a1da417f Enforce max block payload size of 1MB.
This commit changes MsgBlock to enforce a 1MB max payload per the spec.
Previously it was only limited to the max overall message size.  While
here, also enforce max payloads per message type (instead of only the max
overall message payload) when writing messages.
2013-05-16 09:07:04 -05:00
Dave Collins
d8007e9387 Update README to reflect 100% test coverage. 2013-05-15 14:00:06 -05:00
Dave Collins
c164de1692 Fix version typos in README. 2013-05-15 13:57:29 -05:00
Dave Collins
f8553b4a57 Remove test coverage TODO since it's now 100%. 2013-05-13 13:55:07 -05:00
Dave Collins
a3226897f0 Update package overview Errors section.
Now that all errors are either underlying IO errors or of type
MessageError, update the package overview documentation accordingly.
2013-05-13 02:19:57 -05:00
Dave Collins
5b78dee7e1 Add negative tests for MsgTx.
This commit adds tests for the error paths when encoding and decoding
MsgTx.  This commit also achieves 100% test coverage.
2013-05-13 02:09:55 -05:00
Dave Collins
6f511eb75d Make MsgTx test data available to all funcs.
Rather than having to repeat the same data for positive and negative
tests, make the same test data available to both.
2013-05-13 02:08:14 -05:00
Dave Collins
f9b6375d5b Add negative tests for MsgVersion.
This commit adds tests for the error paths when encoding and decoding
MsgVersion.
2013-05-12 21:47:36 -05:00
Dave Collins
3aef93f442 Make MsgVersion test data available to all funcs.
Rather than having to repeat the same data for positive and negative
tests, make the same test data available to both.
2013-05-12 21:01:40 -05:00
Dave Collins
1bab947596 Remove a few dead error checks.
The functions for generating transaction and block hashes contained a few
error checks for conditions which could never fail without run-time
panics.  This commit removes those superfluous checks and adds explanatory
comments.
2013-05-12 14:01:50 -05:00
Dave Collins
1ca8015ea0 Add negative tests for MsgBlock tx location decode.
This commit adds tests for the error paths when decoding MsgBlock via the
transaction location decode variant.
2013-05-12 12:48:52 -05:00
Dave Collins
0e033023bf Improve MsgBlock negative tests.
Rather than decoding from a zero-filled buffer, use valid block encoded
test data.
2013-05-12 12:43:01 -05:00
Dave Collins
4e16030fe8 Add tests for MsgBlock transaction location decode. 2013-05-12 11:52:35 -05:00
Dave Collins
c9d2dfea3d Add negative tests for WriteMessage.
This commit adds tests for the error paths when writing a message
to the wire.
2013-05-11 23:34:10 -05:00
Dave Collins
0400d0cec3 Remove dead error check in WriteMessage.
The io.Writer.Write function always returns an error if the bytes written
is less than provided, so there is no reason to further check if the
payload length matches after a successful write.
2013-05-11 23:22:09 -05:00
Dave Collins
7385f6ff24 Correct several test error messages. 2013-05-11 12:55:50 -05:00
Dave Collins
93070ef960 Add negative tests for MsgAlert.
This commit adds tests for the error paths when encoding and decoding
MsgAlert.
2013-05-11 12:49:22 -05:00
Dave Collins
3d303feefb Add negative test for NewShaHash.
This commit adds a test to ensure NewShaHash fails as expected when the
passed buffer has too many bytes to be a valid sha hash.
2013-05-11 11:19:46 -05:00
Dave Collins
61b86b1bb5 Add negative tests for MsgGetBlocks.
This commit adds tests for the error paths when encoded and decoding
MsgGetBlocks.
2013-05-11 11:06:52 -05:00