Commit Graph

1916 Commits

Author SHA1 Message Date
Tobin C. Harding 07c75304d2 Refactor address byte swapping
When encoding a `network::Address` two of the fields are encoded
big-endian instead of little-endian as is done by `consensus_encode`. In
order to achieve this we have a helper function `addr_to_be` that swaps
the bytes. This function is miss-named because it is not converting to a
specific endian-ness (which implies different behaviour on machines with
different endian-ness) but is reversing the byte order irrespective of
the underlying architecture.

- Remove function `addr_to_be`
- Inline the endian-ness code when encoding an address
- Remove TODO and use `to_be_bytes` when encoding port
- Add a function for reading big-endian bytes `read_be_address`
- Use `read_be_address` when decoding `Address` and `Addrv2`

Refactor only, no logic changes. Code path is already covered by
unit tests.
2022-05-19 16:03:03 +10:00
Tobin Harding 8e29f2b493 Add ChainHash type
The Lightning network defines a type called 'chain hash' that is used to
uniquely represent the various Bitcoin networks as a 32 byte hash value.
Chain hash is now being used by the DLC folks, as such it is useful to
have it implemented in rust-bitcoin.

One method of calculating a chain hash is by hashing the genesis block
for the respective network.

Add a `ChainHash` type that can be used to get the unique identifier of
each of the 4 Bitcoin networks we support. Add a method that returns
the chain hash for a network using the double sha256 of the genesis
block. Do so using hard coded consts and add unit
tests (regression/sanity) that show these hard code byte arrays match
the hash of the data we return for the genesis block for the respective
network.

The chain hash for the main Bitcoin network can be verified from LN
docs (BOLT 0), add a link to this document.
2022-05-19 15:07:39 +10:00
Tobin Harding cd8f511fcb blockdata: constants: Use wildcard import in unit tests
Import with wildcard is applicable in unit tests, use it.
2022-05-19 14:20:06 +10:00
Tobin Harding 71bf19621a Use fully qualified path in macro
As we do for the rest of the macros use the fully qualified path to
`fmt` so users of the macro do not have to import it.
2022-05-19 14:14:32 +10:00
Tobin C. Harding 58f94bee9b Remove sha256t_hash_newtype macro
Since commit `commit 275adc6c335a4326699cfbd444949e1725864ea1` on
`bitcoin_hashes` we have the identical implementation of the macro
`sha256t1_hash_newtype` in this crate and in `bitcoin_hashes`.

Remove the `sha256t_hash_newtype` macro from this crate in favour of the
one in `bitcoin_hashes`.
2022-05-19 14:10:57 +10:00
Tobin C. Harding 90b4f1cde8 Clear TapTreeIter clippy warning
Clippy emits warning:

 public documentation for `script_leaves` links to private item `TapTreeIter`

I'm not exactly sure why this is but adding the generic type place
holder clears the warning.
2022-05-19 14:06:08 +10:00
Tobin Harding e6084a1af8 Improve documentation around EcdsaSig
Improve the rustdocs for serialization methods of the `EcdsaSig` type.
2022-05-19 14:05:34 +10:00
Tobin C. Harding 9896f27eae psbt: Improve documentation
Improve documentation in `psbt/mod.rs` by doing:

- Use full sentences (full stops and capitalisation)
- Use 100 line column width
- Use back ticks and links as appropriate
- Use `Errors` section
- Use third person tense to describe functions
2022-05-19 12:47:33 +10:00
Tobin Harding 33a50831ce sighash: Improve documentation
Improve the rustdoc documentation in the `sighash` module by doing:

- Improve grammar
- Use full sentences (full stops and capitalisation)
- Use 100 line column width
- Use back ticks and links as appropriate
- Improve correctness of `SigHashCache::new` function
2022-05-19 12:29:27 +10:00
Andrew Poelstra 50d9394582
Merge rust-bitcoin/rust-bitcoin#983: Edition 2018
9f0c687d89 Enable edition 2018 (Tobin C. Harding)
dca0d67771 Fix in preparation for next edition (Tobin C. Harding)

