Commit Graph

2854 Commits

Author SHA1 Message Date
DanGould c1dd6ad8a2
Serialize Psbt fields, don't consensus_encode them 2022-12-21 12:19:38 -05:00
DanGould 1b7b08aa5d
De/serialize Psbt without consensus traits 2022-12-21 12:01:20 -05:00
Andrew Poelstra 7fee6239e1
Merge rust-bitcoin/rust-bitcoin#1493: upgrade secp256k1 to 0.25.0
ed1992ffbf build(deps): bump secp256k1 to 0.25.0 (Byron Hambly)

Pull request description:

  upgrades secp256k1 dependency to 0.25.0

  re: #1487

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

Tree-SHA512: ac102aeb37c0f9f9e2dce8723c57015a89cd88d5b962298cb3adf49ac35ce5bc0ac1690dbc06272a0b5c4083ec6b64234d505f1c33e679032462cde03e41ab84
2022-12-21 16:21:04 +00:00
Calvin Kim 411174c391 Add fuzz target for sha512_256 2022-12-21 16:36:35 +09:00
Calvin Kim 31fc1f8638 Add support for sha512/256
Adds a new file named sha512_256.rs that implements the sha512/256
hash. This was needed as a part of
https://github.com/rust-bitcoin/rust-bitcoin/discussions/1318 to
drop the sha2 dependency in current rustreexo code.
2022-12-21 16:36:31 +09:00
Byron Hambly ed1992ffbf
build(deps): bump secp256k1 to 0.25.0 2022-12-20 12:23:15 +02:00
Andrew Poelstra 77aee43685
Merge rust-bitcoin/rust-bitcoin#1485: Add `tapscript_leaf_hash()` to `Script`
bae264d0c2 Add `tapscript_leaf_hash()` to `Script` (Jiri Jakes)

Pull request description:

  Adds convenience method to `Script` for computing leaf hash of tapscript. Closes #1482.

  The little test case is taken from `bip341_tests.json`.

ACKs for top commit:
  Kixunil:
    ACK bae264d0c2
  apoelstra:
    ACK bae264d0c2

Tree-SHA512: fb7a3a552017208decd56ca7d27eab1987a3a92aae5b8620896b3a02986c2fc13043c200ccfbadf9cfdd2d74af38b0bc25936338f55b7d318c1296acc88bf22a
2022-12-19 21:07:59 +00:00
Andrew Poelstra dc91b87990
Merge rust-bitcoin/rust-bitcoin#1477: Patch hashes and update the code
6acf9ac8b8 Patch hashes and update the code (Martin Habovstiak)

Pull request description:

  This patches `bitcoin_hashes` to use the version in the repository and fixes the code after removal of `Deref`.

ACKs for top commit:
  tcharding:
    ACK 6acf9ac8b8
  apoelstra:
    ACK 6acf9ac8b8

Tree-SHA512: b779fa79309f1d648020146b58e96346b67e9f76e29551cbd50251ea6bb7bcfc4c5d42f49cc7ad5660dcd0a5f6306efe96dfcd9530e4b32c62edf4af7076d830
2022-12-19 20:34:20 +00:00
Andrew Poelstra eaee7c52dd
Merge rust-bitcoin/rust-bitcoin#1486: Fix typos in docs
4a6a12011d Fix typos in docs (Daniela Brozzoni)

Pull request description:

  See #828

ACKs for top commit:
  Kixunil:
    ACK 4a6a12011d
  apoelstra:
    ACK 4a6a12011d

Tree-SHA512: 3d3e2c37479986e51595a506c5310a37e51b9a84f9eb2f17c0217430e8150b7a9a7ee8b9c383df6c4ec581a081ea2a722ed4070ff4ede8d777d3bf2a2c19f15e
2022-12-19 20:24:09 +00:00
Andrew Poelstra 8cbecf0209
Merge rust-bitcoin/rust-bitcoin#1483: Mention Script::is_v1_p2tr above Witness::tapscript
67ca3463c0 Mention Script::is_v1_p2tr above Witness::tapscript (Casey Rodarmor)

Pull request description:

  It seems useful to document that this check is also provided.

ACKs for top commit:
  tcharding:
    ACK 67ca3463c0
  Kixunil:
    ACK 67ca3463c0
  apoelstra:
    ACK 67ca3463c0

