Compare commits

...

362 Commits

Author SHA1 Message Date
Elichai Turkel 8a40c7b51a
Merge pull request #432 from taoweicn/patch-1
Remove duplicate code
2020-07-02 11:56:56 +03:00
Andrew Poelstra 4af18729b0
Merge pull request #431 from sgeisler/2020-06-01-ruy-compat
Fix ruy rust 1.22 inccompatibility
2020-06-29 12:51:17 +00:00
Sebastian Geisler 139fc02592 Fix #430: ruy rust 1.22 inccompatibility 2020-06-04 22:05:16 +02:00
Tao Wei ed76e0823b
Remove duplicate code
Duplicated with L38
2020-06-03 17:17:13 +08:00
Elichai Turkel f4e26caa94
Merge pull request #415 from shesek/merkleblock-txids
Allow to construct MerkleBlock using the header and txids
2020-05-24 16:32:17 +03:00
Andrew Poelstra 7efde3ae47
Merge pull request #419 from elichai/2020-03-description
Deprecate Error::description
2020-05-23 17:26:38 +00:00
Andrew Poelstra 31a576020b
Merge pull request #425 from TheBlueMatt/2020-04-uint-fuzz
Add fuzz target comparing native u128 to our Uint type
2020-05-21 23:17:35 +00:00
Elichai Turkel 1c88be4df5
Merge pull request #422 from rust-bitcoin/2020-04-remove-alloc
Remove some needless allocations
2020-05-19 13:20:34 +03:00
Elichai Turkel af31017eb1
Remove the cursor overhead, write is implemented on vec these days 2020-05-19 12:57:39 +03:00
Andrew Poelstra c44bad87b2
Merge pull request #424 from jrawsthorne/wtxid-inv
Fix: Change WitnessTransaction inv type to use txid
2020-05-14 13:51:16 +00:00
Matt Corallo 604f1aa56e Add fuzz target comparing native u128 to our Uint type 2020-04-30 19:22:49 -04:00
Steven Roose a9173d61d3
Merge pull request #375 from canndrew/fix-serde-struct-macros
Fix serde struct macros deserialization impls
2020-04-19 19:56:27 +01:00
Jake Rawsthorne 81c061a68c Change WitnessTransaction inv type to use txid 2020-04-14 14:11:44 +01:00
Elichai Turkel 654232a3dc
Deprecate Error::description 2020-04-13 02:15:28 +03:00
Elichai Turkel 25cb3d3539
Remove alloc when hashing for Bitcoin message signing format 2020-04-12 19:04:13 +03:00
Elichai Turkel 41e4471721
Remove alloc when hashing sighash 2020-04-12 19:04:12 +03:00
Andrew Poelstra c3a7d1b27c
Merge pull request #417 from shesek/202003-block-size-weight
Add Block::get_size() and Block::get_weight()
2020-04-07 14:12:15 +00:00
Andrew Poelstra 8d859cf54c
Merge pull request #308 from elichai/2019-08-clippy
Cargo clippy changes
2020-04-05 16:26:07 +00:00
Elichai Turkel a627457032
Merge pull request #412 from stevenroose/export-denom
Export the util::amount::Denomination type
2020-04-05 10:56:57 +03:00
Andrew Poelstra 78183a31e2
Merge pull request #411 from tnull/handshake_example
Added a simple handshake example.
2020-04-04 21:34:57 +00:00
Elichai Turkel 2cc88a99aa
Removed PartialEq,PartialOrd impls, shouldn't be manually impl when Hash is derived 2020-03-29 17:15:15 +03:00
Elichai Turkel a473d01b17
Made some idiomatic changes 2020-03-29 17:15:15 +03:00
Elichai Turkel 3f2d428706
Remove needless references 2020-03-29 17:15:14 +03:00
Elichai Turkel 16eb81e1f7
Replaced slow vec initialization, and dual calls to hashmap 2020-03-29 17:10:27 +03:00
Nadav Ivgi 94032f6817 Add Block::get_size() and Block::get_weight() 2020-03-27 21:54:46 +03:00
Steven Roose a148e06736
Merge pull request #416 from shesek/202003-tx-size
Add Transaction::get_size()
2020-03-25 16:18:23 +00:00
Nadav Ivgi f3b5a7187c
Add Transaction::get_size() 2020-03-23 19:48:41 +02:00
Nadav Ivgi 65efc5cd37 Allow to construct MerkleBlock using the header and txids
Co-Authored-By: Elichai Turkel <elichai.turkel@gmail.com>
2020-03-21 18:23:08 +02:00
Elias Rohrer 827d98d821 Fixed for rust 1.22.0. 2020-03-03 12:18:37 +01:00
Elias Rohrer aa46618da7 Intialize stream reader only once. 2020-03-03 10:48:01 +01:00
Elias Rohrer 40431f3d4f Formatted. 2020-03-03 10:48:01 +01:00
Elias Rohrer b5f5abe0b4 Removed pre-configured IP, now takes IP as argument. 2020-03-03 10:48:01 +01:00
Elias Rohrer 62f5f8e3f9 Removed explicit dependency on rand. 2020-03-03 10:48:01 +01:00
Elias Rohrer 2852083ff3 Using write_all(). 2020-03-03 10:48:01 +01:00
Elias Rohrer c4f0056856 No clone needed. 2020-03-03 10:48:01 +01:00
Elias Rohrer 9d212da0ba Added a simple handshake example. 2020-03-03 10:48:01 +01:00
Steven Roose 826b2e0e2a
Export the util::amount::Denomination type 2020-02-28 11:51:44 +00:00
Steven Roose 9cff794a09
Merge pull request #399 from elichai/2020-01-tests
Add tests based on mutagen outputs
2020-02-24 19:29:19 +00:00
Elichai Turkel 07b30c7fac
Mutation testing: amount: Added tests to fix mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel ab6e20c87e
Fix an overflow bug in SignedAmount to_string/fmt 2020-02-23 15:59:26 +02:00
Elichai Turkel abc70781e7
Fix a logic problem in base58 (isn't a real bug) 2020-02-23 15:59:26 +02:00
Elichai Turkel 1d01262d5c
Mutation testing: base58: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel 5d276caf95
Mutation testing: encode: Added tests to "fix" mutation misses 2020-02-23 15:59:26 +02:00
Elichai Turkel eb7369b1db
Simlify consensus_encode vectors 2020-02-23 15:59:23 +02:00
Andrew Poelstra 1b946b0034
Merge pull request #378 from wbnns/readme-links
readme: Add links to CHANGELOG.md and LICENSE
2020-01-24 19:41:29 +00:00
Andrew Poelstra a2bfcb5a89
Merge pull request #395 from pandoracore/fix-construct_uint
Improving `construct_uint` macro
2020-01-24 19:39:32 +00:00
Andrew Poelstra 659f2edb3b
Merge pull request #381 from elichai/2020-01-hex
Remove the hex dependency
2020-01-24 19:14:20 +00:00
Andrew Poelstra bf6828c47f
Merge pull request #398 from elichai/2020-01-json
Yet another MSRV breaking change
2020-01-23 15:20:42 +00:00
Elichai Turkel 399950bf71
Restrict serde-json dev dependency to less than 1.0.45 2020-01-23 11:45:59 +02:00
Will Binns 410e45f378
readme: Add links to CHANGELOG.md and LICENSE 2020-01-23 10:45:18 +01:00
Dr Maxim Orlovsky 9c0f4b1a60 Fixing namespaces in `impl_hashencode` 2020-01-22 13:23:09 +01:00
Steven Roose 930a6ca1dc
Merge pull request #390 from instagibbs/bip143_sighash_notall
Add bip143 sighash support for other flags
2020-01-21 23:26:17 +00:00
Gregory Sanders d1c5c7b08d Deprecate SigHashComponents 2020-01-21 09:50:41 -05:00
Gregory Sanders 908aff50bc Add bip143 sighash support for other flags 2020-01-21 09:50:41 -05:00
Dr Maxim Orlovsky f3e762b555 Improving `construct_uint` macro 2020-01-21 13:16:34 +01:00
Elichai Turkel c19b736566
Remove the hex dependency 2020-01-20 18:50:02 +02:00
Elichai Turkel 5452260884
Merge pull request #392 from instagibbs/wit_scale
Add, use WITNESS_SCALE_FACTOR constant
2020-01-20 18:02:59 +02:00
Gregory Sanders 2916685ca6 small Transaction test cleanup 2020-01-14 11:14:23 -05:00
Gregory Sanders 3624ee82c8 Use witness scaling constant in get_weight 2020-01-14 11:14:23 -05:00
Gregory Sanders 09c0e7fbde Add WITNESS_SCALE_FACTOR constant 2020-01-14 11:14:23 -05:00
Steven Roose e76803be85
Merge pull request #385 from stevenroose/no-bitcoin-hash
Remove the BitcoinHash trait
2020-01-13 16:45:31 +01:00
Steven Roose 8e52b8ce4d
Remove the BitcoinHash trait
Replaced by a `block_hash` method on both `Block` and `BlockHeader`.
2020-01-10 11:34:16 +00:00
Andrew Poelstra 2cba81935d
Merge pull request #380 from stevenroose/bump-0.23
Release v0.23.0
2020-01-09 17:02:43 +00:00
Steven Roose 2326dd6a82
Update secp256k1's rand feature to rand-std 2020-01-09 11:11:49 +00:00
Steven Roose 2f89c943e1
Release v0.23.0 2020-01-07 19:27:05 +00:00
Steven Roose 7587c4bf71
Merge pull request #379 from kiminuo/feature/network_address_debug
Improve fmt::Debug for network/Address
2020-01-07 17:39:14 +00:00
Steven Roose e6bc3ec974
Merge pull request #366 from stevenroose/bump-secp
Release v0.22.0
2020-01-07 16:05:29 +00:00
kiminuo 9e223988fa Improve fmt::Debug for network/Address
Original output:

  "Address {services: ServiceFlags(9), address: [0, 0, 0, 0, 0, 65535, 2560, 1], port: 8333}"

New output:

  * for IPv4: "Address {services: ServiceFlags(NETWORK|WITNESS), address: 10.0.0.1, port: 8333}"
  * for IPv6: "Address {services: ServiceFlags(NETWORK_LIMITED), address: fd87:d87e:eb43::ffff:a00:1, port: 8333}"
2020-01-07 12:30:47 +01:00
Andrew Cann d156c65778 Fix serde struct macros deserialization impls
The Deserialize impls generated by serde_struct_impl and
serde_struct_human_string_impl need to be able to handle serialization
formats which serialize structs as sequences (such as bincode).

This commit adds visit_seq methods to the Visitor types defined by these
macros, in addition to the existing visit_map methods. The
implementation is taken directly from the serde docs:
https://serde.rs/deserialize-struct.html
2020-01-07 13:19:22 +08:00
Steven Roose 448b45a3ba
Bump version to v0.22.0 2020-01-06 22:36:15 +00:00
Steven Roose 0398ef8f48
Update changelog for v0.22.0 2020-01-06 22:36:14 +00:00
Andrew Poelstra 50f3a60712
Merge pull request #349 from pandoracore/hashtypes
Hash new types as specified in #284
2020-01-05 00:46:45 +00:00
Dr Maxim Orlovsky 5fc24dea33 Multiple fixes for hash types and their computing
Unit test for wtxid and SegWit transactions
2020-01-01 13:54:23 +01:00
Dr Maxim Orlovsky 0abe15b1f6 Moving from BitcoinHash to Wtxid for Transactions 2020-01-01 13:52:20 +01:00
Dr Maxim Orlovsky f5a8087105 New hash types: MerkleRoot/Branch, WitnessCommit, SigHash, FilterHash 2020-01-01 13:50:17 +01:00
Dr Maxim Orlovsky 4746ccb88e Final work on Txid and other hashes
Fixing issue with external dependency and hash_newtype macro implementation

Reverting back to the bitcoin_hashes crate after new version release
2020-01-01 13:48:28 +01:00
Dr Maxim Orlovsky d20ab1dbc4 Switching to XpubIdentifier 2020-01-01 13:46:44 +01:00
Dr Maxim Orlovsky 5f4f629bb1 Replaced all hash160, sha256 and sha256d with the new hash types throughout the code
Embedding Txid's in the doc exaples
2020-01-01 13:44:34 +01:00
Dr Maxim Orlovsky 5ef39e34fa Implementing (W)Pubkey/ScriptHash and BlockHash 2020-01-01 13:42:22 +01:00
Dr Maxim Orlovsky ec92a05682 New HashTypes defined according to #284 (WIP), Txid is completed 2020-01-01 13:41:42 +01:00
Steven Roose e2caebc42e
Merge pull request #370 from elichai/2019-12-rawmessage
Add a full round test for RawNetworkMessage
2019-12-23 12:30:11 +01:00
Andrew Poelstra efd2168364
Merge pull request #368 from mauzmorose/bip157-service-flag
bip157: Add NODE_COMPACT_FILTERS Service Flag
2019-12-22 16:48:16 +00:00
Elichai Turkel bc2ba5bb12
Add a full round test for RawNetworkMessage 2019-12-22 14:01:12 +02:00
Elichai Turkel 4c3ad9d233
Merge pull request #367 from mauzmorose/fix-bip157-message
bip157: Fix typo on getcfcheckpt command string
2019-12-22 13:59:54 +02:00
Sofiane Baltaci 8617de51c8 Adapt service_flags_test to reflect changes 2019-12-21 03:36:47 +01:00
Sofiane Baltaci 43789b1d5a Add COMPACT_FILTERS service flag to ServiceFlags fmt::Display impl 2019-12-21 03:06:03 +01:00
Sofiane Baltaci b40d94641d Add bip157 NODE_COMPACT_FILTERS Service Flag 2019-12-21 02:39:30 +01:00
Sofiane Baltaci 2605141ada Fix typo on getcfcheckpt command string 2019-12-20 23:47:40 +01:00
Andrew Poelstra a643ac485c
Merge pull request #364 from kiminuo/feature/explicit-serviceFlags
Convert numeric representation of ServiceFlags to bitwise OR of the f…
2019-12-12 13:35:01 +00:00
kiminuo 74285738ce Convert numeric representation of ServiceFlags to bitwise OR of the flag names
The changes affect only tests
2019-12-12 00:11:13 +01:00
Steven Roose 0f4f060e8b
Merge pull request #363 from kiminuo/feature/remove-old-todos
Remove two old TODO comments [nit]
2019-12-11 16:53:20 +00:00
Steven Roose 024557fe47
Merge pull request #357 from stevenroose/command-str
Various optimizations of the network code
2019-12-11 15:38:52 +00:00
kiminuo 269ddb6f07 Remove some old TODO comments 2019-12-11 08:26:04 +01:00
Andrew Poelstra f6f4ea79d6
Merge pull request #360 from kiminuo/feature/issue-350
Feature/issue 350
2019-12-10 20:52:21 +00:00
Steven Roose a8f14af24d
Prevent panic on oversized CommandString's 2019-12-10 20:20:04 +00:00
Andrew Poelstra fef3390d78
Merge pull request #329 from stevenroose/overloaded-encode-error
Overloaded encode error
2019-12-10 13:23:56 +00:00
Steven Roose 617c07d796
Remove encode::Error::ByteOrder
Functions from the byteorder crate only return downstream io errors on
io calls.
2019-12-09 14:19:11 +00:00
Steven Roose 5f4555bfac
Remove util::misc::hex_bytes in favor of bitcoin_hashes::hex 2019-12-09 14:19:09 +00:00
Steven Roose 0469453da6
Use psbt::Error in PartiallySignedTransaction::from_unsigned_tx 2019-12-09 14:19:07 +00:00
Steven Roose 1eeaccc92e
Add encode::Error::NonMinimalVarInt variant 2019-12-09 14:19:05 +00:00
Steven Roose d02318f423
Remove deprecated std::error::Error::description 2019-12-09 14:18:37 +00:00
Steven Roose 5373428510
Drop unused encode::Error::Secp256k1 variant 2019-12-09 14:17:41 +00:00
Steven Roose 725884bab5
Introduce key::Error 2019-12-09 14:17:39 +00:00
Andrew Poelstra 1d209362eb
Merge pull request #361 from stevenroose/inventory-hash
Implement std:#️⃣:Hash for Inventory
2019-12-09 00:43:03 +00:00
Steven Roose fe3397399e
Add Copy to InvType enum 2019-12-08 20:58:52 +00:00
Steven Roose 671b3173c8
Make internals for CommandString private
The From traits and AsRef and Display implementations
let you do all you want.
2019-12-08 20:58:50 +00:00
Steven Roose 83f55b7f1d
Follow Rust std practice for RejectReason enum 2019-12-08 20:58:49 +00:00
Steven Roose 5c84e9671f
Optimize Reject message 2019-12-08 20:58:46 +00:00
Steven Roose c30d6d12ab
Implement Encodable for Cow<'static, str> 2019-12-08 20:57:46 +00:00
Steven Roose e37fdb7319
Also have getter for CommandString 2019-12-08 20:57:07 +00:00
Steven Roose e2eed78964
nit: Reject is implemented 2019-12-08 20:57:05 +00:00
Steven Roose 50a37f415e
Implement From<String> and From<&'static str> for CommandString 2019-12-08 20:57:04 +00:00
Steven Roose 36838b7918
Make network::CommandString a Cow on 'static 2019-12-08 20:57:03 +00:00
Steven Roose bac3e0308b
Add command method to NetworkMessage
Also make the return type an &'static str
2019-12-08 20:57:00 +00:00
Steven Roose b4c4a9658d
Implement std:#️⃣:Hash for Inventory 2019-12-08 17:49:11 +00:00
Kiminuo d8223bb73c Update travis-fuzz.sh to check that fuzz input file names are allowed on Windows systems 2019-12-08 16:42:43 +00:00
Kiminuo 1b617b8f54 Rename fuzz input file names to allow repo cloning on Windows [fixes #350] 2019-12-08 16:42:43 +00:00
Andrew Poelstra 854718219e
Merge pull request #345 from stevenroose/serviceflags
Add ServiceFlags type
2019-12-06 21:31:46 +00:00
Andrew Poelstra 65cb18d583
Merge pull request #341 from ccdle12/txin-impl-default
Add default trait implementation for TxIn
2019-12-06 21:21:49 +00:00
Steven Roose 3e1e4f92b7
Merge pull request #337 from TheBlueMatt/2019-10-less-deps
Drop hex and byteorder (non-test) deps (and disable useless lints)
2019-12-06 15:38:58 +00:00
Steven Roose 1edc436f8f
Add an extensive Display implementation for ServiceFlags 2019-12-05 20:13:45 +00:00
Elichai Turkel 0ae99100eb
Merge pull request #343 from stevenroose/nit-versionmessage
Nit in VersionMessage documentation
2019-12-05 18:19:43 +02:00
Matt Corallo 824d52fe87 Disable useless lints 2019-12-05 10:41:00 -05:00
Matt Corallo acb43af981 Drop byteorder dependency
Taking an external dependency just to convert ints to byte arrays
is somewhat of a waste, especially when Rust isn't very aggressive
about doing cross-crate LTO.

Note that the latest LLVM pattern-matches this, and while I haven't
tested it, that should mean this means no loss of optimization.
2019-12-05 10:41:00 -05:00
Matt Corallo f1f7718b6c Drop (non-test/serde) hex dep in favor of bitcoin_hashes' fn's 2019-12-05 10:40:59 -05:00
Steven Roose 6ce582bed6
Merge pull request #344 from thomaseizinger/expose=secp256k1-features
Expose secp256k1 features
2019-12-04 23:42:54 +00:00
Steven Roose de18e926c1
Use ServiceFlags type in existing API 2019-12-04 23:28:25 +00:00
Steven Roose fdf4b2f74e
Add ServiceFlags type 2019-12-04 23:28:23 +00:00
Andrew Poelstra 885fc39f48
Merge pull request #347 from elichai/patch-1
Adding MSRV to the readme
2019-11-29 21:26:23 +00:00
Elichai Turkel 62a7f26e9b
Update README.md 2019-11-23 18:44:19 +02:00
Thomas Eizinger 7be4ac0403
Include secp256k1 'serde' feature flag in 'use-serde' feature 2019-11-21 12:06:06 +11:00
Thomas Eizinger 24bb6590d6
Expose secp256k1 'rand' feature flag
By exposing this, we can use the 'rand' dependency of secp256k1
in a project that only depends on rust-bitcoin without having to
add a separate dependency in order to activate the feature flag.
2019-11-21 12:05:46 +11:00
Steven Roose 33ba7eaa36
Nit in VersionMessage documentation 2019-11-19 22:58:49 +00:00
Chris Coverdale 0586ed94c4 Add default trait implementation for TxIn 2019-11-17 16:41:14 +00:00
Andrew Poelstra 700ed54efc
Merge pull request #340 from TheBlueMatt/2019-11-4m-limit
Drop message decode max length to 4_000_000
2019-11-12 20:42:51 +00:00
Matt Corallo fe917765c0 Drop message decode max length to 4_000_000
It has been a long time since Bitcoin's maximum network message
length was 32MB, so we should follow suit. This is also an important
DoS limit, so we should limit it as much as possible.
2019-11-06 16:29:21 -05:00
Andrew Poelstra c8ac25219a
Merge pull request #334 from apoelstra/2019-10-version-0.21
bump version to 0.21.0
2019-10-03 16:09:38 +00:00
Andrew Poelstra fb6f50b0ea bump version to 0.21.0 2019-10-02 15:42:58 +00:00
Carl Dong 242ce14cee
Add reject message (#323)
Add reject message
2019-09-30 14:52:19 +00:00
Dr. Maxim Orlovsky 4b1d4edc14 Improvements to `StreamReader` (#318)
* Generalizing StreamReader to support arbitrary data structures

* Using Read trait and adding test cases
2019-09-23 08:31:52 +02:00
practicalswift 0b08978af2 Fix incorrect documentation for is_p2pk(...) (#331) 2019-09-21 13:33:44 +02:00
Tamas Blummer 1b0e31c233 fixed typo 2019-09-21 13:31:03 +02:00
Tamas Blummer 960e3da75b remove #repr on RejectReason
and typo fix
2019-09-10 20:11:25 +02:00
Steven Roose de9ccdec89
Merge pull request #321 from tamasblummer/add_serde_to_block
[TRIVIAL] enable serde serialization for block and blockheader
2019-09-05 09:36:57 +01:00
Tamas Blummer c93b1ed8ce add reverse mapping 2019-09-03 19:59:48 +02:00
Tamas Blummer 3266c192b6 add reject message 2019-08-27 13:42:46 +02:00
Tamas Blummer 38d5ae4e3f enable serde serialization for block and blockheader 2019-08-24 14:26:18 +02:00
Carl Dong 24361dd2f1
Merge pull request #298 from tamasblummer/upgrade_secp_bitcoinconsensus
upgrade to secp256k1 0.15 and bitcoinconsensus 0.17
2019-08-23 14:18:05 -04:00
Tamás Blummer f01568c85a
use lambda instead of a hash map to find spent outputs (#319)
* use lambda instead of a hash map to find spent outputs
* check for double use of an input
2019-08-23 18:49:31 +02:00
Tamas Blummer 78a4f09861 nit 2019-08-22 16:21:16 +02:00
Tamas Blummer 14e61df578 move rand feature of secp256k1 into dev-dependencies 2019-08-22 08:58:58 +02:00
Tamas Blummer d91fa99df0 add CHANGELOG.md entry 2019-08-21 20:59:40 +02:00
Tamas Blummer 76ec4ad820 single line dependencies. setting cargo version to 0.20.0 2019-08-21 20:13:53 +02:00
Tamas Blummer 9f3e355c5c upgrade to secp256k1 0.15 and bitcoinconsensus 0.17 2019-08-21 19:04:40 +02:00
Andrew Poelstra 8ff904c747
Merge pull request #317 from elichai/2019-08-serde
Remove serde-derive as a dependency
2019-08-20 18:17:22 +00:00
Elichai Turkel 837030b04f
Bump version to 0.19.2 2019-08-20 13:28:58 -04:00
Elichai Turkel 89f73ea686
Add a test for testing as a dependency 2019-08-19 13:29:50 -04:00
Elichai Turkel 52ff97cddc
Deny unused imports and remove unneeded 2019-08-19 13:29:43 -04:00
Elichai Turkel df1a5fd6b5
Remove serde-derive as a dependency 2019-08-19 13:29:38 -04:00
Andrew Poelstra 4556c9c570
Merge pull request #316 from elichai/2019-08-pin-export
Pin serde and re-export bech32
2019-08-16 21:22:11 +00:00
Elichai Turkel 0153061647
Bump version to 0.19.1 2019-08-16 16:08:36 -04:00
Elichai Turkel 747e9ce75c
Pinned serde version and re-export bech32 2019-08-16 16:08:14 -04:00
Andrew Poelstra fbc85105b3
Merge pull request #314 from stevenroose/release-0.19.0
Release v0.19.0
2019-08-16 19:29:03 +00:00
Steven Roose 6651cf942b
Merge pull request #315 from elichai/2019-08-deps
Make secp256k1/rand a dev-dependency
2019-08-16 19:05:02 +01:00
Steven Roose 5a4b5826d7
Add CHANGELOG items about dependencies 2019-08-16 19:00:02 +01:00
Elichai Turkel 3bab3e7ea2
make secp256k1/rand a dev-dependency 2019-08-16 13:18:15 -04:00
Steven Roose a472039301
Release v0.19.0 2019-08-16 16:41:08 +01:00
Carl Dong 166e2bd121
Export some dependencies (#289)
Export some dependencies
2019-08-16 11:19:08 -04:00
Steven Roose c01172780b
Re-export bitcoin_hashes and secp256k1 dependency 2019-08-16 15:52:58 +01:00
Steven Roose 48f4c1989f
Rename bitcoin_hashes dependency to hashes 2019-08-16 15:52:27 +01:00
Carl Dong 5f4de0fb46
Refactor Address (#255)
Refactor Address
2019-08-16 10:22:42 -04:00
Steven Roose 3c390ceb93
Add fuzzer for Address::from_script 2019-08-15 22:29:10 +01:00
Steven Roose 09a65023a2
Add tests for p2shwpkh and p2shwsh 2019-08-15 22:29:09 +01:00
Steven Roose 170abaa82f
Use the new bech32 functions 2019-08-15 22:29:06 +01:00
Steven Roose 3a93f8522c
Format address module 2019-08-15 22:28:46 +01:00
Steven Roose 8de13a3915
Redo the BIP-173 test vectors
Before, non-version-zero segwit addresses were not included.
2019-08-15 22:28:27 +01:00
Steven Roose e469fec839
address: Drop error::Error::description impl 2019-08-15 22:28:25 +01:00
Steven Roose bfdcfee28e
Add Address::from_script constructor 2019-08-15 22:28:20 +01:00
Steven Roose 33e8ba3c7e
Extract roundtrip method from Address tests 2019-08-13 08:47:17 +01:00
Steven Roose 8804a41f1f
Add AddressType enum 2019-08-13 08:47:15 +01:00
Steven Roose 7e0d997150
Remove unused encode::Error variant 2019-08-13 08:47:13 +01:00
Steven Roose 385a657974
Refactor Address
- use AddressError instead of encode::Error
- replace using bech32-bitcoin with Payload::WitnessProgram variant
2019-08-13 08:47:10 +01:00
Andrew Poelstra cc0f1143dc
Merge pull request #309 from elichai/2019-08-amount-precision
Check that the amount precision isn't more than the size of the amount
2019-08-12 17:20:18 +00:00
Tim Ruffing fb272160c3 Remove accidentally added file (#312) 2019-08-11 12:04:19 +02:00
Riccardo Casatta 7d6687451a use BTreeMap instead of HashMap to always serialize the same (#310)
* use BTreeMap instead of HashMap to always serialize the same

* fix rust 1.22 error

* psbt fuzz roundtrip

* psbt fuzz roundtrip on our ser
2019-08-09 17:03:12 +02:00
Tamás Blummer 4ddf6f80b9
Reduce blockfilter memory (#302)
* use same Error type in all methods of BlockFilter

* reduce Blockfilter memory footprint

* amend the example use

* remove unused constant
2019-08-09 16:58:02 +02:00
Elichai Turkel a9e65f36d3
Check that the amount precision isn't more than the size of the amount 2019-08-09 10:41:21 -04:00
Elichai Turkel 4a1830c423 Replaced Read trait with a generic over Read (#307)
Removed tempfile usage from stream_reader
2019-08-07 17:35:22 +02:00
Andrew Poelstra db8c8b497b
Merge pull request #303 from practicalswift/typos
Fix typos
2019-08-05 15:16:17 +00:00
Andrew Poelstra c3f3a2bee0
Merge pull request #304 from Aleru/master
Test negative numbers
2019-08-05 15:15:49 +00:00
Aleru 40c5a568fa add TODOs 2019-08-04 22:27:59 -04:00
practicalswift 8152ed758c Fix typos 2019-08-04 19:27:36 +00:00
Andrew Poelstra 2e915bf7ef
Merge pull request #271 from stevenroose/serde-outpoint
Add special human-readable serde for OutPoint and most bip32 types
2019-08-02 22:01:17 +00:00
Andrew Poelstra caae4b7a3f
Merge pull request #297 from dongcarl/2019-07-codecov
Generate codecov.io reports
2019-07-29 12:32:45 +00:00
Steven Roose cc2ede7a80
Use `$crate::` prefix for uses in macros 2019-07-29 11:30:35 +02:00
Carl Dong 3207ac5ea7
Generate codecov.io reports 2019-07-26 15:48:52 -04:00
Steven Roose 2c2d55d90a
bip32: Implement hex serialization for Fingerprint and ChainCode 2019-07-26 15:32:33 +02:00
Steven Roose 4530e403e0
Use collect_str instead of serialize_str in serde macros 2019-07-26 15:30:47 +02:00
Steven Roose fc6415d652
Add human-readable serde for OutPoint as `<txid>:<vout>` 2019-07-26 15:30:46 +02:00
Steven Roose 3c66418f3a
bip32: Add serde for Extended(Priv|Pub)Key 2019-07-26 15:30:44 +02:00
Tamás Blummer c93a70487f
Add client side block filter (BIP158) (#281)
* add client side block filters with code from murmel. use siphash from bitcoin_hashes pass Bitcoin Core tests upgrade to bitcoin_hashes 0.7

* add filter.filter_id() test use BlockFilter directly

* fixed edge cases of matching empty query sets or or using empty filter
2019-07-26 09:36:25 +02:00
Andrew Poelstra b6c1266102
Merge pull request #293 from stevenroose/bip143-script-code
bip143: Rename witness_script to script_code
2019-07-24 22:43:58 +00:00
Andrew Poelstra a041168205
Merge pull request #265 from apoelstra/2019-05-enc-dec-cleanup
clean up encoding/decoding traits
2019-07-24 19:30:21 +00:00
Andrew Poelstra 0fc7b28cfc
Merge pull request #295 from tamasblummer/forbid_unsafe
forbid unsafe
2019-07-24 17:49:51 +00:00
Tamas Blummer ff2f5d9ec2 forbid unsafe 2019-07-23 23:29:45 +02:00
Steven Roose b312c4de6a
bip143: Rename witness_script to script_code
For p2wsh the scriptCode is the witness script, but for p2wpkh, it's the
equivalent legacy p2pkh output script.
The name scriptCode is used in the BIP, so it's less confusing.
2019-07-15 17:33:23 +02:00
Andrew Poelstra 3b9a94a178 eliminate type parameter from the `Decodable` trait 2019-07-11 17:23:01 +00:00
Andrew Poelstra 42960b959f eliminate type parameter from `Encodable` trait 2019-07-11 17:21:19 +00:00
Andrew Poelstra 87e7ebcf1b prevent compilation on 16-bit targets so we can use `usize` and assume it is 32 bits 2019-07-11 17:15:33 +00:00
Andrew Poelstra b734d6488a make consensus_encode return the encoded length 2019-07-11 17:15:32 +00:00
Andrew Poelstra abb9210c04 make `VarInt::len` and `Transaction::get_weight` return a usize 2019-07-11 17:14:05 +00:00
Andrew Poelstra 7e6ad7c893 rename Encoder to WriteExt and Decoder to ReadExt 2019-07-11 15:01:38 +00:00
Andrew Poelstra 24ebc29005 fix some recent rustc warnings 2019-07-11 15:01:38 +00:00
Andrew Poelstra 783948446c
Merge pull request #268 from erasmospunk/merkleblock
Add a MerkleBlock construction
2019-07-10 17:56:04 +00:00
John L. Jegutanis aae2937d11 Add a MerkleBlock construction
This is a port of the bitcoin-core CPartialMerkleTree and CMerkleBlock classes.
Here they are called PartialMerkleTree and MerkleBlock.

These are useful for SPV clients that wish to verify that a transaction is
present in a specific block in an authenticated way.
2019-07-05 20:44:31 +02:00
John L. Jegutanis 56f98e00a0 Changed constants from `static` to `const` and added 2 new constants 2019-07-05 15:01:54 +02:00
Andrew Poelstra 1a4bb371a1
Merge pull request #286 from apoelstra/2019-06-builder-ext
script: give `Builder` ability to verify-ify opcodes
2019-07-03 21:50:57 +00:00
Andrew Poelstra cded694381
Merge pull request #277 from jonasnick/rand
Remove unused rand dependency
2019-07-03 20:42:44 +00:00
Andrew Poelstra bb48a2cf2f
Merge pull request #274 from stevenroose/readme
Slightly update README
2019-07-03 17:32:38 +00:00
Andrew Poelstra b2727b6ebe
Merge pull request #250 from stevenroose/no-strason
Remove Decimal and replace strason with serde_json
2019-07-03 17:30:21 +00:00
Andrew Poelstra a11412862c script: give `Builder` ability to verify-ify opcodes 2019-06-29 21:26:56 +00:00
Steven Roose 560a709faa Add OutPoint::new() for one-liner construction (#285) 2019-06-24 18:49:20 +02:00
Steven Roose 0343559ae0
Slightly update README 2019-06-17 11:46:54 +01:00
Andrew Poelstra b13e4628f9
Merge pull request #282 from stevenroose/cltv-csv
Rename OP_NOP2 and OP_NOP3 to OP_CLTV and OP_CSV
2019-06-15 19:12:06 +00:00
Steven Roose d2923b7cce
Rename OP_NOP2 and OP_NOP3 to OP_CLTV and OP_CSV 2019-06-13 18:56:35 +01:00
Steven Roose 30201f3924
Remove Decimal and replace strason with serde_json 2019-06-13 18:29:16 +01:00
Jonas Nick 94fba3aa88 Remove unused rand dependency 2019-06-10 13:59:31 +00:00
Matt Corallo 330e0fd587
Merge pull request #276 from jonasnick/remove-spv
Remove confusing mentions of SPV
2019-06-08 06:56:44 -04:00
Jonas Nick 30f24a39d0 Remove confusing mentions of SPV 2019-06-07 13:12:07 +00:00
Matt Corallo 860e74ecb5
Merge pull request #273 from stevenroose/spv-validate
Rename BlockHeader::spv_validate to validate_pow
2019-06-07 08:24:47 -04:00
Andrew Poelstra 5d7e6bb7a4
Merge pull request #272 from TheBlueMatt/2019-05-net-cleanups
Fix DoS in RawNetworkMessage Deserialization
2019-06-07 11:53:31 +00:00
Matt Corallo 0904935f19 Switch Travis fuzzing to 30 seconds per target from an iter count. 2019-06-07 07:11:21 -04:00
Andrew Poelstra a6c1eacd70
Merge pull request #270 from stevenroose/signed-amount
Add Amount and SignedAmount
2019-06-07 09:16:02 +00:00
Steven Roose 093d60bf7f
Rename BlockHeader::spv_validate to validate_pow 2019-06-06 10:39:03 +01:00
Matt Corallo 1b2dc9d6b0 Rename deserialize_raw_network_message to make my afl scripts happy 2019-06-05 07:49:19 -04:00
Carl Dong 836fdce475 fuzz: Add fuzzer for RawNetworkMessage. 2019-06-05 07:49:19 -04:00
Matt Corallo 98796576d2 Fix trivial DoS when deserializing messages from the network 2019-06-05 07:49:19 -04:00
Andrew Poelstra 08c756d20e
Merge pull request #264 from TheBlueMatt/2019-05-faster-enc-dec
Speed up consensus::[d]encode significantly
2019-06-05 11:46:56 +00:00
Steven Roose 7af134ce79
Add fuzz target for Amount parsing 2019-06-04 12:54:12 +01:00
Steven Roose 688d95b463
Add Amount and SignedAmount types 2019-05-31 10:18:59 +01:00
Steven Roose d4282353c9
Two serde quirks from switching dependencies 2019-05-31 10:18:57 +01:00
Matt Corallo 2b6058e335 Decrease travis-fuzz iterations to fix hangs 2019-05-30 11:25:37 -04:00
Matt Corallo fa1ec2028d Speed up Vec<u8> [d]e[n]code operations by dropping the generic 2019-05-30 11:25:37 -04:00
Matt Corallo ee827e4aa3 Drop some unused/not-needed Encodable impls 2019-05-30 11:25:37 -04:00
Matt Corallo 84835f244c Support sendheaders network message decode 2019-05-30 11:25:37 -04:00
Matt Corallo 084f82be21 Swap a few more [d]encoders to slice emit/read functions 2019-05-30 11:25:37 -04:00
Matt Corallo 7015b064dd Add slice consensus encode/decode functions and use for short arrays 2019-05-30 11:25:37 -04:00
Andrew Poelstra 4139f2a1ca
Merge pull request #258 from shesek/signed-msg-hash
Implement util::misc::signed_msg_hash()
2019-05-30 14:35:57 +00:00
Andrew Poelstra e0205fc9fa
Merge pull request #260 from TheBlueMatt/2019-05-headers-no-pub-wrapper
Drop LoneHeaders and just use BlockHeader
2019-05-21 20:30:35 +00:00
Matt Corallo 4f96a87475 Drop LoneHeaders and just use BlockHeader
The protocol has a bug where a 0u8 is pushed at the end of each
block header on the wire in headers messages. WHy this bug came
about is unrealted and shouldn't impact API design.
2019-05-17 17:55:02 -04:00
Andrew Poelstra b471a12487
Merge pull request #257 from stevenroose/bip32-increment
bip32: Add increment method to DerivationPath and ChildNumber
2019-05-04 21:25:21 +00:00
Steven Roose bb8520268e
bip32: Add DerivationPathIterator and related methods
Adds methods
- ChildNumber::increment
- DerivationPath::children_from
- DerivationPath::normal_children
- DerivationPath::hardened_children
2019-05-03 17:58:09 +01:00
Andrew Poelstra b75e154dd8
Merge pull request #256 from stevenroose/nit-changelog
Fix nit in CHANGELOG.md
2019-05-02 20:31:42 +00:00
Nadav Ivgi 473b491409
Implement util::misc::signed_msg_hash() 2019-04-28 09:01:42 +03:00
Steven Roose 8f2719016e
Fix nit in CHANGELOG.md 2019-04-26 15:07:18 +01:00
Andrew Poelstra 214345745b
Merge pull request #248 from apoelstra/2019-03-0.18
bump version to 0.18
2019-03-22 15:22:35 +00:00
Andrew Poelstra b9e44e4ffd bump version to 0.18 2019-03-21 23:20:06 +00:00
Andrew Poelstra b94d0fcf24
Merge pull request #247 from apoelstra/2019-03-contracthash
contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups
2019-03-21 23:05:43 +00:00
Andrew Poelstra dc6189dbb2 contracthash: more cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 01a3a9263c contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 3700d100eb contracthash: add fixed test vector 2019-03-21 21:27:26 +00:00
Andrew Poelstra cea49b6522
Merge pull request #246 from apoelstra/2019-03-key-serde
util::key add serde de/serialization
2019-03-21 21:26:25 +00:00
Andrew Poelstra 9daf7fa9dc util::key add serde de/serialization 2019-03-21 18:27:42 +00:00
Carl Dong 221e53b13e
Merge pull request #243 from stevenroose/pubkey-serialize
util:🔑 Provide to_bytes() methods for key types
2019-03-06 21:44:02 -05:00
Carl Dong d667e0f894
Merge pull request #244 from stevenroose/bech32-bump
Bump bitcoin-bech32 dependency
2019-03-06 21:43:36 -05:00
Steven Roose 459059622f
util:🔑 Provide to_bytes() methods for key types
These are mainly utility methods around the existing way to serialize
the key types.
2019-03-05 16:07:52 +00:00
Steven Roose 750da89992
Bump bitcoin-bech32 dependency
This makes the Address::Payload::WitnessProgram inner type compatible
with rust-lightning-invoice's Fallback::SegWitProgram's inner type.
This allows specifying fallbacks from addresses.
2019-03-04 21:15:28 +00:00
Andrew Poelstra 08c6435eb7
Merge pull request #242 from apoelstra/2019-03-0.17.1
bump version to 0.17.1
2019-03-04 20:20:38 +00:00
Andrew Poelstra d5c1200590 bump version to 0.17.1 2019-03-04 17:51:38 +00:00
Andrew Poelstra 7e1a6a4ab7
Merge pull request #241 from apoelstra/2019-03-pubkey-string
key: implement ToString and FromStr for PublicKey
2019-03-04 17:47:36 +00:00
Andrew Poelstra 049f75e502 script: add `push_key` function to Builder to allow serializing public keys more easily 2019-03-04 01:32:35 +00:00
Andrew Poelstra 4dbf431ecd key: implement ToString and FromStr for PublicKey 2019-03-04 01:06:19 +00:00
Andrew Poelstra 8aa964ce43
Merge pull request #239 from apoelstra/2019-02-0.17
bump version to 0.17.0
2019-03-01 19:43:51 +00:00
Andrew Poelstra 8e214ffa90 add #231 to CHANGELOG for 0.17.0 2019-03-01 16:13:56 +00:00
Andrew Poelstra c342bf3731 bump version to 0.17.0 2019-02-28 22:02:45 +00:00
Andrew Poelstra 67e4671457
Merge pull request #103 from dongcarl/psbt
BIP174 (de)serialization support
2019-02-28 17:20:37 +00:00
Carl Dong e5b59120c5 Add copyright notice to PSBT-related files 2019-02-28 11:11:55 -05:00
Carl Dong f74ec3e187 Add fuzz testing for PartiallySignedTransaction 2019-02-28 11:11:55 -05:00
Carl Dong bc73b315cb Add test vectors from BIP174 specification
- Add macro for decoding and unwrapping PartiallySignedTransaction from
  hex string
2019-02-28 11:11:55 -05:00
Carl Dong 39fd567b56 Add Partially Signed Transaction type
- Add merging logic for PartiallySignedTransactions
- Add (en)decoding logic for PartiallySignedTransaction
- Add converting constructor logic from Transaction for
  PartiallySignedTransaction
- Add extracting constructor logic from PartiallySignedTransaction for
  Transaction

Squashed in fixes from stevenroose <stevenroose@gmail.com>

- Prevent PSBT::extract_tx from panicking
- Make PartiallySignedTransaction fields public
2019-02-28 11:11:55 -05:00
Carl Dong badb0f2a77 Add PSBT input data key-value map type
- Implement psbt::Map trait for psbt::Input
- Add (en)decoding logic for psbt::Input

- Implement PSBT (de)serialization trait for relevant psbt::Input types
2019-02-28 11:11:55 -05:00
Carl Dong 9c08dbae47 Add PSBT output data key-value map type
- Implement psbt::Map trait for psbt::Output
- Add (en)decoding logic for psbt::Output

- Implement PSBT (de)serialization trait for relevant psbt::Output types

- Add macro for merging fields for PSBT key-value maps
- Add macro for implementing decoding logic for PSBT key-value maps
- Add convenience macro for implementing both encoding and decoding
  logic for PSBT key-value maps
- Add macro for inserting raw PSBT key-value pairs into PSBT key-value
  maps
- Add macro for getting raw PSBT key-value pairs from PSBT key-value
  maps
2019-02-28 10:54:53 -05:00
Carl Dong 115f8c043c Add PSBT global data key-value map type
- Implement psbt::Map trait for psbt::Global
- Add converting constructor logic from Transaction for psbt::Global
- Add (en)decoding logic for psbt::Global
  - Always deserialize unsigned_tx as non-witness

- Add trait for PSBT (de)serialization
- Implement PSBT (de)serialization trait for relevant psbt::Global types

- Add macros for consensus::encode-backed PSBT (de)serialization
  implementations
- Add macro for implementing encoding logic for PSBT key-value maps
2019-02-28 10:54:53 -05:00
Carl Dong 2715a6e777 Add trait for PSBT key-value maps 2019-02-28 10:54:53 -05:00
Carl Dong 528e39334c Add data types for raw PSBT key-value pairs
- Add (en)decoding logic for said data types
2019-02-28 10:54:53 -05:00
Carl Dong 4fa39c4a3e Add PSBT-specific Error data type
- Implement psbt::Error data type
- Implement conversion from psbt::Error to util::Error
- Create util::psbt module
- Create non-public util::psbt::error module
2019-02-28 10:54:53 -05:00
Andrew Poelstra 919bbeae4a
Merge pull request #238 from apoelstra/2019-02-bip32-keys
Replace `secp256k1` keys with `util::key` keys in BIP32
2019-02-28 13:42:50 +00:00
Andrew Poelstra 4f74ae61c4 bip32: replace rust-secp key types with rust-bitcoin key types
We continue to support only compressed keys when doing key derivation,
but de/serialization of uncompressed keys will now work, and it will
be easier/more consistent to implement PSBT on top of this.
2019-02-27 22:21:40 +00:00
Dr. Maxim Orlovsky 3c21e301aa Better RawNewtorkMessage deserealization from IO stream (#231)
Follow-up to https://github.com/rust-bitcoin/rust-bitcoin/pull/229

While working with remote peers over the network it is required to deserealize RawNetworkMessage from `TCPStream` to read the incoming messages. These messages can be partial – or one TCP packet can contain few of them. To make the library usable for such use cases, I have implemented the required functionality and covered it with unit tests.

Sample usage:
```rust
fn run() -> Result<(), Error> {
    // Opening stream to the remote bitcoind peer
    let mut stream = TcpStream::connect(SocketAddr::from(([37, 187, 0, 47], 8333));
    let start = SystemTime::now();

    // Constructing and sending `version` message to get some messages back from the remote peer
    let since_the_epoch = start.duration_since(UNIX_EPOCH)
        .expect("Time went backwards");
    let version_msg = message::RawNetworkMessage {
        magic: constants::Network::Bitcoin.magic(),
        payload: message::NetworkMessage::Version(message_network::VersionMessage::new(
            0,
            since_the_epoch.as_secs() as i64,
            address::Address::new(receiver, 0),
            address::Address::new(receiver, 0),
            0,
            String::from("macx0r"),
            0
        ))
    };
    stream.write(encode::serialize(&version_msg).as_slice())?;

    // Receiving incoming messages
    let mut buffer = vec![];
    loop {
        let result = StreamReader::new(&mut stream, None).read_messages();
        if let Err(err) = result {
            stream.shutdown(Shutdown::Both)?;
            return Err(Error::DataError(err))
        }
        for msg in result.unwrap() {
            println!("Received message: {:?}", msg.payload);
        }
    }
}
```

Sample output is the following:
```
Received message: Version(VersionMessage { version: 70015, services: 1037, timestamp: 1548637162, receiver: Address {services: 0, address: [0, 0, 0, 0, 0, 65535, 23536, 35968], port: 33716}, sender: Address {services: 1037, address: [0, 0, 0, 0, 0, 0, 0, 0], port: 0}, nonce: 1370726880972892633, user_agent: "/Satoshi:0.17.99/", start_height: 560412, relay: true })
Received message: Verack
Received message: Alert([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 254, 255, 255, 127, 1, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 0, 255, 255, 255, 127, 0, 47, 85, 82, 71, 69, 78, 84, 58, 32, 65, 108, 101, 114, 116, 32, 107, 101, 121, 32, 99, 111, 109, 112, 114, 111, 109, 105, 115, 101, 100, 44, 32, 117, 112, 103, 114, 97, 100, 101, 32, 114, 101, 113, 117, 105, 114, 101, 100, 0])
```

Working sample code can be found here: https://github.com/dr-orlovsky/bitcoinbigdata-netlistener
2019-02-27 16:41:28 -05:00
Andrew Poelstra fc47c477ab key: add some missing functionality 2019-02-27 01:56:38 +00:00
Carl Dong 4bf99e79f8
Merge pull request #236 from dongcarl/2019-02-remove-unused-option-decoding
Remove unused Option en/decoding
2019-02-22 10:14:37 -05:00
Carl Dong 04c7f2071d
Merge pull request #235 from dongcarl/2019-02-remove-extraneous-params-clone
Remove extraneous clones in consensus::params
2019-02-21 17:41:08 -05:00
Carl Dong 4c742fbaa1
Merge pull request #237 from dongcarl/2019-02-forbid-unsafe
Forbid unsafe code
2019-02-21 17:37:59 -05:00
Carl Dong 1ad1c11649 Forbid unsafe code 2019-02-20 17:16:21 -05:00
Carl Dong 17c0f4e784 Remove unused Option en/decoding 2019-02-20 17:08:36 -05:00
Carl Dong 2f70c3bc34 Remove extraneous clones in consensus::params 2019-02-20 15:47:31 -05:00
Matt Corallo 084703cba9
Merge pull request #218 from tamasblummer/merkle_root_fix
Merkle root calculation and witness commitment check for Block
2019-02-16 19:05:42 -05:00
Carl Dong d5331e59ed
Merge pull request #233 from stevenroose/derivation-path
bip32: Add DerivationPath type
2019-02-15 09:52:59 -05:00
Steven Roose dce81b623e
bip32: Add additional methods and traits to DerivationPath
- From<&[ChildNumber]> (cloning)
- AsRef<[ChildNumber]>
- std::iter::FromIterator<ChildNumber>
- std::iter::IntoIterator<ChildNumber>
- std::ops::Index (returning &[ChildNumber])

Also add two methods:
- child(&self, ChildNumber) -> DerivationPath
- into_child(self, ChildNumber) -> DerivationPath
2019-02-14 11:16:06 +00:00
Steven Roose 1373969805 bip32: Change test vectors to use DerivationPath 2019-02-14 11:09:39 +00:00
Steven Roose b23de17d55 bip32: Introduce DerivationPath type
Implements Display and FromStr for easy usage with serialized types.
2019-02-14 11:09:34 +00:00
Steven Roose a80cea270a bip32: ChildNumber constructors return Result
They can produce an error if the index is out of range.
2019-02-14 11:08:13 +00:00
Sebastian Geisler cad0fe790f point to IRC 2019-02-12 14:28:57 -08:00
lucash-dev 114ebb0c73 Added contributing part to README 2019-02-12 14:28:57 -08:00
Carl Dong 560dfb7c01
Merge pull request #203 from stevenroose/asm
Extract the Script assembly creator from fmt::Debug
2019-02-11 17:24:03 -05:00
Carl Dong f87e173268
Merge pull request #227 from dongcarl/2019-01-improve-local-testing
Extract travis testing into locally-runnable script
2019-02-11 16:24:05 -05:00
Andrew Poelstra 8ae4aee0d8
Merge pull request #183 from dongcarl/2018-9-pubkey-wrapper
Ready for Review: Introduce util::key and deprecate util::privkey
2019-02-11 21:21:32 +00:00
Carl Dong a944c7fbd0 key: Use correct error for decoding
This change also moves the secp256k1::Error wrapper from util::Error to
consensus::encode::Error, since we do not use it anywhere else. We can
add it back to util::Error once we have instances of secp256k1::Error
that are not related to consensus::encode.
2019-02-11 15:15:03 -05:00
Carl Dong fc448ba47c key: Reword and clarify comments 2019-02-11 15:10:20 -05:00
Carl Dong b3cc3d50ef Integrate newly-added PublicKey with Address
- Switch util::address::Payload::Pubkey variant to wrap
  util:🔑:PublicKey
- Switch util::address::Address::p*k* constructors to use
  util:🔑:PublicKey
- Fix tests for aforementioned switch
- Add convenience methods for util:🔑:PublicKey to
  util:🔑:PrivateKey conversion
- Switch BIP143 tests to use util:🔑:PublicKey
2019-02-11 15:10:13 -05:00
Carl Dong 53a6efe33c Add PublicKey struct encapsulating compressedness
- Move util::privkey to util::key
- Add PublicKey struct to util::key
- Implement de/serialization methods for util:🔑:PublicKey
2019-02-11 14:56:55 -05:00
Carl Dong 60c93c387f Cleanup util::privkey in preparation for PublicKey
- Rename privkey::PrivKey to privkey::PrivateKey
- Remove unnecessary methods for privkey::PrivateKey
- Modify tests to work with above changes
2019-02-11 14:56:49 -05:00
Tamás Blummer 1cd2782122
add BIP157 (Client Side Block Filtering) Messages (#225)
* add BIP57 (Client Side Block Filtering) Messages

* rabased after https://github.com/rust-bitcoin/rust-bitcoin/pull/215
2019-02-08 13:00:51 +01:00
Carl Dong e386d9e2e9
Merge pull request #222 from stevenroose/no-p2pk-addr
Remove Address::p2pk
2019-02-07 16:18:31 -05:00
Steven Roose f80e882813
Remove Address::p2pk
There is no address format for p2pk.
2019-02-07 20:02:21 +00:00
Carl Dong 50fef2d851 Extract travis testing into locally-runnable script 2019-02-04 10:39:37 -05:00
ariard 51971dd533 Fix typos and clarify some comment in blockdata, block, address (#230) 2019-02-04 07:30:41 +01:00
Tamas Blummer d8c93d9935 Implement Witness commitment check for Block. Remove MerkleRoot implementations for types implementing BitcoinHash as
it is misleading. MerkleRoot is defined instead for a Block.
2019-02-01 17:46:26 +01:00
Carl Dong 51aba8bb21
Merge pull request #215 from dongcarl/2018-12-integrate-bitcoin-hashes
Integrate bitcoin_hashes, remove rust-crypto and fuzz_util
2019-01-24 19:58:34 -05:00
Carl Dong ca72a04dd4 Remove rust-crypto dependency
We no longer need rust-crypto after integrating bitcoin_hashes.
2019-01-24 16:27:52 -05:00
Carl Dong 1bbeda87eb Remove fuzz_util module
Not needed anymore as the bitcoin_hashes crate handles this.
2019-01-24 16:27:52 -05:00
Carl Dong 96f9c62b0e Remove unused internal macro 2019-01-24 16:27:52 -05:00
Carl Dong c830fb4629 Remove code deprecated by bitcoin_hashes from util::hash 2019-01-24 16:27:52 -05:00
Carl Dong 99f63a8ca4 Convert codebase from util::hash to bitcoin_hashes
Also replace unsafe transmute with call to read_u64_into
2019-01-24 16:27:52 -05:00
Carl Dong 45aa709467 Implement En/Decodable for sha256d::Hash 2019-01-24 11:31:07 -05:00
Carl Dong b88f00c698 Add bitcoin_hashes dependency, rename some features
Because features and dependencies share the same namespace, and we want
to pass down the optional dependence on serde to bitcoin_hashes, we need
to rename the feature to something other than serde. Right now only
features can be passed down to dependencies.

Note that we could have also renamed the dependency to something like
serde-dep and kept the same feature name, however, dependency renaming
has only been available since cargo 0.27.0

Features that represent optional dependencies have been prefixed with
'use-'. The travis file has also been modified to conform to this
change.
2019-01-24 11:31:07 -05:00
Carl Dong b6ec6a0d62
Merge pull request #212 from TheBlueMatt/2019-01-travis-nightly-bench
Run cargo bench on rustc nightly in travis
2019-01-23 19:25:44 -05:00
Dimitris Apostolou 132ca5ea95 Fix typos 2019-01-23 14:17:29 -05:00
Tamas Blummer 96be35b1d3 it is annoying to have a difference between debug and print for hash 2019-01-23 14:14:29 -05:00
Carl Dong 8584303768 Bump rustc version to 1.22.0 2019-01-22 19:58:18 -05:00
Andrew Poelstra 21bd59cb17
Merge pull request #214 from apoelstra/2019-01-0.16
bump version to 0.16
2019-01-15 21:01:10 +00:00
Andrew Poelstra b5d5ac5ffb bump version to 0.16 2019-01-15 19:07:53 +00:00
Matt Corallo 0d7e13b034 Run cargo bench on rustc nightly in travis, remote useless move 2019-01-15 14:06:24 -05:00
Matt Corallo 2ed4b1f246
Merge pull request #208 from sgeisler/hex_bytes
Use more performant hex_bytes function
2019-01-15 14:06:00 -05:00
Andrew Poelstra 282daaab69
Merge pull request #213 from dongcarl/2019-01-secp-0.12-bump
Bump secp to 0.12
2019-01-15 19:03:03 +00:00
Carl Dong ff5c4a1806 Bump secp to 0.12 2019-01-15 12:58:54 -05:00
Matt Corallo 81bfc4f027
Merge pull request #211 from dongcarl/2019-01-move-user-enum-macro
Internalize unnecessarily exported macros
2019-01-15 12:58:47 -05:00
Carl Dong b2e044f9db Internalize unnecessarily exported macros 2019-01-15 11:53:31 -05:00
Antoine Riard 96c66292c8 Fix comment on transaction version 2019-01-10 18:29:50 -08:00
Sebastian Geisler 4c29fc0e8d Add feature gated hex decode benchmark 2019-01-07 17:49:55 -08:00
Sebastian Geisler 7c7ec02ed2 Remove unused Pair iterator and util::iter module 2019-01-03 17:28:36 -08:00
Sebastian Geisler c6a41651ab Replace slow hex decoding function with optimized version
Fixes #207.
2019-01-03 17:28:32 -08:00
Steven Roose a10d5e15b3
Extract the Script assembly creator from fmt::Debug 2018-12-19 21:17:00 +01:00
Andrew Poelstra 5a5158e120
Merge pull request #198 from sgeisler/safe-opcodes
Safe opcodes 1.14.0
2018-12-14 16:32:29 +00:00
Sebastian Geisler a6d204cbda Fix indentation in opcodes.rs 2018-12-13 15:35:29 -08:00
Andrew Poelstra bb7ca63776
Merge pull request #196 from sgeisler/separate-fuzzing
Move fuzzing code out of utils
2018-12-09 16:33:21 +00:00
Andrew Poelstra 617406228a add some opcode tests 2018-12-09 16:30:23 +00:00
Tamas Blummer bc5f78c170 upgrade byteorder to 1.2 2018-12-08 14:53:23 -08:00
Sebastian Geisler 9fee72cf20 make opcode PR work with 1.14.0 2018-12-04 15:56:18 -08:00
Andrew Poelstra 8a14ddbc27
Merge pull request #191 from sgeisler/base58
Avoid heap usage when encoding to base58
2018-12-04 12:18:02 +00:00
Sebastian Geisler 79a88e1612 Move fuzzing code out of utils 2018-12-03 16:31:13 -08:00
Sebastian Geisler e88612d617 add test case and cleanup 2018-12-03 14:51:55 -08:00
Sebastian Geisler 4a27c1369a avoid heap use when encoding base58 2018-12-03 14:51:53 -08:00
Andrew Poelstra 944c840460
Merge pull request #179 from apoelstra/2018-10-fuzz-outpoint
add fuzzer for transaction::OutPoint
2018-12-03 18:18:13 +00:00
Kaz Wesley 6b67c8cdff squashme: work around lack of associated constants 2018-11-11 14:58:33 -08:00
Kaz Wesley 45234eb09a safe implementation of All -> Ordinary 2018-11-11 14:19:25 -08:00
Kaz Wesley 0bfef68851 newtype implementation of opcodes::All
Removes unsafety when converting u8 -> All
2018-11-11 14:11:06 -08:00
Andrew Poelstra 84df2f05d7
Merge pull request #190 from apoelstra/2018-11-0.15.1
update version to 0.15.1
2018-11-08 22:34:44 +00:00
Andrew Poelstra 05a00e31e1 update version to 0.15.1 2018-11-08 15:05:13 +00:00
Andrew Poelstra 88daac6b43
Merge pull request #189 from shesek/compressed-p2pk
Detect compressed p2pk in script.is_p2pk()
2018-11-08 14:00:30 +00:00
Nadav Ivgi 18fcab6715 Detect compressed p2pk in script.is_p2pk() 2018-11-08 02:37:27 +02:00
Andrew Poelstra 8b6a40f96a add fuzzer for transaction::OutPoint 2018-10-18 23:14:23 +00:00
749 changed files with 10945 additions and 3882 deletions

View File

@ -1,21 +1,46 @@
language: rust language: rust
rust: cache: cargo
- stable
- beta
- nightly
- 1.14.0
before_install: addons:
- sudo apt-get -qq update apt:
- sudo apt-get install -y binutils-dev libunwind8-dev update: true
packages:
- binutils-dev
- libunwind8-dev
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- libiberty-dev
matrix:
include:
- rust: stable
env: DO_FUZZ=true DO_COV=true AS_DEPENDENCY=true
- rust: beta
env: AS_DEPENDENCY=true
- rust: nightly
env: DO_BENCH=true AS_DEPENDENCY=true
- rust: 1.22.0
env: AS_DEPENDENCY=true
script: script:
- cargo build --verbose - ./contrib/test.sh
- cargo test --verbose
- cargo build --verbose --features=bitcoinconsensus after_success: |
- cargo test --verbose --features=bitcoinconsensus if [ "$DO_COV" = true ]; then
- cargo build --verbose --features=serde wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
- cargo test --verbose --features=serde tar xzf master.tar.gz &&
- cargo build --verbose --features=serde-decimal cd kcov-master &&
- cargo test --verbose --features=serde-decimal mkdir build &&
- if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi cd build &&
cmake .. &&
make &&
make install DESTDIR=../../kcov-build &&
cd ../.. &&
rm -rf kcov-master &&
for file in target/debug/bitcoin-*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"; fi

View File

@ -1,4 +1,118 @@
# 0.23.0 - 2020-01-07
- Update `secp256k1` dependency to `0.17.1`.
- Update `bitcoinconsensus` dependency to `0.19.0-1`.
- Update `bech32` dependency to `0.7.2`.
# 0.22.0 - 2020-01-07
- Add `ServiceFlags` type.
- Add `NetworkMessage::command`.
- Add `key::Error`.
- Add newtypes for specific hashes:
- `Txid`
- `Wtxid`
- `BlockHash`
- `SigHash`
- `PubkeyHash`
- `ScriptHash`
- `WPubkeyHash`
- `WScriptHash`
- `TxMerkleNode`
- `WitnessMerkleNode`
- `WitnessCommitment`
- `XpubIdentifier`
- `FilterHash`
- Refactor `CommandString`.
- Refactor `Reject` message.
- Rename `RejectReason` enum variants.
- Refactor `encode::Error`.
- Implement `Default` for `TxIn`.
- Implement `std::hash::Hash` for `Inventory`.
- Implement `Copy` for `InvType` enum.
- Use `psbt::Error` in `PartiallySignedTransaction::from_unsigned_tx`.
- Drop message decode max length to 4_000_000.
- Drop `hex` and `byteorder` dependencies.
# 0.21.0 - 2019-10-02
* Add [serde to `BlockHeader` and `Block`](https://github.com/rust-bitcoin/rust-bitcoin/pull/321)
* [Clean up `StreamReader` API](https://github.com/rust-bitcoin/rust-bitcoin/pull/318) (breaking change)
* Add [reject message](https://github.com/rust-bitcoin/rust-bitcoin/pull/323) to p2p messages
# 0.20.0 - 2019-08-23
* Update `secp256k1` 0.15 and `bitcoinconsensus` 0.17
# 0.19.0 - 2019-08-16
* Add `Amount` and `SignedAmount` types.
* Add BIP-158 support with `BlockFilter` and related types.
* Add `util::misc::signed_msg_hash()` for signing messages.
* Add `MerkleBlock` and `PartialMerkleTree` types.
* bip32: Support serde serializaton for types and add some utility methods:
* `ChildNumber::increment`
* `DerivationPath::children_from`
* `DerivationPath::normal_children`
* `DerivationPath::hardened_children`
* Add `blockdata::script::Builder::push_verify` to verify-ify an opcode.
* Add `sendheaders` network message.
* Add `OutPoint::new()` method and JSON-serialize as `<txid>:<vout>`.
* Refactor `Address` type:
* Now supports segwit addresses with version >0.
* Add `Address::from_script` constructor.
* Add `Address::address_type` inspector.
* Parsing now returns an `address::Error` instead of `encode::Error`.
* Removed `bitcoin_bech32` dependency for bech32 payloads.
* bip143: Rename `witness_script` to `script_code`
* Rename `BlockHeader::spv_validate` to `validate_pow`
* Rename `OP_NOP2` and `OP_NOP3` to `OP_CLTV` and `OP_CSV`
* psbt: Use `BTreeMap` instead of `HashMap` to ensure serialization roundtrips.
* Drop `Decimal` type.
* Drop `LoneHeaders` type.
* Replace `strason` dependency with (optional) `serde_json`.
* Export the `bitcoin_hashes` and `secp256k1` dependent crates.
* Updated `bitcoin_hashes` dependency to v0.7.
* Removed `rand` and `serde_test` dependencies.
* Internal improvements to consensus encoding logic.
# 0.18.0 - 2019-03-21
* Update `bitcoin-bech32` version to 0.9
* add `to_bytes` method for `util::key` types
* add serde impls for `util::key` types
* contracthash: minor cleanups, use `util::key` types instead of `secp256k1` types
# 0.17.1 - 2019-03-04
* Add some trait impls to `PublicKey` for miniscript interoperability
# 0.17.0 - 2019-02-28 - ``The PSBT Release''
* **Update minimum rustc version to 1.22**.
* [Replace `rust-crypto` with `bitcoin_hashes`; refactor hash types](https://github.com/rust-bitcoin/rust-bitcoin/pull/215)
* [Remove `Address::p2pk`](https://github.com/rust-bitcoin/rust-bitcoin/pull/222/)
* Remove misleading blanket `MerkleRoot` implementation; [it is now only defined for `Block`](https://github.com/rust-bitcoin/rust-bitcoin/pull/218)
* [Add BIP157](https://github.com/rust-bitcoin/rust-bitcoin/pull/215) (client-side block filtering messages)
* Allow network messages [to be deserialized even across multiple packets](https://github.com/rust-bitcoin/rust-bitcoin/pull/231)
* [Replace all key types](https://github.com/rust-bitcoin/rust-bitcoin/pull/183) to better match abstractions needed for PSBT
* [Clean up BIP32](https://github.com/rust-bitcoin/rust-bitcoin/pull/233) in preparation for PSBT; [use new native key types rather than `secp256k1` ones](https://github.com/rust-bitcoin/rust-bitcoin/pull/238/)
* Remove [apparently-used `Option` serialization](https://github.com/rust-bitcoin/rust-bitcoin/pull/236#event-2158116421) code
* Finally merge [PSBT](https://github.com/rust-bitcoin/rust-bitcoin/pull/103) after nearly nine months
# 0.16.0 - 2019-01-15
* Reorganize opcode types to eliminate unsafe code
* Un-expose some macros that were unintentionally exported
* Update rust-secp256k1 dependency to 0.12
* Remove `util::iter::Pair` type which does not belong in this library
* Minor bugfixes and optimizations
# 0.15.1 - 2018-11-08
* [Detect p2pk addresses with compressed keys](https://github.com/rust-bitcoin/rust-bitcoin/pull/189)
# 0.15.0 - 2018-11-03 # 0.15.0 - 2018-11-03
* [Significant API overhaul](https://github.com/rust-bitcoin/rust-bitcoin/pull/156): * [Significant API overhaul](https://github.com/rust-bitcoin/rust-bitcoin/pull/156):

View File

@ -1,7 +1,6 @@
[package] [package]
name = "bitcoin" name = "bitcoin"
version = "0.15.0" version = "0.23.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"] authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0" license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bitcoin/" homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"
@ -16,28 +15,24 @@ name = "bitcoin"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
fuzztarget = ["secp256k1/fuzztarget"] fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
serde-decimal = ["serde", "strason"] unstable = []
rand = ["secp256k1/rand-std"]
use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"]
[dependencies] [dependencies]
bitcoin-bech32 = "0.8.0" bech32 = "0.7.2"
byteorder = "1.1" bitcoin_hashes = "0.7.3"
rand = "0.3" secp256k1 = "0.17.1"
rust-crypto = "0.2"
bitcoinconsensus = { version = "0.16", optional = true }
[dependencies.serde] bitcoinconsensus = { version = "0.19.0-1", optional = true }
version = "1" serde = { version = "1", optional = true }
optional = true
[dependencies.strason] [dev-dependencies]
version = "0.4" hex = "=0.3.2"
optional = true serde_derive = "<1.0.99"
default-features = false serde_json = "<1.0.45"
serde_test = "1"
[dependencies.hex] secp256k1 = { version = "0.17.1", features = ["rand-std"] }
version = "=0.3.2" # We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0
ryu = "<1.0.5"
[dependencies.secp256k1]
version = "0.11"
features = [ "rand" ]

View File

@ -1,10 +1,10 @@
[![Status](https://travis-ci.org/rust-bitcoin/rust-bitcoin.png?branch=master)](https://travis-ci.org/rust-bitcoin/rust-bitcoin) [![Status](https://travis-ci.org/rust-bitcoin/rust-bitcoin.png?branch=master)](https://travis-ci.org/rust-bitcoin/rust-bitcoin)
[![Safety Dance](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
# Rust Bitcoin Library # Rust Bitcoin Library
Library with support for de/serialization, parsing and executing on data Library with support for de/serialization, parsing and executing on data
structures and network messages related to Bitcoin and other blockchain-based structures and network messages related to Bitcoin.
currencies.
[Documentation](https://docs.rs/bitcoin/) [Documentation](https://docs.rs/bitcoin/)
@ -14,12 +14,11 @@ Supports (or should support)
* De/serialization of blocks and transactions * De/serialization of blocks and transactions
* Script de/serialization * Script de/serialization
* Private keys and address creation, de/serialization and validation (including full BIP32 support) * Private keys and address creation, de/serialization and validation (including full BIP32 support)
* PSBT creation, manipulation, merging and finalization
* Pay-to-contract support as in Appendix A of the [Blockstream sidechains whitepaper](https://www.blockstream.com/sidechains.pdf) * Pay-to-contract support as in Appendix A of the [Blockstream sidechains whitepaper](https://www.blockstream.com/sidechains.pdf)
For JSONRPC interaction with Bitcoin Core, it is recommended to use [rust-jsonrpc](https://github.com/apoelstra/rust-jsonrpc) For JSONRPC interaction with Bitcoin Core, it is recommended to use
which uses the underlying [strason library](https://github.com/apoelstra/strason) [rust-bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc).
which parses decimal numbers as strings, preventing precision errors.
# Known limitations # Known limitations
@ -39,12 +38,54 @@ fix specific consensus incompatibilities are welcome.
## Documentation ## Documentation
Currently the [documentation](https://www.wpsoftware.net/rustdoc/bitcoin/) Currently can be found on [docs.rs/bitcoin](https://docs.rs/bitcoin/).
is very sparse. Patches to add usage examples and to expand on existing Patches to add usage examples and to expand on existing docs would be extremely
docs would be extremely appreciated. appreciated.
# Contributing
Contributions are generally welcome. If you intend to make larger changes please
discuss them in an issue before PRing them to avoid duplicate work and
architectural mismatches. If you have any questions or ideas you want to discuss
please join us in
[#rust-bitcoin](http://webchat.freenode.net/?channels=%23rust-bitcoin) on
freenode.
# Policy on Altcoins/Altchains ## Minimum Supported Rust Version (MSRV)
This library should always compile with any combination of features on **Rust 1.22**.
## Installing Rust
Rust can be installed using your package manager of choice or
[rustup.rs](https://rustup.rs). The former way is considered more secure since
it typically doesn't involve trust in the CA system. But you should be aware
that the version of Rust shipped by your distribution might be out of date.
Generally this isn't a problem for `rust-bitcoin` since we support much older
versions (>=1.22) than the current stable one.
## Building
The library can be built and tested using [`cargo`](https://github.com/rust-lang/cargo/):
```
git clone git@github.com:rust-bitcoin/rust-bitcoin.git
cd rust-bitcoin
cargo build
```
You can run tests with:
```
cargo test
```
Please refer to the [`cargo` documentation](https://doc.rust-lang.org/stable/cargo/) for more detailed instructions.
## Pull Requests
Every PR needs at least two reviews to get merged. During the review phase
maintainers and contributors are likely to leave comments and request changes.
Please try to address them, otherwise your PR might get closed without merging
after a longer time of inactivity. If your PR isn't ready for review yet please
mark it by prefixing the title with `WIP: `.
## Policy on Altcoins/Altchains
Patches which add support for non-Bitcoin cryptocurrencies by adding constants Patches which add support for non-Bitcoin cryptocurrencies by adding constants
to existing enums (e.g. to set the network message magic-byte sequence) are to existing enums (e.g. to set the network message magic-byte sequence) are
@ -58,7 +99,12 @@ cross-chain atomic swaps) are more likely to be accepted than things which
support only a single blockchain. support only a single blockchain.
## Release Notes # Release Notes
See CHANGELOG.md See [CHANGELOG.md](CHANGELOG.md).
# Licensing
The code in this project is licensed under the [Creative Commons CC0 1.0
Universal license](LICENSE).

49
contrib/test.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/sh -ex
FEATURES="bitcoinconsensus use-serde rand"
if [ "$DO_COV" = true ]
then
export RUSTFLAGS="-C link-dead-code"
fi
# Use toolchain if explicitly specified
if [ -n "$TOOLCHAIN" ]
then
alias cargo="cargo +$TOOLCHAIN"
fi
# Test without any features first
cargo test --verbose
# Test each feature
for feature in ${FEATURES}
do
cargo test --verbose --features="$feature"
done
# Fuzz if told to
if [ "$DO_FUZZ" = true ]
then
(
cd fuzz
cargo test --verbose
./travis-fuzz.sh
)
fi
# Bench if told to
if [ "$DO_BENCH" = true ]
then
cargo bench --features unstable
fi
# Use as dependency if told to
if [ -n "$AS_DEPENDENCY" ]
then
cargo new dep_test
cd dep_test
echo 'bitcoin = { path = "..", features = ["use-serde"] }' >> Cargo.toml
cargo test --verbose
fi

114
examples/handshake.rs Normal file
View File

@ -0,0 +1,114 @@
extern crate bitcoin;
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, process};
use std::io::Write;
use bitcoin::consensus::encode;
use bitcoin::network::{address, constants, message, message_network};
use bitcoin::network::stream_reader::StreamReader;
use bitcoin::secp256k1;
use bitcoin::secp256k1::rand::Rng;
fn main() {
// This example establishes a connection to a Bitcoin node, sends the intial
// "version" message, waits for the reply, and finally closes the connection.
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("not enough arguments");
process::exit(1);
}
let str_address = &args[1];
let address: SocketAddr = str_address.parse().unwrap_or_else(|error| {
eprintln!("Error parsing address: {:?}", error);
process::exit(1);
});
let version_message = build_version_message(address);
let first_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
payload: version_message,
};
if let Ok(mut stream) = TcpStream::connect(address) {
// Send the message
let _ = stream.write_all(encode::serialize(&first_message).as_slice());
println!("Sent version message");
// Setup StreamReader
let read_stream = stream.try_clone().unwrap();
let mut stream_reader = StreamReader::new(read_stream, None);
loop {
// Loop an retrieve new messages
let reply: message::RawNetworkMessage = stream_reader.read_next().unwrap();
match reply.payload {
message::NetworkMessage::Version(_) => {
println!("Received version message: {:?}", reply.payload);
let second_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
payload: message::NetworkMessage::Verack,
};
let _ = stream.write_all(encode::serialize(&second_message).as_slice());
println!("Sent verack message");
}
message::NetworkMessage::Verack => {
println!("Received verack message: {:?}", reply.payload);
break;
}
_ => {
println!("Received unknown message: {:?}", reply.payload);
break;
}
}
}
let _ = stream.shutdown(Shutdown::Both);
} else {
eprintln!("Failed to open connection");
}
}
fn build_version_message(address: SocketAddr) -> message::NetworkMessage {
// Building version message, see https://en.bitcoin.it/wiki/Protocol_documentation#version
let my_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
// "bitfield of features to be enabled for this connection"
let services = constants::ServiceFlags::NONE;
// "standard UNIX timestamp in seconds"
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time error")
.as_secs();
// "The network address of the node receiving this message"
let addr_recv = address::Address::new(&address, constants::ServiceFlags::NONE);
// "The network address of the node emitting this message"
let addr_from = address::Address::new(&my_address, constants::ServiceFlags::NONE);
// "Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self."
let nonce: u64 = secp256k1::rand::thread_rng().gen();
// "User Agent (0x00 if string is 0 bytes long)"
let user_agent = String::from("rust-example");
// "The last block received by the emitting node"
let start_height: i32 = 0;
// Construct the message
message::NetworkMessage::Version(message_network::VersionMessage::new(
services,
timestamp as i64,
addr_recv,
addr_from,
nonce,
user_agent,
start_height,
))
}

View File

@ -14,7 +14,7 @@ honggfuzz_fuzz = ["honggfuzz"]
[dependencies] [dependencies]
honggfuzz = { version = "0.5", optional = true } honggfuzz = { version = "0.5", optional = true }
afl = { version = "0.4", optional = true } afl = { version = "0.4", optional = true }
bitcoin = { path = "..", features = ["fuzztarget", "serde-decimal"] } bitcoin = { path = "..", features = ["fuzztarget"] }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]
@ -37,9 +37,21 @@ name = "deserialize_address"
path = "fuzz_targets/deserialize_address.rs" path = "fuzz_targets/deserialize_address.rs"
[[bin]] [[bin]]
name = "deserialize_decimal" name = "deserialize_amount"
path = "fuzz_targets/deserialize_decimal.rs" path = "fuzz_targets/deserialize_amount.rs"
[[bin]] [[bin]]
name = "deserialize_udecimal" name = "outpoint_string"
path = "fuzz_targets/deserialize_udecimal.rs" path = "fuzz_targets/outpoint_string.rs"
[[bin]]
name = "deserialize_psbt"
path = "fuzz_targets/deserialize_psbt.rs"
[[bin]]
name = "deser_net_msg"
path = "fuzz_targets/deser_net_msg.rs"
[[bin]]
name = "uint128_fuzz"
path = "fuzz_targets/uint128_fuzz.rs"

View File

@ -1,16 +1,7 @@
extern crate bitcoin; extern crate bitcoin;
use std::str::FromStr;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data); let _: Result<bitcoin::network::message::RawNetworkMessage, _> = bitcoin::consensus::encode::deserialize(data);
let dec = match bitcoin::util::decimal::Decimal::from_str(&data_str) {
Ok(dec) => dec,
Err(_) => return,
};
let dec_roundtrip = match bitcoin::util::decimal::Decimal::from_str(&dec.to_string()) {
Ok(dec) => dec,
Err(_) => return,
};
assert_eq!(dec, dec_roundtrip);
} }
#[cfg(feature = "afl")] #[cfg(feature = "afl")]
@ -55,7 +46,7 @@ mod tests {
#[test] #[test]
fn duplicate_crash() { fn duplicate_crash() {
let mut a = Vec::new(); let mut a = Vec::new();
extend_vec_from_hex("00000000", &mut a); extend_vec_from_hex("00", &mut a);
super::do_test(&a); super::do_test(&a);
} }
} }

View File

@ -2,15 +2,28 @@ extern crate bitcoin;
use std::str::FromStr; use std::str::FromStr;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data); let data_str = String::from_utf8_lossy(data);
let dec = match bitcoin::util::decimal::UDecimal::from_str(&data_str) {
Ok(dec) => dec, // signed
let samt = match bitcoin::util::amount::SignedAmount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return, Err(_) => return,
}; };
let dec_roundtrip = match bitcoin::util::decimal::UDecimal::from_str(&dec.to_string()) { let samt_roundtrip = match bitcoin::util::amount::SignedAmount::from_str(&samt.to_string()) {
Ok(dec) => dec, Ok(amt) => amt,
Err(_) => return, Err(_) => return,
}; };
assert_eq!(dec, dec_roundtrip); assert_eq!(samt, samt_roundtrip);
// unsigned
let amt = match bitcoin::util::amount::Amount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return,
};
let amt_roundtrip = match bitcoin::util::amount::Amount::from_str(&amt.to_string()) {
Ok(amt) => amt,
Err(_) => return,
};
assert_eq!(amt, amt_roundtrip);
} }
#[cfg(feature = "afl")] #[cfg(feature = "afl")]

View File

@ -0,0 +1,61 @@
extern crate bitcoin;
fn do_test(data: &[u8]) {
let psbt: Result<bitcoin::util::psbt::PartiallySignedTransaction, _> = bitcoin::consensus::encode::deserialize(data);
match psbt {
Err(_) => {},
Ok(psbt) => {
let ser = bitcoin::consensus::encode::serialize(&psbt);
let deser: bitcoin::util::psbt::PartiallySignedTransaction = bitcoin::consensus::encode::deserialize(&ser).unwrap();
// Since the fuzz data could order psbt fields differently, we compare to our deser/ser instead of data
assert_eq!(ser, bitcoin::consensus::encode::serialize(&deser));
}
}
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}
}

View File

@ -1,5 +1,7 @@
extern crate bitcoin; extern crate bitcoin;
use bitcoin::util::address::Address;
use bitcoin::network::constants::Network;
use bitcoin::blockdata::script; use bitcoin::blockdata::script;
use bitcoin::consensus::encode; use bitcoin::consensus::encode;
@ -32,6 +34,11 @@ fn do_test(data: &[u8]) {
} }
assert_eq!(b.into_script(), script); assert_eq!(b.into_script(), script);
assert_eq!(data, &encode::serialize(&script)[..]); assert_eq!(data, &encode::serialize(&script)[..]);
// Check if valid address and if that address roundtrips.
if let Some(addr) = Address::from_script(&script, Network::Bitcoin) {
assert_eq!(addr.script_pubkey(), script);
}
} }
} }

View File

@ -7,12 +7,12 @@ fn do_test(data: &[u8]) {
Ok(mut tx) => { Ok(mut tx) => {
let ser = bitcoin::consensus::encode::serialize(&tx); let ser = bitcoin::consensus::encode::serialize(&tx);
assert_eq!(&ser[..], data); assert_eq!(&ser[..], data);
let len = ser.len() as u64; let len = ser.len();
let calculated_weight = tx.get_weight(); let calculated_weight = tx.get_weight();
for input in &mut tx.input { for input in &mut tx.input {
input.witness = vec![]; input.witness = vec![];
} }
let no_witness_len = bitcoin::consensus::encode::serialize(&tx).len() as u64; let no_witness_len = bitcoin::consensus::encode::serialize(&tx).len();
// For 0-input transactions, `no_witness_len` will be incorrect because // For 0-input transactions, `no_witness_len` will be incorrect because
// we serialize as segwit even after "stripping the witnesses". We need // we serialize as segwit even after "stripping the witnesses". We need
// to drop two bytes (i.e. eight weight) // to drop two bytes (i.e. eight weight)

View File

@ -0,0 +1,88 @@
extern crate bitcoin;
use bitcoin::blockdata::transaction::OutPoint;
use bitcoin::consensus::encode;
use std::str::FromStr;
fn do_test(data: &[u8]) {
let lowercase: Vec<u8> = data.iter().map(|c| match *c {
b'A' => b'a',
b'B' => b'b',
b'C' => b'c',
b'D' => b'd',
b'E' => b'e',
b'F' => b'f',
x => x
}).collect();
let data_str = match String::from_utf8(lowercase) {
Err(_) => return,
Ok(s) => s,
};
match OutPoint::from_str(&data_str) {
Ok(op) => {
assert_eq!(op.to_string().as_bytes(), data_str.as_bytes());
}
Err(_) => {
// If we can't deserialize as a string, try consensus deserializing
let res: Result<OutPoint, _> = encode::deserialize(data);
if let Ok(deser) = res {
let ser = encode::serialize(&deser);
assert_eq!(ser, data);
let string = deser.to_string();
match OutPoint::from_str(&string) {
Ok(destring) => assert_eq!(destring, deser),
Err(_) => panic!()
}
}
}
}
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}
}

View File

@ -0,0 +1,101 @@
extern crate bitcoin;
use std::str::FromStr;
fn do_test(data: &[u8]) {
macro_rules! read_ints {
($start: expr) => { {
let mut native = 0;
for c in data[$start..$start + 16].iter() {
native <<= 8;
native |= (*c) as u128;
}
// Note BE:
let uint128 = bitcoin::util::uint::Uint128::from(&[native as u64, (native >> 8*8) as u64][..]);
(native, uint128)
} }
}
macro_rules! check_eq {
($native: expr, $uint: expr) => { {
assert_eq!(&[$native as u64, ($native >> 8*8) as u64], $uint.as_bytes());
} }
}
if data.len() != 16*2 + 1 { return; }
let (a_native, a) = read_ints!(0);
// Checks using only a:
for i in 0..128 {
check_eq!(a_native << i, a << i);
check_eq!(a_native >> i, a >> i);
}
assert_eq!(a_native as u64, a.low_u64());
assert_eq!(a_native as u32, a.low_u32());
assert_eq!(128 - a_native.leading_zeros() as usize, a.bits());
assert_eq!(a_native as u64, bitcoin::util::uint::Uint128::from_u64(a_native as u64).unwrap().low_u64());
// Checks with two numbers:
let (b_native, b) = read_ints!(16);
check_eq!(a_native.wrapping_add(b_native), a + b);
check_eq!(a_native.wrapping_sub(b_native), a - b);
if b_native != 0 {
check_eq!(a_native.wrapping_div(b_native), a / b);
}
check_eq!(a_native.wrapping_mul(b_native), a * b);
check_eq!(a_native & b_native, a & b);
check_eq!(a_native | b_native, a | b);
check_eq!(a_native ^ b_native, a ^ b);
check_eq!(a_native.wrapping_mul((b_native as u32) as u128), a.mul_u32(b.low_u32()));
assert_eq!(a_native > b_native, a > b);
assert_eq!(a_native >= b_native, a >= b);
assert_eq!(a_native < b_native, a < b);
assert_eq!(a_native <= b_native, a <= b);
}
#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
do_test(&data);
});
}
#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}
#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("100000a70000000000000000000000000000000000000000000000000000000054", &mut a);
super::do_test(&a);
}
}

Some files were not shown because too many files have changed in this diff Show More