Pull request description:

  This PR supersedes #635 at the permission of @Kixunil in the thread of that PR.

  Do a minimal set of changes to enable edition 2018.  Patch 1 is  the biggest change set, it is done with `cargo`, no other manual changes are included in patch 1.  It can verified by running `cargo fix --edition` on master and checking the diffs are the same.

  Patch 2 enables 2018 and includes all the manual changes required to get the code to build (with _all_ the feature combinations :)

ACKs for top commit:
  dunxen:
    re-ACK  9f0c687
  apoelstra:
    re-ACK 9f0c687d89
  RCasatta:
    ACK 9f0c687d89,

Tree-SHA512: 7c23554adb4c1dd932af1e80f04397bad0418b4fdae2d0fe243c3f19ba1169686a386bffd38a3c02871c7544b5a7bc8af525b50617a2695726408c091700f081
2022-05-18 19:21:01 +00:00
Matt Corallo 491da3e701
Merge pull request #992 from tcharding/rm-dr
Remove dr-orlovsky from maintainer list
2022-05-12 21:33:50 +00:00
Tobin C. Harding 38c41e4612 Replace base64-compat dependency
Now that we have MSRV 1.41.1 we can use the more modern `base64` instead
of the compat crate. Requires no changes other than changing the
dependency.
2022-05-11 10:33:03 +10:00
Tobin C. Harding 9f0c687d89 Enable edition 2018
Add 'edition = "2018"' to the manifest and do a bunch of manual path
fixups (use statements and fully qualified paths).
2022-05-11 10:16:48 +10:00
Tobin C. Harding dca0d67771 Fix in preparation for next edition
Use cargo to upgrade from edition 2015 to edition 2018.

 cargo fix --edition

No manual changes made. The result of the command above is just to fix
all the use statements (add `crate::`) and fix the fully qualified path
formats i.e., `::Foo` -> `crate::Foo`.
2022-05-11 10:16:17 +10:00
Tobin C. Harding b5a76e0434 Remove dr-orlovsky from maintainer list
Dr Orlovsky is no longer maintaining rust-bitcoin projects. Remove his
name from the maintainer list.
2022-05-11 07:17:47 +10:00
Andrew Poelstra af1f259419
Merge rust-bitcoin/rust-bitcoin#989: Add method to push an ECDSA sig + sighash type byte on a witness
0ab5eeac81 Add method to push an ECDSA sig + sighash type byte on a witness (Matt Corallo)

Pull request description:

  We do this all over the place in rust-lightning, and its probably
  the most common thing to do with a `Witness` so I figured I'd
  upstream the util method to do this. It also avoids an allocation
  compared to the naive approach of `SerializedSignature.to_vec()`
  with two pushes, which is nice.

ACKs for top commit:
  apoelstra:
    ACK 0ab5eeac81
  tcharding:
    ACK 0ab5eeac81
  dunxen:
    ACK 0ab5eea

Tree-SHA512: d4042eb3f2bc7e6beecd2c17eaeef1fdb7d096b8889a3709924734739557031f338525b685d32ac0dc26404afefd4f2d48defd1753ea8935e54e3a82987feb8c
2022-05-10 18:16:33 +00:00
Matt Corallo 0ab5eeac81 Add method to push an ECDSA sig + sighash type byte on a witness
We do this all over the place in rust-lightning, and its probably
the most common thing to do with a `Witness` so I figured I'd
upstream the util method to do this. It also avoids an allocation
compared to the naive approach of `SerializedSignature.to_vec()`
with two pushes, which is nice.
2022-05-05 03:27:28 +00:00
sanket1729 23fe753f0f
Merge rust-bitcoin/rust-bitcoin#982: Remove irrelevant notes about version pinning
091688c078 Remove irrelevant notes about version pinning (Martin Habovštiak)

Pull request description:

  These are no longer relevant for MSRV 1.41.1+

ACKs for top commit:
  tcharding:
    ACK 091688c078
  sanket1729:
    ACK 091688c078