Tree-SHA512: b36ff89cd7bb4ffe48e1bc4fcbfe35116492f5b0f9fbce271abd83f266fdcb25f7faa459acc35f944c4bdfa2626c00c194400a11f32ad84a323a07bfa5ec1b0a
2022-12-19 19:04:36 +00:00
Daniela Brozzoni 4a6a12011d
Fix typos in docs
See #828
2022-12-19 09:32:52 +01:00
Jiri Jakes bae264d0c2 Add `tapscript_leaf_hash()` to `Script` 2022-12-19 08:35:35 +01:00
Martin Habovstiak 6acf9ac8b8 Patch hashes and update the code
This patches `bitcoin_hashes` to use the version in the repository and
fixes the code after removal of `Deref`.

This also turns off `AS_DEPENDENCY` check with the intention to refactor
it later.
2022-12-18 14:33:55 +01:00
Casey Rodarmor 67ca3463c0 Mention Script::is_v1_p2tr above Witness::tapscript 2022-12-17 16:37:01 -08:00
Andrew Poelstra 0203107360
Merge rust-bitcoin/rust-bitcoin#1475: add some documentation clarifying the locktime ordering shenanigans in #1330
02c1cd6291 add some documentation clarifying the locktime ordering shenanigans in #1330 (Andrew Poelstra)

Pull request description:

  Updates the CHANGELOG and also the doccomment on `Transaction`.

ACKs for top commit:
  tcharding:
    ACK 02c1cd6291
  Kixunil:
    ACK 02c1cd6291
  sanket1729:
    ACK 02c1cd6291

Tree-SHA512: e2d23a90fb1e53758449fe49a3db7ae1497a260ce7efcade4b50265fa70840db273609019590d9d0a69e1272607a6bcf37924b805b4f09909487eb0c3b91a3cd
2022-12-16 14:41:00 +00:00
Andrew Poelstra 02c1cd6291
add some documentation clarifying the locktime ordering shenanigans in #1330 2022-12-15 23:12:03 +00:00
Andrew Poelstra 033d964b57
Merge rust-bitcoin/rust-bitcoin#1419: Run clippy in ci for `hashes`
b78ba730f2 hashes: Run clippy in ci (Tobin C. Harding)
5e67f7a7cb Remove the unnecessary explicit reference (Tobin C. Harding)

Pull request description:

  Currently we only run the linter in `bitcoin/contrib/test.sh`, we should do the same in the `hashes` ci script.

  - Patch 1: Fix current clippy issues in `hashes` crate
  - Patch 2: Run clippy in CI for `hashes` crate

ACKs for top commit:
  apoelstra:
    ACK b78ba730f2
  Kixunil:
    ACK b78ba730f2

Tree-SHA512: f9fedcd8c1a06c715396cf6c7b752e2c9e32dbfde48c8b4bcb9ac5e701abe109ddeadc2e7466f6926f7c3ab74fa26e68b70473b4a5b5009cb4644d634707d4ea
2022-12-15 20:34:13 +00:00
Andrew Poelstra c657a1be3c
Merge rust-bitcoin/rust-bitcoin#1467: Add weight utilities to `TxIn` and `TxOut`
6d51e9255b Add weight utilities to `TxIn` and `TxOut` (Daniela Brozzoni)

Pull request description:

  - Add `segwit_weight` and `legacy_weight` methods to `TxIn`
  - Add `weight` method to `TxOut`

ACKs for top commit:
  danielabrozzoni:
    > ACK [6d51e92](6d51e9255b)
  apoelstra:
    ACK 6d51e9255b
  Kixunil:
    ACK 6d51e9255b

Tree-SHA512: 217eae49b5f6e8149af251fb82682aed34e0003342d19ec66aa0f66b8044d50c18d1e3e2d58068e4d2572b1af8bbc3403bfd5447662b45bc4f1e0e7f0672964f
2022-12-15 20:21:00 +00:00
sanket1729 5b10e6cf0c
Merge rust-bitcoin/rust-bitcoin#1155: Implemented unsized `Script`
8e428562cb Implemented unsized `Script` (Martin Habovstiak)

Pull request description:

  This renames `Script` to `ScriptBuf` and adds unsized `Script` modeled
  after `PathBuf`/`Path`. The change cleans up the API a bit, especially
  all functions that previously accepted `&Script` now accept truly
  borrowed version. Some functions that perviously accepted `&[u8]` can
  now accept `&Script` because constructing it is no loger costly.

  This is a more idiomatic alternative to #884 with two unavoidable lines of `unsafe` copied from `std`.

  Closes #522
  Closes #949

  (For 949, we allow users to use whichever they like but still use `ScriptBuf` in `Transaction`.)

