In order to sign a utxo that does a p2wpkh spend we need to create the
script that can be used to create a sighash. In the libbitcoin docs this
is referred to as the 'script code' [0].
The script is the same as a p2pkh script but the pubkey_hash is found in
the scriptPubkey.
Add a `Script` conversion method that checks if `self` is a v0 p2wpkh
script and if so extracts the pubkey_hash and returns the required
script.
[0] https://github.com/libbitcoin/libbitcoin-system/wiki/P2WPKH-Transactions#spending-a-p2wpkh-output
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`.
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
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
29843c41ef Allow deprecated function call (Tobin Harding)
Pull request description:
We have a deprecated function call because of the MSRV, tell clippy to ignore it.
ACKs for top commit:
Kixunil:
ACK 29843c41ef conditioned on adding this to MSRV bump TODO list.
sanket1729:
ACK 29843c41ef.
Tree-SHA512: 3e2bf95d05c3baff4f01c447717dde4e78d686cbc6f720591f6656ce1e5d8cf3a276a0c3dc0016dea357b61350091778d4500a59427ea9863eb5bb9344b822e4
This adds tests for the previously untested reject message
(de)serialization. The two reject messages were received from an
older Bitcoin Core peer that still sends reject messages.
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
f27c4a541d Added push_x_only_key(..) and its test. (mpls)
Pull request description:
**Issue**
I can not use [`XOnlyPublicKey`](ae985dd191/src/key.rs (L973)) in my Scripts which prevents me from working with Taproot.
**Cause**
The current version of [`script::Builder`](0a2d45de09/src/blockdata/script.rs (L121)) does not accept `XOnlyPublicKey`s.
**Solution**
So, I created a function `push_xkey(self, key: &XOnlyPublicKey)` based on the existing [`push_key`](0a2d45de09/src/blockdata/script.rs (L914)) function. I also augmented an [existing test](0a2d45de09/src/blockdata/script.rs (L1108)) in an attempt to reach testing parity with existing code.
After toying around with `push_xkey`, it seems to work on my end.
ACKs for top commit:
dr-orlovsky:
ACK f27c4a541d
sanket1729:
utACK f27c4a541d. Thanks a lot for keeping up the iterations with prompt responses
Tree-SHA512: 064958d49edc1d3636a21e428d62c2e9bcd9b13bd226c5821db9e04ce78663a11fcf601c7667b564f88e845207219a052e1c7413f50e5d27c79003e8129825ed
da731c4825 Add further description to the NodeInfo struct (Tobin Harding)
492ccebd99 Use links for error types (Tobin Harding)
3e05887579 Use 'the' to improve sentence (Tobin Harding)
Pull request description:
See to nits from review of https://github.com/rust-bitcoin/rust-bitcoin/pull/912
Three minor patches to the `taproot` module docs.
CC @dr-orlovsky
ACKs for top commit:
dr-orlovsky:
ACK da731c4825
sanket1729:
ACK da731c4825
Tree-SHA512: 17a27a19c88f9baa8127023b2ee30fc2259cb0058a92dc9d8ae595e9e02ccb047fefcba7548ff7900fffa7bc6853447183e80660b8756d90d055ab8aa96ae938
e3f173e521 Require taproot tree depth argument always to be u8 (Dr Maxim Orlovsky)
Pull request description:
There is an inconsistency in depth type: some places uses `u8` (which is reasonable, since the depth can't be >127), others use `usize`. This PR makes API consistent.
I think this should be a RC fix, since it affects newly introduced API in this release and it will be bad to make a breaking changes the next version after its introduction.
ACKs for top commit:
tcharding:
Hey @sanket1729, I know you pointed me already to `bitcoin-maintainer-tools` for acking PRs but I'm not finding how to do it. If you get a sec can you tell me like I'm 5 please. I used `gh pr comment 925 --body "ACK e3f173e"` to ack this but it does not get picked up as an 'approve'. Thanks
sanket1729:
ACK e3f173e521
Tree-SHA512: 58797e5f0e295310a9fa409d1d497711e40d95a5ef8424d7ad4206d6ba00b89d9f981600293245282d5acf948d58674d97cd24ace8f0228ffcb62989f1464350
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.
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'.
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 `SigHash` type to `Sighash`.
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`.
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 `SigHashCache` to `SighashCache`.
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`.
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`.
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`.
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`.
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`.
c25eddd187 Remove unnecessary documentation (Tobin Harding)
8631474f08 Improve docs in taproot module (Tobin Harding)
Pull request description:
I should have done this PR a month ago, my bad. This one is kind of important IMO because we are going to have so many people looking at this part of the code soon as we release.
As has been done in other places in the codebase; improve the docs in the `taproot` module by doing:
- Use full sentences (capital letters + full stops)
- Use back ticks and links for types where appropriate
- Fix grammar
- Fix stale docs
- Use third person for describing functions
- Use 100 character line width
- Use markdown sections (`# Examples`, `# Returns`) where appropriate
- Separate brief heading from extended description when appropriate
- Use `///` for all functions/types (both private and public)
I also did:
- Build the docs and check all the links
- Read all the built docs, check for sanity and pretty-ness
Its all in one patch, I couldn't really tease it apart. I can try a bit harder if it proves too annoying to review.
ACKs for top commit:
sanket1729:
ACK c25eddd187
dr-orlovsky:
ACK c25eddd187
apoelstra:
ACK c25eddd187
Tree-SHA512: 72f35bf8779392060388db985df5abc42a89796eaad1eafd08ea50b635d469fbd07a53ff253cdf27ad4d4baed7d37cec6ea1da1aece3672b9447f87181e218f8
8d602b8778 Fix deprecated since version (Tobin Harding)
Pull request description:
We deprecated the `bip143::SigHashCache` in
```
commit 53d0e176d3
Author: <elided>
Date: Fri Jul 16 10:44:18 2021 +0200
Deprecate bip143::SigHashCache in favor of sighash::SigHashCache
...
```
This means these changes are unreleased so the deprecated since version
should be the upcoming 0.28 release.
ACKs for top commit:
sanket1729:
Nice catch! ACK 8d602b8778
dr-orlovsky:
ACK 8d602b8778
Tree-SHA512: 7fba5b542de0d03e519a77204908cacb78c160bc41e02010b2bb258d8620d988dbc5d686a7b9f5144bf5afea414cb2c1b0c0f4e817c08b16f4c48c6f8d0de427
We deprecated the `bip143::SigHashCache` in
```
commit 53d0e176d3
Author: <elided>
Date: Fri Jul 16 10:44:18 2021 +0200
Deprecate bip143::SigHashCache in favor of sighash::SigHashCache
...
```
This means these changes are unreleased so the deprecated since version
should be the upcoming 0.28 release.
As has been done in other places in the codebase; improve the docs in
the `taproot` module by doing:
- Use full sentences (capital letters + full stops)
- Use back ticks and links for types where appropriate
- Fix grammar
- Fix stale docs
- Use third person for describing functions
- Use 100 character line width
- Use markdown sections (`# Examples`, `# Returns`) where appropriate
- Separate brief heading from extended description when appropriate
- Use `///` for all functions/types (both private and public)
I also did:
- Build the docs and check all the links
- Read all the built docs, check for sanity and pretty-ness
0d29c8388d rust-bitcoin 0.28.0-rc.2 (sanket1729)
b3e612a154 Remove misc whitespace (sanket1729)
Pull request description:
This does not include a changelog because rc.1 did not have changelog.
ACKs for top commit:
dr-orlovsky:
ACK 0d29c8388d
apoelstra:
ACK 0d29c8388d
Tree-SHA512: ec0858c0b075c023abb6a10e377b07b5fad56a683efb68450afe1270a74a705349c0050526125d8dd6bed08fc9aed263f4dde68f3c8ade6c76e6143da5f12691
174a99cd06 Implement serde for TweakedKeyPair (Dr Maxim Orlovsky)
df3297c34e Implement derives for TweakedKeyPair (Dr Maxim Orlovsky)
Pull request description:
We forgot about them and marked as TODO. This is clearly an RC fix
ACKs for top commit:
apoelstra:
ACK 174a99cd06
sanket1729:
ACK 174a99cd06
Tree-SHA512: 6cd446f1b73a9f381db976dcf77d75a108e60f5a521a0d387052779be5ac98ba6b82fb3a39dc58e5529ffcc4fb2fef2a037443dc1afde8309716096f97408a78