Tree-SHA512: d40ea1cd788ada3172dbedcfd2f9f1472222941b6e3753feee8e2f0c929abe3d12ac9a91488d332a180c9685d53b8c1daf96fe309a586d8f93e49066d5c1dfcc
2022-05-02 16:36:49 -07:00
Martin Habovštiak 091688c078
Remove irrelevant notes about version pinning
These are no longer relevant for MSRV 1.41.1+
2022-05-02 14:34:19 +02:00
Fredrik Meringdal 7ca30b6aa8 Move Address::payload_as_bytes to Payload::as_bytes 2022-05-02 12:32:08 +02:00
sanket1729 bcc923c03a
Merge rust-bitcoin/rust-bitcoin#716: Add `amount::Display` - make formatting configurable
4f1200d629 Added `amount::Display` - configurable formatting (Martin Habovstiak)

Pull request description:

  This significatnly refactors the formatting code to make formatting more
  configurable. The main addition is the `Display` type which is a
  builder that can configure denomination or other things (possibly more
  in the future).

  Further, this makes all representations of numbers minimal by default,
  so should be documented as a possibly-breaking change.

  Because of the effort to support all other `fmt::Formatter` options this
  required practically complete rewrite of `fmt_satoshi_in`. As a
  byproduct I took the opportunity of removing one allocation from there.

  Closes #709

ACKs for top commit:
  tcharding:
    ACK 4f1200d629
  dr-orlovsky:
    ACK 4f1200d629
  sanket1729:
    ACK 4f1200d629

Tree-SHA512: 3fafdf63fd720fd4514e026e9d323ac45dfcd3d3a53a4943178b1e84e4cf7603cb6235ecd3989d46c4ae29453c4b0bb2f2a5996fbddf341cd3f68dc286062144
2022-04-30 15:27:19 -07:00
sanket1729 d5a28fc48f
Merge rust-bitcoin/rust-bitcoin#673: Use iterator in `blockdata::script::Instructions`
2c28d3b448 Fix handling of empty slice in Instructions (Martin Habovštiak)
e6ff754b73 Fix doc of take_slice_or_kill (Martin Habovštiak)
0ec6d96a7b Cleanup after `Instructions` refactoring (Martin Habovstiak)
bc763259fe Move repeated code to functions in script (Martin Habovstiak)
1f55edf718 Use iterator in `blockdata::script::Instructions` (Martin Habovstiak)

Pull request description:

  This refactors `blockdata::script::Instructions` to use
  `::core::slice::Iter<'a, u8>` instead of `&'a [u8]` to better express
  the intention and to avoid some slicing mistakes. Similarly to a
  previous change this uses a macro to deduplicate the common logic and
  the new `read_uint_iter` internal function to automatically advance the
  iterator.

  Addresses:
  https://github.com/rust-bitcoin/rust-bitcoin/pull/662#pullrequestreview-768320603

ACKs for top commit:
  tcharding:
    ACK 2c28d3b448
  sanket1729:
    ACK 2c28d3b448. I don't want to hold ACKs on minor things as they can be in a fixup later.

Tree-SHA512: 9dc770b9f7958efbd0df2cc2d3546e23deca5df2f94ea2c42b089df628f4b99f08032ca4aa8822caf6643a8892903e1bda41228b78c8519b90bcaa1255d9acc6
2022-04-30 15:25:41 -07:00
Andrew Poelstra 9f817982a3
Merge rust-bitcoin/rust-bitcoin#905: Disable Serde's default-features
76fcf81474 Override default visit_byte_buf on Script (ass3rt)
add100c20d Removed reimplementations of default methods (ass3rt)
7db03f27e4 Disable Serde's default-features (ass3rt)

Pull request description:

  With this patch, existing users of the `use-serde` feature will no longer be
  compiling with `serde/std` enabled, but this allows dependent projects
  to import serde and enable `serde/alloc` as required by some no-std targets.

ACKs for top commit:
  Kixunil:
    ACK 76fcf81474
  tcharding:
    ACK 76fcf81474
  apoelstra:
    ACK 76fcf81474