ACKs for top commit:
  apoelstra:
    ACK 8e428562cb
  tcharding:
    ACK 8e428562cb
  sanket1729:
    ACK 8e428562cb. Let's get this in

Tree-SHA512: 2ff7f0b3abd1999261388b7c5075aa1caa17bdaf4538b443bd098c31565d9dc8423ae3f9a9b3cd2f0aee6a01591992dbe8c9592f9cf14ec0f7cc395f696b9a66
2022-12-15 05:44:57 -08:00
Daniela Brozzoni 6d51e9255b
Add weight utilities to `TxIn` and `TxOut`
- Add `segwit_weight` and `legacy_weight` methods to `TxIn`
- Add `weight` method to `TxOut`
2022-12-15 09:20:56 +01:00
Martin Habovstiak 8e428562cb Implemented unsized `Script`
This renames `Script` to `ScriptBuf` and adds unsized `Script` modeled
after `PathBuf`/`Path`. The change cleans up the API a bit, especially
all functions that previously accepted `&Script` now accept truly
borrowed version. Some functions that perviously accepted `&[u8]` can
now accept `&Script` because constructing it is no loger costly.
2022-12-14 23:21:27 +01:00
Andrew Poelstra f231617103
Merge rust-bitcoin/rust-bitcoin#1330: Remove `PackedLockTime` in favor of `absolute::LockTime`
1b15a13e5a run cargo clippy and fmt (Andrew Poelstra)
f2a5596899 examples: clean up taproot PSBT example locktime handling (Andrew Poelstra)
821842e1a1 drop Ord on absolute::LockTime; add Ord to Transaction (Andrew Poelstra)
5b7d801ee6 remove PackedLockTime type (Andrew Poelstra)
4dee116b8a delete PackedLockTime by aliasing it to LockTime (Andrew Poelstra)
fa81568fb6 locktime: add `FromHexStr` impl for `LockTime` (Andrew Poelstra)
74ff4946e4 locktime: unify serde impls (Andrew Poelstra)

Pull request description:

  This is potentially a controversial PR, but hear me out. My argument is that right now `absolute::LockTime` and `PackedLockTime` are basically identical types; they can be converted between each other with `From` and they have exactly the same semantics except that `PackedLockTime` has `Ord` on it. This makes it very confusing to tell which one should be used, for example in PSBT2 where there are now extra locktime-related fields.

  The motivation for having `PackedLockTime` independent of `LockTime` are:
  * `PackedLockTime` is theoretically more efficient because you don't need to unpack the field, don't need to store a enum discriminate, etc. I don't buy this. If you are trying to save individual bytes in your transaction-parsing there are lots of places you'd look before messing around with locktimes, so we shouldn't privilege this specific thing.
  * `PackedLockTIme` has an `Ord` impl, and removing that will have a cascading effect on transactions, blocks, etc., preventing them from being held in `BTreeMaps` etc. **My proposal**, implemented here, is to just manually impl `Ord` on `Transaction` and don't impl it on `LockTime`.

  I recall some argument that we need to be able to sort miniscripts, and miniscripts might have locktimes in them, but I think this is wrong -- miniscripts always have explicitly either a `Height` or a `Time`, and there is no problem ordering these.

  Closes #1455

ACKs for top commit:
  sanket1729:
    code review ACK 1b15a13e5a
  tcharding:
    ACK 1b15a13e5a

Tree-SHA512: d9776f14560c3822980e8fff8978bf8ca753035152f957a84af25d063c66e4e9df3d5cf98af38d6cb59cc52ba407282f722925b1ca670ae623ac91add3149d2f
2022-12-14 18:21:07 +00:00
Tobin C. Harding 56e4e53357 hashes: ci: Remove --all
Currently we are using the `--all` flag in `cargo` commands in the
`hashes` CI script. This flag (the deprecated version of `--workspace`)
causes cargo to run the command for the whole workspace, this is not
what we want because we run test individually for each crate using a ci
script per crate.

The effect of this patch is to reduce re-runs of tests i.e., reduce
machine usage during CI runs with no reduction of coverage - PROFIT!
2022-12-14 08:24:59 +11:00
Andrew Poelstra d581207cb8
Merge rust-bitcoin/rust-bitcoin#1450: hashes: Do not implement `Deref`
b7a84d0c68 hashes: Do not implement Deref (Tobin C. Harding)

