Commit Graph

193 Commits

Author SHA1 Message Date
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
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 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 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 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 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
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 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
violet360 5afb0eaf40 API to get an iterator for funding utxos in psbt 2022-04-25 18:18:11 +05:30
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
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 3c502ffc2d
Making all LeafInfo fields private 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky d655ff3e93
Make TapTreeIterator use LeafInfo
Previously used depth and script tuple missed information about the leaf version. 
All three comprises already existing type `LeafInfo` which was made public in 
previous commits.
2022-04-19 20:31:49 +02:00
Tobin Harding f92854a805 Add PSBT alias
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`.
2022-04-18 07:21:19 +10:00
sanket1729 c97589f8de Fix TapTree derserialization
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
2022-04-14 10:04:46 -07:00
Andrew Poelstra 8ca18f75dd
Merge rust-bitcoin/rust-bitcoin#929: Fix TapTree hidden branches bug
c036b0db6f Unit test for failing TapTree on builder containing hidden nodes. (Dr Maxim Orlovsky)
77715311cf Prevent TapTree from hidden parts (Dr Maxim Orlovsky)
b0f3992db1 Rename TaprootBuilder::is_complete into is_finalized (Dr Maxim Orlovsky)
efa800fb1f Make TapTree::from_inner return a proper error type (Dr Maxim Orlovsky)
e24c6e23e3 TapTree serialization roundtrip unit test (Dr Maxim Orlovsky)
56adfa4527 TaprootBuilder::has_hidden_nodes method (Dr Maxim Orlovsky)
e69701e089 Rename taproot `*_hidden` API into `*_hidden_nodes` (Dr Maxim Orlovsky)
6add0dd9dc Track information about hidden leaves in taproot NodeInfo (Dr Maxim Orlovsky)

Pull request description:

  Closes #928

ACKs for top commit:
  sanket1729:
    ACK c036b0db6f. Reviewed the range diff
  apoelstra:
    ACK c036b0db6f

Tree-SHA512: 3a8193e6d6dd985da30a2094d1111471b5971f422525870003b77b6ac47cd4ad6e718d46a6d86bbb5e92e5253ac53804badf67edd98bbccbdc11e6383c675663
2022-04-14 17:03:14 +00:00
Dr Maxim Orlovsky c036b0db6f
Unit test for failing TapTree on builder containing hidden nodes. 2022-04-05 22:43:52 +02:00
Dr Maxim Orlovsky 77715311cf
Prevent TapTree from hidden parts 2022-04-05 22:30:34 +02:00
Dr Maxim Orlovsky b0f3992db1
Rename TaprootBuilder::is_complete into is_finalized 2022-04-05 22:29:32 +02:00
Dr Maxim Orlovsky efa800fb1f
Make TapTree::from_inner return a proper error type 2022-04-05 22:29:20 +02:00
Dr Maxim Orlovsky e24c6e23e3
TapTree serialization roundtrip unit test 2022-04-05 22:18:23 +02:00
Tobin Harding 29843c41ef Allow deprecated function call
We have a deprecated function call because of the MSRV, tell clippy to
ignore it.
2022-04-04 18:28:09 +10:00
sanket1729 cb4d34fd40
Merge rust-bitcoin/rust-bitcoin#932: Derive Eq for PSBT types
603e75eb77 Derive Eq for PSBT types (Dr Maxim Orlovsky)

Pull request description:

  Closes #931

ACKs for top commit:
  apoelstra:
    ACK 603e75eb77
  sanket1729:
    utACK 603e75eb77.

Tree-SHA512: 8099e80aa2000b3d1284543b6bfab3edd45f8649519bd09b4d73d250bdb6cce5edf67a1e0e0cec61db23c358daca286061641da5ff5c2a8b4b030d1199707c94
2022-04-01 11:38:45 -07:00
Andrew Poelstra 9316c52946
Merge rust-bitcoin/rust-bitcoin#917: Rename SigHash to Sighash
46c34b3fb7 Fix code comments referring to sighash (Tobin Harding)
8f36c3979c Use sighash not sig_hash in identifiers (Tobin Harding)
c3a167b96b Rename SigHash -> Sighash (Tobin Harding)
52b711c084 Rename InvalidSigHashType -> InvalidSighashType (Tobin Harding)
b84f25584e Rename SigHashCache -> SighashCache (Tobin Harding)
e37652578b Rename PsbtSigHashType -> PsbtSighashType (Tobin Harding)
c19ec339ef Rename NonStandardSigHashType -> NonStandardSighashType (Tobin Harding)
130e27349e Rename SigHashTypeParseError -> SighashTypeParseError (Tobin Harding)
6caba2ed24 Rename SchnorrSigHashType -> SchnorrSighashType (Tobin Harding)
5522454583 Rename EcdsaSigHashType -> EcdsaSighashType (Tobin Harding)

Pull request description:

  Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash' is a well known word in the Bitcoin ecosystem it should appear in identifiers as `Sighash`.

  Change various types, variants, and code comments to use sighash as a single word.

  - Patches 1-8 are code changes `s/SigHash/Sighash/g`
  - Patch 9 is code changes `s/sig_hash/sighash/g`
  - Patch 11 is docs fixes

  Fixes: #911

  ## Note to reviewers

  I've been particularly pedantic with the patch separation because we are so close to release.

  Done as separate patches to make review easier if review is to be done by reading the diffs. Perhaps at least one person could verify this PR programmatically by doing
  - Reset the last 2 patches (those are easy to do manually)
  - Check out master
  - Do `s/SigHash/Sighash/g` on all source files (bash function below)
  - Use `git diff branchA..branchB` to verify

  The difference between the two branches should only include comment lines (last three patches) and these seven instances of `SigHash:

  ```
  CHANGELOG.md:82:- [Add FromStr/Display implementation for SigHashType](a4a7035a94)
  CHANGELOG.md:93:- [Introduce `SigHashCache` structure](https://github.com/rust-bitcoin/rust-bitcoin/pull/390) to replace `SighashComponents` and support all sighash modes
  CHANGELOG.md:121:    - `SigHash`
  src/blockdata/transaction.rs:1190:            "SigHash_None",
  src/blockdata/transaction.rs:1191:            "SigHash_NONE",
  src/util/sighash.rs:1175:            "SigHash_None",
  src/util/sighash.rs:1176:            "SigHash_NONE",
  ```

  In case its useful, the shell function I used to do these changes is:
  ```bash
  function search-and-replace() {
      if (($# != 2))
      then
          echo "Usage: $0 <this> <that>"
          return
      fi

      local this="$1"
      local that="$2"

      # For all files containing $this, replace $this with $that.
      for file in $(git grep -l "$this")
      do
          perl -pi -e "s/$this/$that/g" "$file"
      done
  }
  ```

