Commit Graph

817 Commits

Author SHA1 Message Date
Tobin C. Harding fcd0f4deac Use struct field init shorthand
Clippy emits:

  warning: redundant field names in struct initialization

As suggested use struct field init shorthand.
2022-05-25 13:15:20 +10:00
Tobin C. Harding 641960f037 Use rustfmt::skip
Clippy emits:

  warning: `cfg_attr` is deprecated for rustfmt and got replaced by tool
  attributes

As suggested use `rustfmt::skip`.
2022-05-25 13:13:13 +10:00
Tobin C. Harding 3cd00e5d47 Remove unnecessary whitespace 2022-05-25 13:12:31 +10:00
Andrew Poelstra 0e82376bf8
Merge rust-bitcoin/rust-bitcoin#987: Implement `std::error::Error` for the new MSRV
97a5bb1439 Implement std::error::source codebase wide (Tobin C. Harding)
0a9191b429 Add parenthesis around left hand side of companion (Tobin C. Harding)
7cf8af2f86 Put Error impl block below Display (Tobin C. Harding)
2384712364 Re-order Display match arms (Tobin C. Harding)

Pull request description:

  Now that we have MSRV of 1.41.1 we should use `source` instead of `cause`. Audit the whole codebase and implement `source` for _every_ error type we have.

  The first three patches are preparatory cleanup, patch 3 is particularly shameful (adds parenthesis to make my editor work).

  CC @Kixunil because he is championing the error stuff.

ACKs for top commit:
  apoelstra:
    ACK 97a5bb1439

Tree-SHA512: 46313a28929445f32e01e30ca3b0246b30bc9d5e43db5754d4b441e9c30d3e427efaf247100eb6b452f98beec5a4fcde1daba7943a772114aa34f78ab52cbc60
2022-05-21 14:08:52 +00:00
sanket1729 2b1154cefe
Merge rust-bitcoin/rust-bitcoin#996: Box value encoded in a variant to reduce enum stack space
9906cea14c Box value encoded in a variant to reduce enum stack space (Riccardo Casatta)

Pull request description:

  before

  ```
  print-type-size type: `util::psbt::error::Error`: 120 bytes, alignment: 8 bytes
  print-type-size     discriminant: 1 bytes
  print-type-size     variant `CombineInconsistentKeySources`: 115 bytes
  print-type-size         padding: 3 bytes
  print-type-size         field `.0`: 112 bytes, alignment: 4 bytes
  print-type-size     variant `InvalidKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  ```

  after
  ```
  print-type-size type: `util::psbt::error::Error`: 40 bytes, alignment: 8 bytes
  print-type-size     discriminant: 1 bytes
  print-type-size     variant `InvalidKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  print-type-size     variant `DuplicateKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  ```

  `util::psbt::error::Error` is wrapped also in `consensus::encode::Error` and stack savings are gained there also

ACKs for top commit:
  apoelstra:
    ACK 9906cea14c
  tcharding:
    ACK 9906cea14c
  sanket1729:
    utACK 9906cea14c

Tree-SHA512: e03988fcbc3dd87f83d00dd84ec1c538bc5c63bea97ff4a69a715621f498f57d7fe2a623e351942d9532af40c723e42a9eb6ef48ebf4c62ddf5c0f44e9ea0a07
2022-05-19 19:04:58 -07:00
sanket1729 fcb035fb4f
Merge rust-bitcoin/rust-bitcoin#956: Improve docs in `sighash` and `psbt/mod.rs`
9896f27eae psbt: Improve documentation (Tobin C. Harding)
33a50831ce sighash: Improve documentation (Tobin Harding)

Pull request description:

  Done while working on sighash and PSBT signing. Just the usual docs fixes. Note, does not do the whole `psbt` module just the file mentioned.

ACKs for top commit:
  apoelstra:
    ACK 9896f27eae

Tree-SHA512: 5fbfa258cdb216189922a49a42b7ab9fb78faeee72d82f8cb99a1b3d930d170074013e317b0e7af259a404ac4db93841b4d2b525e933c5e145da71e7522800fd
2022-05-19 18:59:37 -07:00
sanket1729 fa8091866d
Merge rust-bitcoin/rust-bitcoin#980: Remove sha256t_hash_newtype macro
58f94bee9b Remove sha256t_hash_newtype macro (Tobin C. Harding)

Pull request description:

  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`.

ACKs for top commit:
  apoelstra:
    ACK 58f94bee9b
  sanket1729:
    ACK 58f94bee9b