Pull request description:

  Currently we implement `Deref` for hashes. From the docs [0]

   > Deref should only be implemented for smart pointers to avoid confusion

  Furthermore because we implement `Deref` as well as implement `internals::hex::display::DisplayHex` for slices hashes get coerced into slices and `to_lower_hex_string` can be called on them, this is incorrect because `DisplayHex` does not account for hashes that display backwards so we end up with the wrong string.

  This is an API breaking change, and I have not built any other crates in our stack to check if anything breaks.

  [0] https://doc.rust-lang.org/std/ops/trait.Deref.html

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

Tree-SHA512: 573169095dd9f9032e3f685e3b0af3b569f1cb5368e1b2f37940504fd887592f46488abcfbe84107baf9c5453c7db47bc342a6bc273ff98cb0570ffacb549c21
2022-12-13 20:59:41 +00:00
Andrew Poelstra 1b15a13e5a
run cargo clippy and fmt 2022-12-13 14:52:43 +00:00
Andrew Poelstra f2a5596899
examples: clean up taproot PSBT example locktime handling
This still has the line

    let lock_time = absolute::LockTime::from_height(psbt.unsigned_tx.lock_time.to_consensus_u32() + lock_time_delta).unwrap();

I'm unsure whether this "adding height to a locktime" concept is a
meaningful thing or just the sort of thing that shows up in example
code. Maybe we should have first-class support for it.

Note that the line, as written, depends on the fact that the original
locktime was a small blockheight. A proper function for this would
handle the exceptional case gracefully.
2022-12-13 14:52:43 +00:00
Andrew Poelstra 821842e1a1
drop Ord on absolute::LockTime; add Ord to Transaction 2022-12-13 14:52:36 +00:00
Tobin C. Harding b7a84d0c68 hashes: Do not implement Deref
Currently we implement `Deref` for hashes. From the docs [0]

 > Deref should only be implemented for smart pointers to avoid confusion

Furthermore because we implement `Deref` as well as implement
`internals::hex::display::DisplayHex` for slices hashes get coerced into
slices and `to_lower_hex_string` can be called on them, this is
incorrect because `DisplayHex` does not account for hashes that display
backwards so we end up with the wrong string.

