Commit Graph

835 Commits

Author SHA1 Message Date
Dr Maxim Orlovsky 8363c76f5c Script hash functions (normal and witness) 2020-09-11 15:10:57 +02:00
Dr Maxim Orlovsky 1d9f531581 Pubkey hash functions (normal and witness) 2020-09-11 15:04:26 +02:00
Andrew Poelstra c94295c3a9
Revert "Added hash Preimages to psbt" 2020-09-11 11:31:10 +00:00
Andrew Poelstra 3f33bd74e4
Merge pull request #465 from sanket1729/psbt_updates
Added hash Preimages to psbt
2020-09-11 11:30:27 +00:00
Andrew Poelstra 49e97cca65
Merge pull request #387 from pandoracore/builder-p2wildcard
Refactoring script generating functions into a single place
2020-09-11 11:29:09 +00:00
sanket1729 c1eafff9ef Added Sighash calculation for psbt 2020-09-11 01:01:33 -05:00
Andrew Poelstra bcf2c5981d
Merge pull request #475 from apoelstra/2020-09--0.24.0
Increase version to 0.24
2020-09-10 19:58:03 +00:00
Andrew Poelstra 440005b16e
Merge pull request #464 from TheBlueMatt/2020-08-pow-clarification
Set Params::pow_limit to an attainable value not a theoretical one
2020-09-10 16:46:40 +00:00
Andrew Poelstra 05f3451b10 un-deperate contracthash during testing
Avoids a rust test runner bug, see https://github.com/rust-lang/rust/issues/47238
2020-09-10 16:40:31 +00:00
Matt Corallo cf45a61070 Set Params::pow_limit to an attainable value not a theoretical one
`cloudhead` on IRC was asking how to properly use
`BlockHeader::validate_pow()` on genesis (or similar) when the
pow_limit field isn't expressible as a compact target (and, thus,
does not actually represent the PoW limit/genesis target). We
swap it for the actual PoW limit by truncating the way a compact
encoding round-trip would.

Note that, in Bitcoin Core, the original value is only ever used
once in its original form:
```
    if (bnNew > bnPowLimit) // Note: bnPowLimit is params.powLimit
        bnNew = bnPowLimit;

    return bnNew.GetCompact();
```
Thus, even if Core adopted our change, as long as there exist no
256-bit integer x which satisfies
`x <= powLimit && x > encoding_roundtrip_truncated(powLimit)` and
`enoding_roundtrip_truncated(x) != powLimit`, the change would have
no impact on consensus.