ACKs for top commit:
  dr-orlovsky:
    ACK 46c34b3fb7
  apoelstra:
    ACK 46c34b3fb7

Tree-SHA512: fe7e25e9cfb5155e4921de5ac185dbf9f4ca0770846d7892f6968b44fc5431f3f1a183380107449e90f7ea662094c60b118dc0468230384e8f9a8ef98d5ee0a0
2022-04-01 17:30:42 +00:00
Dr Maxim Orlovsky 603e75eb77 Derive Eq for PSBT types 2022-04-01 11:45:32 +02:00
Dr Maxim Orlovsky e3f173e521
Require taproot tree depth argument always to be u8 2022-03-31 15:12:05 +02:00
Tobin Harding 46c34b3fb7 Fix code comments referring to sighash
Recently we added a bunch of additional sighash types, some of the code
comments became stale. Use the non-specific term 'sighash type' instead
of a particular sighash identifier in comments to make the comments more
applicable.
2022-03-31 09:44:22 +11:00
Tobin Harding 8f36c3979c Use sighash not sig_hash in identifiers
Recently we update all types and docs to use `Sighash` instead of
`SigHash` because 'sighash' is a single word. We should apply the same
logic to functions and variable names.

Do not use an underscore in the identifier 'sighash'.
2022-03-31 09:42:52 +11:00
Tobin Harding 52b711c084 Rename InvalidSigHashType -> InvalidSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `InvalidSigHashType` variant to `InvalidSighashType`.
2022-03-31 09:42:52 +11:00
Tobin Harding e37652578b Rename PsbtSigHashType -> PsbtSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `PsbtSigHashType` to `PsbtSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding c19ec339ef Rename NonStandardSigHashType -> NonStandardSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `NonStandardSigHashType` type and error variant to
`NonStandardSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding 130e27349e Rename SigHashTypeParseError -> SighashTypeParseError
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `SigHashTypeParseError` to `SighashTypeParseError`.
2022-03-31 09:42:18 +11:00
Tobin Harding 6caba2ed24 Rename SchnorrSigHashType -> SchnorrSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `SchnorrSigHashType` to `SchnorrSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding 5522454583 Rename EcdsaSigHashType -> EcdsaSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `EcdsaSigHashType` to `EcdsaSighashType`.
2022-03-31 09:42:18 +11:00
Andrew Poelstra b32d40390c
Merge rust-bitcoin/rust-bitcoin#898: Make PsbtSigHashType use the same formatting as other *SigHashTypes
992857ad0a PsbtSighashType unit tests (Dr Maxim Orlovsky)
5be1cdb8c7 PsbtSigHashType Display and FromStr implementation (Dr Maxim Orlovsky)
7cdcdaad6c Support SIGHASH_RESERVED in SchnorrSigHashType::from_u8 (Dr Maxim Orlovsky)

Pull request description:

  The newly introduced `PsbtSigHashType` uses very different serde formatting from previously used `EcdsaSigHashType`; for instance it does not output human-readable sighash. This is especially obvious when printing out PSBT as JSON/YAML object and is a breaking change from the `0.27`. Serde human-readable implementation requires `Display/FromStr`, which were also absent.

ACKs for top commit:
  sanket1729:
    ACK 992857ad0a. This is much better
  apoelstra:
    ACK 992857ad0a

Tree-SHA512: 71a46471f34b5481e4c1273a66846f59d61bfd98fcb65e7823ca216ff0dd419d81ca86d99c7aaf674fcfe2b1c010e899c8e74328f60a1e809015c663c453cc89
2022-03-28 17:34:20 +00:00