Tree-SHA512: 5748e64e1f91f19dbfbf32bead6e6d759e448e92ed0dab731b3059f6b37bd811fad6654edc8fbd113e3be17fefaf9fc4912145d6b61484ced0517712361ecfdc
2022-04-30 15:52:03 +00:00
Andrew Poelstra ff6dc61967
Merge rust-bitcoin/rust-bitcoin#690: BUG: Does not work with `no_std` under 1.29 (MSRV)
7854bd7918 Fix `no_std` MSRV Fixes #690, #947 (mcroad)

Pull request description:

  `rust-bitcoin` does not work with rust 1.29 under a `no_std` environment. This could be considered a bug. However, `no_std` support is a recent addition and this is likely not breaking anyone's builds.

  A decision needs to be made, either `no_std` MSRV is the current stable version while keeping the `std` MSRV as 1.29, or it needs to be fixed.

  This pr adds `no_std` to the 1.29 test suite.

  This came as I try to get rust-bitcoin/rust-miniscript#277 working and got stuck on the issue of testing `no_std` under 1.29.

ACKs for top commit:
  Kixunil:
    ACK 7854bd7918
  tcharding:
    ACK 7854bd7918
  sanket1729:
    ACK 7854bd7918
  apoelstra:
    ACK 7854bd7918

Tree-SHA512: 1614fb2193f760ed340592bdb94d076066f6f783bc1dc2b145d97f7151a28316e56b1975f1ad948460eb26db04e7e9382e60076686a681e46dcf33521fda5fca
2022-04-30 15:50:54 +00:00
Andrew Poelstra 0dd2b433a0
Merge rust-bitcoin/rust-bitcoin#970: Fix badges
a0a83e18f6 README: Use correct license (Tobin C. Harding)
5c363bc785 README: Update badge to Rust 1.41.1 (Tobin C. Harding)

Pull request description:

  We have two small bugs in our README badges

  - Patch 1: sets the MSRV badge to the new 1.41.1
  - Patch 2: sets the license badge to the correct license, CC0

  (To verify that the changes render correctly, click on the 'from' branch name above.)

ACKs for top commit:
  sanket1729:
    ACK a0a83e18f6
  apoelstra:
    ACK a0a83e18f6

Tree-SHA512: e216cd36ac3ea477146c1a8ac842718dfe07762dd47378b7862a6ad5f92a08c25ed92133543fdc083d5edd80d08e7da46e1f87067c14d3240b3e411b2a05baf3
2022-04-30 13:10:47 +00:00
Fredrik Meringdal 525ea00e0f Make Address::get_payload_bytes public 2022-04-29 11:54:53 +02:00
sanket1729 e47d89c537
Merge rust-bitcoin/rust-bitcoin#952: Remove MSRV todo comments
831b0267de Use contains() instead of manual range (Tobin C. Harding)
6410095687 Use chunks_exact (Tobin C. Harding)
3a0097ba49 Use trim_start_matches (Tobin C. Harding)
0a19710906 Use vec! macro instead of new followed by push (Tobin C. Harding)

Pull request description:

  Now that 0.28 is out we do not need to support Rust 1.29 on `master`.

  Remove trivial MSRV `TODO`s from the code. (All these changes only rely on MSRV bumping to 1.31 so are easily within bounds.)

ACKs for top commit:
  Kixunil:
    ACK 831b0267de
  sanket1729:
    ACK 831b0267de

Tree-SHA512: f1ea594216ba7dfa24696b964ce296a8aea72dd2e16e11d3a43fe8b90c851abf59b1612b2b1311146e8070112f3834762584e4f0515b8f546f72af169eb4bda9
2022-04-27 15:52:16 -07:00
sanket1729 9eadbde730
Merge rust-bitcoin/rust-bitcoin#969: Update MSRV in clippy.toml
c5bb689b60 Update MSRV in clippy.toml (Martin Habovštiak)

Pull request description:

  We forgot about this during MSRV bump.

ACKs for top commit:
  tcharding:
    ACK c5bb689b60
  DanGould:
    ACK c5bb689b60
  sanket1729:
    ACK c5bb689b60

Tree-SHA512: 3acd2f3b28fdb7d450923dcec39af980cef95d997b54c9e48f09d78d41ba2b301a1a7637d629cadcaee87b3c9cb2e80c08f971bdf7de06d42fe50158278661f4
2022-04-27 15:45:37 -07:00
sanket1729 ee411a4cc2
Merge rust-bitcoin/rust-bitcoin#853: API to find funding utxos in psbt
5afb0eaf40 API to get an iterator for funding utxos in psbt (violet360)