Tree-SHA512: ec08fd25c1cca71a07ea61cb5838ce8962daae7cbb84d8beccc3d0d285439909721edd643292a8f3f6989e1c2c41fda9addfd5cdb063ef53ebc6ef646da79cf3
2022-05-19 18:53:32 -07:00
sanket1729 d73a94a5d9
Merge rust-bitcoin/rust-bitcoin#960: Trival docs fixes
90b4f1cde8 Clear TapTreeIter clippy warning (Tobin C. Harding)
e6084a1af8 Improve documentation around EcdsaSig (Tobin Harding)

Pull request description:

  Do a couple of trivial docs fixes, done during other work.

  - Patch 1 improves docs on the `EcdsaSig` struct
  - Patch 2 clears a clippy warning during docs build - no sure if the solution is the best available though

ACKs for top commit:
  apoelstra:
    re-ACK 90b4f1cde8
  sanket1729:
    ACK 90b4f1cde8

Tree-SHA512: 0647dc2e6550938ccca658a9dddffba7175d5c4eb8cec0e165d3a7fa8f2b1dfb902e795aca77d96a6c31092baf64244fa1d7151a304134d3b1895619a2823338
2022-05-19 18:50:48 -07:00
sanket1729 48466bdf93
Merge rust-bitcoin/rust-bitcoin#978: Make Address::get_payload_bytes public
7ca30b6aa8 Move Address::payload_as_bytes to Payload::as_bytes (Fredrik Meringdal)
525ea00e0f Make Address::get_payload_bytes public (Fredrik Meringdal)

Pull request description:

  Hi, thanks for the amazing work on this crate.

  I am trying to upgrade from v0.27 to v0.28, but unable to do so because the `Address::get_payload_bytes` was made private. My use-case is that I have a script hash address and an `Address` and need to compare the two, and in order to do so I need access to the payload bytes of `Address`.
  I hope you will consider making this function public again 🙏

ACKs for top commit:
  apoelstra:
    ACK 7ca30b6
  tcharding:
    ACK 7ca30b6aa8
  sanket1729:
    ACK 7ca30b6aa8. Sorry for the delay and congratz on your first time contribution

Tree-SHA512: 02af4565853d93506751ed7cb004f52cb5d8c7936067e06b3e237b448ccdf5716470448eeccbe211958e095b66bb37c7027800c0470c6988dc18d8bd5b48f459
2022-05-19 18:39:14 -07:00
Riccardo Casatta 9906cea14c
Box value encoded in a variant to reduce enum stack space
before

```
print-type-size type: `util::psbt::error::Error`: 120 bytes, alignment: 8 bytes
print-type-size     discriminant: 1 bytes
print-type-size     variant `CombineInconsistentKeySources`: 115 bytes
print-type-size         padding: 3 bytes
print-type-size         field `.0`: 112 bytes, alignment: 4 bytes
print-type-size     variant `InvalidKey`: 39 bytes
print-type-size         padding: 7 bytes
print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
```

after
```
print-type-size type: `util::psbt::error::Error`: 40 bytes, alignment: 8 bytes
print-type-size     discriminant: 1 bytes
print-type-size     variant `InvalidKey`: 39 bytes
print-type-size         padding: 7 bytes
print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
print-type-size     variant `DuplicateKey`: 39 bytes
print-type-size         padding: 7 bytes
print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
```
2022-05-19 17:05:42 +02:00
Tobin C. Harding 97a5bb1439 Implement std::error::source codebase wide
Audit ever error type we have and implement `source` for each.
2022-05-19 16:35:11 +10:00
Tobin C. Harding 0a9191b429 Add parenthesis around left hand side of companion
Parenthesis are not needed around this expression but my editor is going
mad and cannot format the code without them. Since it does not hurt
readability add parenthesis around the expression.
2022-05-19 16:33:49 +10:00
Tobin C. Harding 7cf8af2f86 Put Error impl block below Display
In an effort to be uniform throughout the codebase; put the
`std::error::Error` impl block below the `Display` impl block.
2022-05-19 16:33:49 +10:00
Tobin C. Harding 2384712364 Re-order Display match arms
Put the match arms in the same order as the enum that defines them.
2022-05-19 16:33:49 +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
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
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
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
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 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 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
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
mcroad 7854bd7918
Fix `no_std` MSRV
Fixes #690, #947
2022-04-25 11:14:41 -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
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
Tobin C. Harding 21e1b9dbbd Use secp256k1 qualified path instead of underscore
We can use the qualified path for create type aliases, this is arguably
easier to read and reduces the number of LOC.
2022-04-21 12:50:22 +10:00
Tobin C. Harding 033a12def7 Remove unused Write as _fmtWrite
We can bring the `Write` trait into scope, no need to underscore it.
2022-04-21 12:37:56 +10:00
sanket1729 94f8c4b530
Merge rust-bitcoin/rust-bitcoin#951: Add PSBT alias
f92854a805 Add PSBT alias (Tobin Harding)