It is trivial to show that there are no values which are between
the new value
(0x00000000ffff0000000000000000000000000000000000000000000000000000)
and the original value
(0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
which can be encoded in compact form, but it is also critically, no
such values will encode to a compact form of anything different than
the new value as the encoding always truncates the low bits, never
rounding up.
2020-09-10 12:03:51 -04:00
Andrew Poelstra 4e737f708a
Merge pull request #461 from TheBlueMatt/2020-08-mut-sighash
Expose the witnesses of the tx being hashed in SigHashCache
2020-09-10 13:04:51 +00:00
Dr Maxim Orlovsky 38a412c4d5 Fixing review comments for script generators refactoring 2020-09-10 14:44:44 +02:00
Dr Maxim Orlovsky e33cdcca14 OP_RETURN script initializer 2020-09-10 12:09:04 +02:00
Dr Maxim Orlovsky 9143fd3888 All script generation functionality moved to standalone methods in Script 2020-09-10 12:09:04 +02:00
Sebastian Geisler 202a946fc3 Allow easy concatenation of bip32 derivation paths
Currently one has to convert the path into a Vec<ChildNumber>, extend it and finally convert it back again.
2020-09-09 21:42:27 +02:00
sanket1729 e97dda0ffe Add tests for psbt serde 2020-09-09 12:53:09 -05:00
Andrew Poelstra addb54ffc7
Merge pull request #458 from braydonf/version
Transaction and header version is signed int
2020-09-09 17:06:31 +00:00
Andrew Poelstra 5fd91ca2d8
Merge pull request #451 from stevenroose/deprecate-contracthash
Deprecate the util::contracthash module
2020-09-09 17:02:19 +00:00
Andrew Poelstra c8633b5bce
Merge pull request #436 from LNP-BP/feat-u256u8
Big integers (Uint*) from byte slice array with `from_be_bytes`
2020-09-09 16:42:32 +00:00
Andrew Poelstra 45da3add10
Merge pull request #428 from stevenroose/no-witness-uncompressed
Don't allow uncompressed pks in witness addresses
2020-09-09 16:37:06 +00:00
Elichai Turkel a44ba2d878
Merge pull request #397 from stevenroose/script-iter
Improve the Instructions iterator for scripts
2020-09-09 19:06:05 +03:00
Dr. Maxim Orlovsky 42bf893d8b
Update big int from_be_bytes with iterators
Co-authored-by: Sebastian <geisler.sebastian@googlemail.com>
2020-09-03 16:42:00 +02:00
sanket1729 c5204c001f Added Hash Preimages to psbt
Added hash preimages to psbt as per updated bip174
2020-08-31 17:22:40 -05:00
Alexis Sellier 5017b33326
Add `Clone` instance to `RawNetworkMessage` 2020-08-31 19:21:29 +02:00
Matt Corallo 3d80a0c962 Expose the witnesses of the tx being hashed in SigHashCache
See docuemntation of the new method for more, but this allows
certain use patterns which were broken with the introduction of
SigHashCache.
2020-08-26 11:18:14 -04:00
Braydon Fuller 945db009b2
Add test for transaction and block version serialization 2020-08-19 14:12:03 -07:00
Braydon Fuller e9f1f11c2c
Transaction and header version is signed int 2020-08-17 10:28:51 -07:00
Dr Maxim Orlovsky 2fd353d5ab Big integers (Uint*) from byte slice array with `from_be_bytes` 2020-08-09 18:00:00 +02:00
Elichai Turkel e8bcde4d38
Merge pull request #403 from LNP-BP/fix-macro-ns
Hygiene/single code style for all existing macros
2020-08-09 18:16:36 +03:00
Steven Roose c03d2d59c6
Merge pull request #445 from elichai/2020-07-divmod
Use the remainder from div_rem instead of recomputing it
2020-08-09 16:59:39 +02:00
Roman Zeyde 0a25d87f2e Remove empty code block 2020-08-07 14:48:46 +02:00
Steven Roose 1ffdce99ed
Deprecate the util::contracthash module 2020-08-06 12:24:08 +02:00
Jake Rawsthorne e47fcae435 feefilter message 2020-07-30 17:25:21 +01:00
Elichai Turkel 478e091af6
Merge pull request #443 from sgeisler/2020-06-bip32-derive-more
Derive more traits to use for bip32 Types
2020-07-23 11:24:50 +03:00
Elichai Turkel c20d356d7e
Use the remainder from div_rem instead of recomputing it 2020-07-22 12:39:32 +03:00
Dr Maxim Orlovsky 257ca8e504 Using :: for std namespaces in macro 2020-07-21 22:28:05 +02:00
Dr Maxim Orlovsky f6aa8853a0 Namespace hygiene for macros.rs 2020-07-21 22:28:05 +02:00
Dr Maxim Orlovsky 3a5e8d8504 Namespace hygiene for internal macros 2020-07-21 22:25:59 +02:00
Dr Maxim Orlovsky 7588b211ff Adding Rem op (%) to Uint128 & Uint256 types 2020-07-21 14:37:21 +02:00
Sebastian Geisler a3bb03eeb9 Derive more traits to use DerivationPath in rust-miniscript 2020-07-20 16:52:18 +02:00
Alexis Sellier 9cb5d2e711 Link type in rustdoc 2020-07-09 21:17:02 +02:00
Alexis Sellier e8cecfe1d3 Add `BlockHeader::u256_from_compact_target` function
This implements the counterparty to BlockHeader::compact_target_from_u256,
to convert a compact u32 to a Uint256.
2020-07-09 21:17:02 +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
Steven Roose ed9bf41ff5
Don't allow uncompressed pks in witness addresses 2020-05-23 23:20:46 +01:00
Steven Roose 59b5a73a55
Fix typo and minor formatting in address::Error 2020-05-23 23:20:19 +01:00
Andrew Poelstra 7efde3ae47
Merge pull request #419 from elichai/2020-03-description
Deprecate Error::description
2020-05-23 17:26:38 +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
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
Steven Roose fea09a0a94
Improve the Instructions iterator for scripts
- Rename the `iter` method to `instructions`.
- Add `instructions_minimal` for minimal-enforced iteration.
- Iterator has `Result<Instruction, Error>` as items.
2020-04-11 23:52:26 +01: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
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
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
Steven Roose 6186ee6269
Change Amount Debug impl to BTC with 8 decimals 2020-03-07 19:52:16 +00:00
Steven Roose 826b2e0e2a
Export the util::amount::Denomination type 2020-02-28 11:51:44 +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 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
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 8e52b8ce4d
Remove the BitcoinHash trait
Replaced by a `block_hash` method on both `Block` and `BlockHeader`.
2020-01-10 11:34:16 +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
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
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
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
Steven Roose a8f14af24d
Prevent panic on oversized CommandString's 2019-12-10 20:20:04 +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
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
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
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 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
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
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
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
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 9f3e355c5c upgrade to secp256k1 0.15 and bitcoinconsensus 0.17 2019-08-21 19:04:40 +02:00
Elichai Turkel 52ff97cddc
Deny unused imports and remove unneeded 2019-08-19 13:29:43 -04:00
Elichai Turkel 747e9ce75c
Pinned serde version and re-export bech32 2019-08-16 16:08:14 -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
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
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
Aleru 40c5a568fa add TODOs 2019-08-04 22:27:59 -04:00
practicalswift 8152ed758c Fix typos 2019-08-04 19:27:36 +00:00
Steven Roose cc2ede7a80
Use `$crate::` prefix for uses in macros 2019-07-29 11:30:35 +02: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
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
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 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 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
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
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 98796576d2 Fix trivial DoS when deserializing messages from the network 2019-06-05 07:49:19 -04: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 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
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
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
Nadav Ivgi 473b491409
Implement util::misc::signed_msg_hash() 2019-04-28 09:01:42 +03: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 9daf7fa9dc util::key add serde de/serialization 2019-03-21 18:27:42 +00: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
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
Carl Dong e5b59120c5 Add copyright notice to PSBT-related files 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 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
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 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