[0] https://doc.rust-lang.org/std/ops/trait.Deref.html
2022-12-12 12:05:54 +11:00
Andrew Poelstra 5b7d801ee6
remove PackedLockTime type
This can be replicated by deleting the `type PackedLockTime = LockTime'
line, and then running
    find . -type f | xargs sed -i 's/PackedLockTime/LockTime/g
at the root of the repo.
2022-12-11 19:08:14 +00:00
Andrew Poelstra 4dee116b8a
delete PackedLockTime by aliasing it to LockTime
The next commit will be a mechanical s/PackedLockTime/LockTime/; this commit
seemed like the easiest way to facilitate that.
2022-12-11 19:00:01 +00:00
Andrew Poelstra fa81568fb6
locktime: add `FromHexStr` impl for `LockTime`
This will be tested in a later commit, when `PackedLockTime` is folded
into this type so all its tests apply to `LockTime`.
2022-12-11 18:59:24 +00:00
Andrew Poelstra 74ff4946e4
locktime: unify serde impls 2022-12-11 18:48:56 +00:00
Andrew Poelstra 32afe5ae48
Merge rust-bitcoin/rust-bitcoin#1400: Add trait `FromStrHex` for tuple structs with single `u32` member
e00dfa9806 impl FromHexStr for structs with single u32 member (connormullett)

Pull request description:

  Closes: #1112

   - Adds new trait `FromStrHex` with 2 methods: `from_hex_str` and `from_hex_str_no_prefix`
   -  Impl new trait on each tuple struct with single u32 member. eg `Time(u32)`

  As stated in the issue, grep through codebase with `\(u32\)` and `\(pub u32\)` to see all implementations and verify none were missed.

  NonStandardSighashType is an error type and should never be constructed from a hex string. Therefore, it has been omitted from this change.

  Tests are somewhat redundant, but cover 4 cases each. 2 happy paths, 1 for each function. 1 case for malformed/invalid hex input, and 1 for calling no_prefix without a prefix

ACKs for top commit:
  Kixunil:
    ACK e00dfa9806
  apoelstra:
    ACK e00dfa9806

Tree-SHA512: 221faef7fc1fa8fdb4cba79cfae317a0b63984937c345c6ca2287123a078f38911cdc07db7589a88b7bc6fbecf389e9bcff47952728410510ffcfc1857e0f91f
2022-12-11 18:47:32 +00:00
connormullett e00dfa9806 impl FromHexStr for structs with single u32 member
Adds new module `string` to be later converted to its own
crate. The module currently contains the FromHexStr trait and an error
type to be used for implementing hex parsing on types. This change
also adds implementations of FromHexStr for types with a single u32
member such as `Sequence(pub u32)`. All structs that match the
following regex have been given this implementation
`\(u32\)` and `\(pub u32\)`. All implementations have associated
unit tests matching all possible cases. NonStandardSighashType has
been ommitted from this change as it is an error and should not be
constructed using the methods added in this change.

Adds parse::hex_u32 for future use to be made generic to allow
different sizes of integers to be parsed from hex strings.

The error type FromHexError implements required traits such as
Display and std::error::Error
2022-12-11 00:01:58 -05:00
Andrew Poelstra c93e83e94b
Merge rust-bitcoin/rust-bitcoin#1428: Adds Network::from_core_arg and links it to Network::from_str
d7006ef80d Adds roundtrip tests for Network::from_core_arg (Sergi Delgado Segura)
bd1eb29f61 Adds Network::to_core_arg (Sergi Delgado Segura)

Pull request description:

  Comming from https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/247

  `Network::from_str` only considers `rust-bitcoin` string as possible inputs to create a `Network` instance. This PR adds a new method to `Network`, `from_core_arg`, which is complementary to the existing `Network::to_core_arg`. This method allows the conversion between `bitcoind -network` string and `Network` variants.

  This also links `Network::from_str` to `Network::from_core_arg` so the default case on the former calls the latter, and an error is only returned if none of the cases match.

ACKs for top commit:
  Kixunil:
    ACK d7006ef80d
  apoelstra:
    ACK d7006ef80d

Tree-SHA512: 97a66f858a7d4a3642bdef9016457833cfc1181e276f7ead7c6b87f6fcdcb7c5d1cfdb4b621225b806bc5949c3c5cc6a32b7df934157542d7c79aa00a9e20f41
2022-12-08 15:12:40 +00:00
Andrew Poelstra ca563c4b27
Merge rust-bitcoin/rust-bitcoin#1234: Serde derive in tests
c822fcf435 Remove helper variables (Martin Habovstiak)
70d1a0348e Use serde derive rather than manual parsing (Martin Habovstiak)

Pull request description:

  Manual parsing Json is tedious and error-prone. It contained a bunch of
  `unwrap`s and was hard to read.

  This replaces manual Json parsing with serde_derive implementation.

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/1231

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

Tree-SHA512: 0e1df6a62dc8438d67979a00658f8a2820135beebdd01d7275149b06feacd0d18accb86cecbf8c85f9a02ddc724575eaffff079b45cfe0e7765c8559c5eb03f7
2022-12-08 14:21:18 +00:00
Sergi Delgado Segura d7006ef80d Adds roundtrip tests for Network::from_core_arg 2022-12-08 07:19:22 -05:00
Sergi Delgado Segura bd1eb29f61 Adds Network::to_core_arg
This allows users to create `Network` instances from `bitcoind -chain` values
2022-12-08 06:33:24 -05:00
Andrew Poelstra fd5c5e43d2
Merge rust-bitcoin/rust-bitcoin#1357: Do some rustdoc cleanups
26be9ddd27 Make RBF rustdoc more scrary (Tobin C. Harding)
c9a49d5be7 blockdata: Improve content of rustdocs (Tobin C. Harding)
e1e5974065 consensus: Improve rustdocs (Tobin C. Harding)
c553299ace Remove uninformative code comments (Tobin C. Harding)
bbd39e5ecc Use longer column width (Tobin C. Harding)
31740710ee blockdata: Improve rustdocs (Tobin C. Harding)
fb708ca74b Add newline after brief description (Tobin C. Harding)

Pull request description:

  Put some effort into our documentation, this is all pretty non-controversial. Patches separated to ease review.

ACKs for top commit:
  Kixunil:
    ACK 26be9ddd27
  apoelstra:
    ACK 26be9ddd27

Tree-SHA512: 8990ed812b3bb55f722ac7e85a8655b65744eb21ad3b16dae77e05d9273f86e248f1ef4945a35d7767241038986bc23e0a8024347e600f0c1e53f8de992208e2
2022-12-07 13:48:11 +00:00
Tobin C. Harding 26be9ddd27 Make RBF rustdoc more scrary
In order to really bring the security risks of RBF to peoples attention
make the docs more scary.
2022-12-06 12:25:30 +11:00
Tobin C. Harding c9a49d5be7 blockdata: Improve content of rustdocs
Recently we (tcharding) do some mechanical improvements to the rustdocs
in the `blockdata` module without considering the content. On review a
bunch of improvements were suggested.

Improve the content of various rustdoc comments in the `blockdata`
module.

Suggested content came from reviewers, all mistakes are my own :)
2022-12-06 12:25:30 +11:00
Tobin C. Harding e1e5974065 consensus: Improve rustdocs
Do an audit of the `consensus` module and clean up rustdocs.
2022-12-06 12:25:30 +11:00
Tobin C. Harding c553299ace Remove uninformative code comments
The comments add no value to the code, remove them.
2022-12-06 12:25:30 +11:00
Tobin C. Harding bbd39e5ecc Use longer column width
Reduce the number of lines of code by using a longer column width, 100
as is more-or-less standard in this repo.

This patch only changes column width (line length), no other changes.
2022-12-06 12:25:30 +11:00
Tobin C. Harding 31740710ee blockdata: Improve rustdocs
Do an audit of the `blockdata` module and clean up rustdocs.
2022-12-06 12:25:26 +11:00
Tobin C. Harding fb708ca74b Add newline after brief description
rustdocs should contain a newline to separate the brief description from
the rest of long description.
2022-12-06 12:25:04 +11:00
Martin Habovstiak c822fcf435 Remove helper variables 2022-12-05 22:23:44 +01:00
Martin Habovstiak 70d1a0348e Use serde derive rather than manual parsing
Manual parsing Json is tedious and error-prone. It contained a bunch of
`unwrap`s and was hard to read.

This replaces manual Json parsing with serde_derive implementation.

Closes #1231
2022-12-05 22:23:36 +01:00
Andrew Poelstra 52fbb043b6
Merge rust-bitcoin/rust-bitcoin#1254: Consensus encoding based serialization
1a2cf2681d Implement consensus encoding adapter for serde (Martin Habovstiak)
a6ecc58a5e Add `put_bytes_min` and `space_remaining` methods (Martin Habovstiak)

Pull request description:

  In some protocols it is preferred to serialize consensus-encodable types
  using consensus encoding. E.g. serialize `Transaction` as hex-encoded
  string in Json in Bitcoin Core RPC protocol. This change provides
  adapter to make this easier.

  The adapter allows providing custom byte-to-string encoder for more
  exotic cases and provides a hex implementation which should be useful in
  majority of the cases.

  Should help with #765

  Based on #1252

  Required by #1234

ACKs for top commit:
  tcharding:
    ACK 1a2cf2681d
  apoelstra:
    ACK 1a2cf2681d

Tree-SHA512: 96e10cf6ea0e7dfecfb58ee97453e0e7c8a2cfbb8af1e73a23c3afb67b985b394976361ac237528991fbb7344cc9f24644869199008245a91838309aff34bb97
2022-12-05 16:25:55 +00:00
Andrew Poelstra 4fccd3fb84
Merge rust-bitcoin/rust-bitcoin#1437: Add log2 to Work
df90c50242 Add log2 to Work (Jiri Jakes)

Pull request description:

  Adds method `Work::log2()` providing value equivalent to Bitcoin Core's `log2_work` in its logs. Fixes #1326.

  Questions:

  - The original issue (#1326) also suggests to add log2 to Target but it does not seem to be meaningful, does it? Bitcoin Core, to which the issue refers, also displays only log2 of work.
  - Although work should not be 0, the type allows it. In this case, log2 would return -inf. I think we could leave it like that but if there are suggestions to deal with it in a different way, please let me know.

ACKs for top commit:
  Kixunil:
    ACK df90c50242
  tcharding:
    ACK df90c50242
  apoelstra:
    ACK df90c50242

Tree-SHA512: 24e83c849ea3e16cad6f1636920883967cdac90b1b98ab19e86d1a5d0ac4585079740b54c1315afecabc1943d29a8b94316e3586bd2d10f1b61cc5cf7ad5b273
2022-12-03 21:19:38 +00:00