Pull request description:

  ### Current status
  The API returns a vector of UTXOs and has return type `Result<Vec<&TxOut>, Error>`

  ### Expected
  The return statement should be of type `sighash::Prevouts` as pointed in #849

ACKs for top commit:
  Kixunil:
    ACK 5afb0eaf40
  tcharding:
    ACK 5afb0eaf40
  sanket1729:
    ACK 5afb0eaf40. Thanks for being patient with this.

Tree-SHA512: 724fc3dffdbb1331584f89bbe84527e1af0d193a344fe43b36f2f2a628652d259001a3abf6b3909df53524cd3fbdbe3af760b7004d40d3bee1848fbb83efff5b
2022-04-27 15:40:10 -07:00
Tobin C. Harding a0a83e18f6 README: Use correct license
Currently the readme badge is displaying Apache, we are not using the
Apache license, it should be CC0.

Use the correct CC0-1.0 Universal license.
2022-04-27 08:39:26 +10:00
Tobin C. Harding 5c363bc785 README: Update badge to Rust 1.41.1
Since we just bumped the MSRV, let's update the badge also.
2022-04-27 08:34:53 +10:00
Tobin C. Harding 831b0267de Use contains() instead of manual range
We no longer support Rust 1.29, we can use `contains` for ranges instead
of doing so manually.
2022-04-27 07:59:51 +10:00
Tobin C. Harding 6410095687 Use chunks_exact
Now that we are going to bump the MSRV above 1.31 we can use
`chunks_exact`.
2022-04-27 07:59:40 +10:00
Martin Habovštiak c5bb689b60
Update MSRV in clippy.toml
We forgot about this during MSRV bump.
2022-04-26 10:39:40 +02:00
Tobin C. Harding 3a0097ba49 Use trim_start_matches
Now that we are bumping the MSRV to greater than 1.30 we can use
`trim_start_matches`.

Use `trim_start_matches` and remove the clippy directive.
2022-04-26 11:34:30 +10:00
Tobin C. Harding 0a19710906 Use vec! macro instead of new followed by push
No need to manually create a vector and push each element, just use the
`vec![]` macro.
2022-04-26 11:32:34 +10:00
mcroad 7854bd7918
Fix `no_std` MSRV
Fixes #690, #947
2022-04-25 11:14:41 -05:00
ass3rt 76fcf81474 Override default visit_byte_buf on Script
This override may avoid allocation and thus make the deserialization
faster.

Credit to Kixunil for this fix: https://github.com/rust-bitcoin/rust-bitcoin/pull/905#issuecomment-1092756343
2022-04-25 09:53:52 -05:00
ass3rt add100c20d Removed reimplementations of default methods
The default methods do the exact same thing thus our overrides are
useless, potentially even problematic.

Credit to Kixunil for this fix: https://github.com/rust-bitcoin/rust-bitcoin/pull/905#issuecomment-1092756343
2022-04-25 09:53:52 -05:00
ass3rt 7db03f27e4 Disable Serde's default-features
We do not need serde/std, only serde/alloc. Serde/std breaks no-std
builds, but serde/alloc does not. Depending on serde/alloc is the more
compatible approach, as the entire library already depends on alloc.
2022-04-25 09:51:02 -05:00
violet360 5afb0eaf40 API to get an iterator for funding utxos in psbt 2022-04-25 18:18:11 +05:30
Andrew Poelstra 83514c87a7
Merge rust-bitcoin/rust-bitcoin#902: util::amount: Make from_sat constructor constant
31571cafbd util::amount: Make from_sat constructor constant (Steven Roose)

Pull request description:

  Currently unmergable because of MSRV but I heard talk about bumping it, so once it's bumped, this is a very much needed change :)

ACKs for top commit:
  tcharding:
    ACK 31571cafbd
  apoelstra:
    ACK 31571cafbd