Pull request description:

  Programmers are inherently lazy and for good reason. I'm yet to see
  anyone write `PartiallySignedTransaction` in code that uses
  `rust-bitcoin`, its too obvious to add a type alias for PSBTs, let's
  just do it ourselves to save everyone else having to do so.

  Add public type alias `Psbt` for `PartiallySignedTransaction`.

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

Tree-SHA512: 1f56ac236d34a89bbb557ada147f05d8a8ce961dad3ad921f10f26c597b91ecc8e15070f8825774745e5333ba5282962830a3cc0c53b93f147be93ab566b1b9e
2022-04-20 14:32:34 -07:00
Andrew Poelstra 1e58208039
Merge rust-bitcoin/rust-bitcoin#950: Fix TapTree derserialization
c97589f8de Fix TapTree derserialization (sanket1729)

Pull request description:

  Trees should only be serialized if both of the following conditions
  hold:
  1) Tree is complete binary tree(is_finalized)
  2) Tree does not have any hidden nodes

ACKs for top commit:
  tcharding:
    ACK c97589f8de
  apoelstra:
    ACK c97589f8de

Tree-SHA512: 33d16f2d532cb24acba4ab847d493e550f7b279567678f3f2cd7e4161dea8b720a0e35be32b6c506e467c3526a29042aad8f4b5f45133b9a32028d4ee6a48f8e
2022-04-20 20:47:30 +00:00
Andrew Poelstra 6b57a02b1f
Merge rust-bitcoin/rust-bitcoin#927: Trivial improvements for TapTree type
4cdff06b1e Add convenience method TapTree:to_builder (Dr Maxim Orlovsky)
a12e7c73b6 Implement From<TapTree> for TaprootBuilder (Dr Maxim Orlovsky)
410412ff01 Rename TapTree::from_builder (Dr Maxim Orlovsky)
219273788c Rename TapTree::into_builder (Dr Maxim Orlovsky)
f9d8d0d968 Make TapTree::node_info public (Dr Maxim Orlovsky)

Pull request description:

  These are trivial fixes from extracted from now closed #922

ACKs for top commit:
  Kixunil:
    ACK 4cdff06b1e
  sanket1729:
    ACK 4cdff06b1e
  apoelstra:
    ACK 4cdff06b1e

Tree-SHA512: 6132e8c214edc6f199a5550309daf4ed5035f24f545c793d6396c393bd2f55940dc418af62aed9aff25c0c90b74ee384ace986f7201db4018c6fd52710006126
2022-04-20 17:44:27 +00:00
sanket1729 9f79f8d1ce
Merge rust-bitcoin/rust-bitcoin#936: Make TaprooBuilder::finalize able to return keyspend only
7969b7a43e Make TaprooBuilder::finalize able to return keyspend only (Jeremy Rubin)

Pull request description:

ACKs for top commit:
  JeremyRubin:
    > ACK 7969b7a
  sanket1729:
    ACK 7969b7a43e
  apoelstra:
    ACK 7969b7a43e

Tree-SHA512: 26d0b730590f610a858061394faafaa74b13dd353f34ccf1c6166d0cbb62937010eed5661a887f7bea4f983ac9eab8cdca10a5fe7bd74f2dd5701a7782cbac64
2022-04-20 09:39:20 -07:00
Dr Maxim Orlovsky 4cdff06b1e
Add convenience method TapTree:to_builder 2022-04-20 10:31:28 +02:00
Dr Maxim Orlovsky a12e7c73b6
Implement From<TapTree> for TaprootBuilder 2022-04-20 10:30:45 +02:00
Dr Maxim Orlovsky 410412ff01
Rename TapTree::from_builder 2022-04-20 10:30:45 +02:00
Dr Maxim Orlovsky 219273788c
Rename TapTree::into_builder 2022-04-20 10:28:28 +02:00
Dr Maxim Orlovsky f9d8d0d968
Make TapTree::node_info public 2022-04-20 10:28:28 +02:00
Dr Maxim Orlovsky 3c59897598
Removed IntoIterator for TapTree implementation
In the future, TapTree may iterate over different node types, and that's why it does not have `iter()` function; using instead `script_leafs`. Thus, we should not have IntoIterator implementation as well
2022-04-19 20:32:13 +02:00
Dr Maxim Orlovsky 7a5482d23a
Rename LeafInfo into ScriptLeaf 2022-04-19 20:32:13 +02:00
Dr Maxim Orlovsky 2b8d96581a
Rename TapTree::iter into TapTree::script_leaves 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 6f871ba47d
Add convenience LeafInfo::depth method
Without this method computation of the leaf depth requires cloning due
to the requirements of merkle_branch.into_inner()
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 3c502ffc2d
Making all LeafInfo fields private 2022-04-19 20:31:49 +02:00