Tree-SHA512: f254eb10a4349d890e29ea5fae77536429c7e731362cf2edcf2fe98ec9cbf2d8bbf65f98dfc8f0b80bac89960de688005d066a116d6cb62cca1efa9c1151f2ae
2022-04-22 23:43:52 +00:00
sanket1729 b169925c24
Merge rust-bitcoin/rust-bitcoin#966: Clean up import aliases
7307363c2e Use qualified path instead of alias (Tobin C. Harding)
80e0fb7673 Remove unnecessary 'as' statement (Tobin C. Harding)
21e1b9dbbd Use secp256k1 qualified path instead of underscore (Tobin C. Harding)

Pull request description:

  Three trivial clean ups of import aliases.

ACKs for top commit:
  apoelstra:
    ACK 7307363c2e
  sanket1729:
    ACK 7307363c2e. These are clean improvements
  Kixunil:
    ACK 7307363c2e

Tree-SHA512: f6ed3ede11d2803dbcb4584f11632fc47d28e525b5bf4de7794d400117f2d7c9ffce5bdff274877a63a519d5799bba2224fc39105d623da4bccad863005e171f
2022-04-22 12:32:18 -07:00
Andrew Poelstra d6f5d9885b
Merge rust-bitcoin/rust-bitcoin#964: Remove 1.29 checks from CI pipeline
8f45723bc6 test.sh: Remove 1.29 pinning (Tobin C. Harding)
15bae28b6b Remove CI check for Rust 1.29 (Tobin C. Harding)

Pull request description:

  We no longer need to test against Rust 1.29 now that v0.28 is out. In order to allow minor changes to be merged (i.e., not the _big_ MSRV patchset) that rely on MSRV being 1.41.1 update the CI pipeline.

  Remove the pinning stuff from `contrib/test.sh` while we are at it.

ACKs for top commit:
  sanket1729:
    ACK 8f45723bc6.
  Kixunil:
    ACK 8f45723bc6

Tree-SHA512: acad2aa75077fd6959b85758aaa2265ae1f9c72a92edb528072cac68e83b903fcd2d15c9410ba35570132d927cf3d0bbc2deb537ba2298958476b0b8e5f2e149
2022-04-22 17:01:16 +00:00
sanket1729 53a781ae3c
Merge rust-bitcoin/rust-bitcoin#965: Remove unnecessary `Write as _fmtWrite`
033a12def7 Remove unused Write as _fmtWrite (Tobin C. Harding)

Pull request description:

  We can bring the `Write` trait into scope, no need to underscore it.

  Done as part of the MSRV checklist.

ACKs for top commit:
  Kixunil:
    ACK 033a12def7
  elichai:
    ACK 033a12def7
  apoelstra:
    ACK 033a12def7
  sanket1729:
    utACK 033a12def7

Tree-SHA512: ce1c7ec2376d4838066a6d87f2cc9fe4c911090a58c397d2f4080c4d40c913cff4999e2620054a32b72aa197254ffed74633ddb75ece175813d867c3d53892d2
2022-04-21 17:11:51 -07:00
Tobin C. Harding 8f45723bc6 test.sh: Remove 1.29 pinning
We no longer need to test Rust 1.29, remove the pinning from the test
script.
2022-04-22 07:41:46 +10:00
Tobin C. Harding 15bae28b6b Remove CI check for Rust 1.29
In preparation for starting to merge patches that rely on an MSRV of
1.41 update the CI pipeline.
2022-04-22 07:41:39 +10:00
Martin Habovštiak 2c28d3b448
Fix handling of empty slice in Instructions
The code would've taken one element when an empty slice was requested.

Co-authored-by: Tobin C. Harding <me@tobin.cc>
2022-04-21 19:14:30 +02:00
Tobin C. Harding 7307363c2e Use qualified path instead of alias
It is more typical in this repo to use `module::Error` instead of a type
alias when importing.

Use `hex::Error` directly instead of `use hex::Error as HexError`.
2022-04-21 12:50:22 +10:00
Tobin C. Harding 80e0fb7673 Remove unnecessary 'as' statement
We can just use `self`, no idea why the `self as io` is there.
2022-04-21 12:50:22 +10:00