Commit Graph

3629 Commits

Author SHA1 Message Date
Andrew Poelstra 4fd88e2f30
Merge rust-bitcoin/rust-bitcoin#2298: Automated nightly rustfmt (2023-12-17)
5af7727250 2023-12-17 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  Kixunil:
    ACK 5af7727250
  apoelstra:
    ACK 5af7727250

Tree-SHA512: f3a4c7e80cc7d30eb10572bf44f3a0cd44748dd4f24a0d9f0fcf7de4f5c351c1dd17cbd80253b074f9fdac7e1bcf4bab7b0fbe61067e9a9dafc4fe5c25f1ab52
2023-12-17 15:03:24 +00:00
Fmt Bot 5af7727250 2023-12-17 automated rustfmt nightly 2023-12-17 00:59:05 +00:00
Martin Habovstiak 089ce8f0fb Deprecate `Script::is_provably_unspendable`
This method is not really that useful because it checked an arbitrary
condition. There already exists `OP_RETURN` semantics and the method
didn't cover all possible ways the script may be invalid.

This deprecates the method and documents why.
2023-12-15 23:55:21 +01:00
Andrew Poelstra eadc6a6c9e
Merge rust-bitcoin/rust-bitcoin#2207: policy: Add section on standard set of derives
cb42c74f58 policy: Add section on standard set of derives (Tobin C. Harding)
ec1a5a25c7 CONTRIBUTING: Remove stale links (Tobin C. Harding)

Pull request description:

  We can have a standard set of derives to make it easier for new devs to work out what to use and also to help us move towards a uniform set in preparation for crate stabilization.

  This is not me imposing my view but rather a place for the discussion to happen, could have been a discussions topic also? Using "open" instead of "draft" to aid visibility. Probably requires more than the usual amount of acks.

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

Tree-SHA512: b4c4094ea3652e92a5bea90e16f13971202710166524cc15abef5e8318ba5f59df084f5246331870fc641456b49d4e35d266c937375bdc5035f03699a7d4c1b9
2023-12-15 22:47:57 +00:00
Andrew Poelstra 9f68e6a6b5
Merge rust-bitcoin/rust-bitcoin#2286: fix : adds the arrayvec dependency
8783d526bd fix : adds the arrayvec dependency (harshit933)

Pull request description:

  This commit adds the arrayvec dependency to the sortKey.

  Potential fix #2276

ACKs for top commit:
  Kixunil:
    ACK 8783d526bd
  apoelstra:
    ACK 8783d526bd

Tree-SHA512: 35f28ade02dd526ce5dfa2f42578b36cd5af29a5a9f409da70a775bc12046674737e9bce9fabcc87f1b4669080ad10465c75601342f280c11eab11f791f44c36
2023-12-15 22:37:00 +00:00
Andrew Poelstra a90104af2d
Merge rust-bitcoin/rust-bitcoin#2232: Add `NetworkKind`
4354f37f51 Use NetworkKind in bip32 module (Tobin C. Harding)
35bbfcded7 Use NetworkKind in PrivateKey (Tobin C. Harding)
d22f3828f6 Use NetworkKind in address module (Tobin C. Harding)
6d5ef23e61 Add NetworkKind (Tobin C. Harding)

Pull request description:

  Add a new type `NetworkKind` the describes the kind of network we are on, ether mainnet or one of the test nets (testnet, regtest, signet).

  Use it in `Address`, `PrivateKey`, and `bip32`.

ACKs for top commit:
  Kixunil:
    ACK 4354f37f51
  apoelstra:
    ACK 4354f37f51

Tree-SHA512: d015283b55b2dc68c0a5cc5f17332fce648d3e4fb4e63e0b61943b7edfe4112e8ace760cb743cd3fd5ad0c34636e51a6a12382b34b6e62dfd7dab894d2ceefc0
2023-12-15 21:08:36 +00:00
harshit933 8783d526bd fix : adds the arrayvec dependency
This commit adds the arrayvec dependency to the sortKey.
2023-12-15 23:46:12 +05:30
Andrew Poelstra 37a6b48933
Merge rust-bitcoin/rust-bitcoin#2284: policy: Add section on returning `Self`
472da02c58 policy: Add section on returning Self (Tobin C. Harding)

Pull request description:

  Returning `Self` instead of the actual type makes refactoring easier, especially for error enums.

ACKs for top commit:
  Kixunil:
    ACK 472da02c58
  apoelstra:
    ACK 472da02c58

Tree-SHA512: 22c74ed02b06907a3e2d79e82620e90e5cad2bd64322fc87ce01640c1ca51907c43329211952c62776834bbdce936f312f82ab166e85a8559614cfa25c0db708
2023-12-15 15:07:30 +00:00
Andrew Poelstra 12e11a089c
Merge rust-bitcoin/rust-bitcoin#2287: Implement custom `ArrayVec` that is `Copy`
7c3b198127 Add a simple `Copy`-able `ArrayVec` (Martin Habovstiak)
f17c0402b7 Add tools that help with making code `const` (Martin Habovstiak)

Pull request description:

  While we decided to use `arrayvec::ArrayVec`, unfortunately it currently isn't `Copy` even if `T` is because of unfortunate interactions with the `Drop` trait. So this adds a super-simple custom version that is `Copy` and may be extended if we need to or replaced with `arrayvec` if they start supporting `Copy`.

ACKs for top commit:
  tcharding:
    ACK 7c3b198127
  apoelstra:
    ACK 7c3b198127

Tree-SHA512: 545cb99c910f9455185a78a77a1110374e45a11e374c698316a222e599737b82ec2ac5c8ef1a8fe7037f20d938b1a4061685b6c673061b706dc9df9478de2b48
2023-12-15 14:47:06 +00:00
Tobin C. Harding cb42c74f58
policy: Add section on standard set of derives
We can have a standard set of derives to make it easier for new devs to
work out what to use and also to help us move towards a uniform set in
preparation for crate stabilization. Mention the new `ordered` crate.
2023-12-15 12:06:37 +11:00
Tobin C. Harding ec1a5a25c7
CONTRIBUTING: Remove stale links
These sections have been removed but still have links in the index.
2023-12-15 12:06:36 +11:00
Tobin C. Harding 4354f37f51
Use NetworkKind in bip32 module
BIP-32 only differentiates between mainnet and some testnet when
encoding and decoding xpubs and xprivs. As such we can use the new
`NetworkKind` type instead of `Network` throughout the `bip32` module.
2023-12-15 11:50:50 +11:00
Tobin C. Harding 35bbfcded7
Use NetworkKind in PrivateKey
We only use the network to serialize and deserialize from WIF.
For this we only really need network kind since WIF only differentiates
between mainnet and non-mainnet.
2023-12-15 11:49:43 +11:00
Tobin C. Harding d22f3828f6
Use NetworkKind in address module 2023-12-15 11:49:41 +11:00
Tobin C. Harding 6d5ef23e61
Add NetworkKind
Add a new type `NetworkKind` the describes the kind of network we are
on, ether mainnet or one of the test nets (testnet, regtest, signet).

Do not use the type yet.
2023-12-15 11:40:38 +11:00
Martin Habovstiak 7c3b198127 Add a simple `Copy`-able `ArrayVec`
The `arrayvec::ArrayVec` type is not `Copy` which is not nice and we
would like to have a `Copy` type in our crates. While the PR to add
support to the `arrayvec` crate is not merged we implement our own
simplified version.

This one acts mostly as a dumb storage - it has just a few methods and
traits. The new ones can be added as needed later.
2023-12-15 01:37:53 +01:00
Martin Habovstiak f17c0402b7 Add tools that help with making code `const`
There are various challenges when making code `const`: making it
conditional, awkward copying of slices... This change adds tools that
help dealing with these challenges.
2023-12-15 01:37:33 +01:00
Tobin C. Harding 472da02c58
policy: Add section on returning Self
Returning `Self` instead of the actual type makes refactoring easier,
especially for error enums.
2023-12-15 10:44:34 +11:00
Andrew Poelstra 3d6151b9e1
Merge rust-bitcoin/rust-bitcoin#2277: Implement `CompressedPublicKey`
a92d49fe33 Implement `CompressedPublicKey` (Martin Habovstiak)

Pull request description:

  P2WPKH requires keys to be compressed which introduces error handling even in cases when it's statically known that a key is compressed. To avoid it, this change introduces `CompressedPublicKey` which is similar to `PublicKey` except it's statically known to be compressed.

  This also changes relevant code to use `CompressedPublicKey` instead of `PublicKey`.

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

Tree-SHA512: ff5ff8f0cf81035f042dd8fdd52a0801f0488aea56f3cdd840663abaf7ac1d25a0339cd8d1b00f1f92878c5bd55881bc1740424683cde0c28539b546f171ed4b
2023-12-14 00:08:46 +00:00
Andrew Poelstra e5272f3467
Merge rust-bitcoin/rust-bitcoin#2283: Remove unnecessary private extern crate
0d9c7add4a Remove unnecessary private extern crate (Tobin C. Harding)

Pull request description:

  In #2278 I mistakenly left in the `use extern crate` after removing the `pub` from it - while not incorrect it is unnecessary.

ACKs for top commit:
  apoelstra:
    ACK 0d9c7add4a

Tree-SHA512: 60a2638feda2ca5aea234de74fc751c8c140a47946f20cac95d804099f0ba7c78d8eef51912446024e2aafa97008bb93334c0fd3e97267a7f91c4ab86ffcd908
2023-12-13 23:05:26 +00:00
Tobin C. Harding 0d9c7add4a
Remove unnecessary private extern crate
In #2278 I mistakenly left in the `use extern crate` after removing the
`pub` from it - while not incorrect it is unnecessary.
2023-12-14 08:49:44 +11:00
Andrew Poelstra 8afa379f39
Merge rust-bitcoin/rust-bitcoin#2264: Improve the `io` crate
b58c235733 io: Make crate MSRV 1.56.1 (Tobin C. Harding)
063dac03bd Import core::cmp (Tobin C. Harding)
c038d00bd1 io: Move use statement (Tobin C. Harding)
21c44df76e inline sink function (Tobin C. Harding)
5610b9a6b6 Remove unnecessary rustdoc (Tobin C. Harding)

Pull request description:

  In preparation for adding the `BufRead` trait do a few improvements, the first ones are all trivial, the last sets the MSRV to Rust 1.56.1

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

Tree-SHA512: e750cd615d9423f4a581b80acb8c928d537538703e2079d7bb700e6155eee4bd9b768c1eb53b0b2aa841497474460ec5926ac59c11eea1722f028efacc87c813
2023-12-13 18:28:23 +00:00
Andrew Poelstra 6b9f927f7f
Merge rust-bitcoin/rust-bitcoin#2278: Fully encapsulate bitcoinconsensus
43b1ed1b86 Fully encapsulate bitcoinconsensus (Tobin C. Harding)

Pull request description:

  The `bitcoinconsensus` crate is not fully under our control because it exposes code from Core, so we cannot guarantee its stability across versions. To make our semver compliance easier we can fully encapsulate the `bitcoinconsensus` crate so it does not appear in our public API.

  ### Please note that with this applied:

  - The `bitcoinconsenus` crate is no longer exported at the crate root
  - No `bitcoinconsensus` types appear in our public API

ACKs for top commit:
  Kixunil:
    ACK 43b1ed1b86
  apoelstra:
    ACK 43b1ed1b86

Tree-SHA512: 9fc4f01a35396562e980a647784b22667cbd289e45b5c122610d23a1f8bcf0fe8b9c27e33745f14ee010050d4c2d2669b679fb39c7a108e4e86d2c14fd60571a
2023-12-13 15:07:41 +00:00
Tobin C. Harding b58c235733
io: Make crate MSRV 1.56.1
Same as for `rust-bitcoin`, make the MSRV of the `io` crate Rust 1.56.1
2023-12-13 14:22:01 +11:00
Tobin C. Harding 063dac03bd
Import core::cmp 2023-12-13 14:22:01 +11:00
Tobin C. Harding c038d00bd1
io: Move use statement
Use the newly settled upon policy governing layout for imports.
2023-12-13 14:22:01 +11:00
Tobin C. Harding 21c44df76e
inline sink function 2023-12-13 14:22:00 +11:00
Tobin C. Harding 5610b9a6b6
Remove unnecessary rustdoc
This doc does not document any type, remove it.
2023-12-13 14:22:00 +11:00
Tobin C. Harding 43b1ed1b86
Fully encapsulate bitcoinconsensus
The `bitcoinconsensus` crate is not fully under our control because it
exposes code from Core, so we cannot guarantee its stability across
versions. To make our semver compliance easier we can fully encapsulate
the `bitcoinconsensus` crate so it does not appear in our public API.
However, it is useful to have the crate itself exported, here we add an
"unstable" feature and only publicly export the `bitcoinconsensus` crate
if the "unstable" feature is enabled.
2023-12-13 13:37:52 +11:00
Andrew Poelstra 2a6b4c1f43
Merge rust-bitcoin/rust-bitcoin#2262: Clean up `io` usage
f06d12455f bitcoin: Remove the custom sink (Tobin C. Harding)
b503aa1544 Run the formatter (Tobin C. Harding)
3ca55fb163 Remove qualifying path from Read and Write (Tobin C. Harding)
ebeb21fa7a Import fmt::Write using underscore (Tobin C. Harding)
e2dbcb1d28 Use W for writer generic type (Tobin C. Harding)
8704d9f0ae docs: Fix grammar (Tobin C. Harding)

Pull request description:

  A few cleanups to how we use the `io` crate, this is reasonably trivial but commit `a6c7e696 Remove qualifying path from Read and Write` is big, I have however gone to some effort to make sure it is easy to flick through the diff.

  Done in preparation for another go at the `BufRead` stuff.

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

Tree-SHA512: 751c489c67901c7563f1cc91f7761a4e3c276ae1981010338134e8c13200720ba69fcc74948c1dc1e6e65390197da0da27b2b69b86034029748321b404142cba
2023-12-12 20:07:06 +00:00
Andrew Poelstra 24bc6aaad2
Merge rust-bitcoin/rust-bitcoin#2281: Allow `SignedAmount` parse values equal to `i64::MIN`
daa47b2061 Allow `SignedAmount` parse values equal to i64::MIN (Jiri Jakes)

Pull request description:

  Fixes #2267.

  Previously, parsing such textual value returned 'too big' error. This change fixes it and adds relevant tests. Without this patch, the newly added tests fail with `TooBig`.

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

Tree-SHA512: b6e4ee8ed3fa15ecb988b3a6f32f16a17ba9c6de0b99c8a198254d85d263cfffa0498487a3f47b7ddc2c976cade128ac6a7952baecc8721d5d45e057c0eb87b4
2023-12-12 18:04:33 +00:00
Martin Habovstiak a92d49fe33 Implement `CompressedPublicKey`
P2WPKH requires keys to be compressed which introduces error handling
even in cases when it's statically known that a key is compressed. To
avoid it, this change introduces `CompressedPublicKey` which is similar
to `PublicKey` except it's statically known to be compressed.

This also changes relevant code to use `CompressedPublicKey` instead of
`PublicKey`.
2023-12-12 15:16:16 +01:00
Jiri Jakes daa47b2061
Allow `SignedAmount` parse values equal to i64::MIN
Previously, parsing such textual value returned 'too big' error. This
change fixes it and adds relevant tests.
2023-12-12 18:33:44 +08:00
Tobin C. Harding f06d12455f
bitcoin: Remove the custom sink
We have a sink in the new `io` crate, use that one and remove the one in
`bitcoin::prelude`.
2023-12-12 11:48:29 +11:00
Tobin C. Harding b503aa1544
Run the formatter
Run `cargo +nightly fmt`, no manual changes. Done separately to make
review of the last patch easier.
2023-12-12 11:48:29 +11:00
Tobin C. Harding 3ca55fb163
Remove qualifying path from Read and Write
There is no advantage in having `io::Read` as opposed to `Read` and
importing the trait. It is surprising that we do so.

Remove `io::` path from `io::Read` and `io::Write`. Some docs keep the
path, leave them as is. Add import `use io::{Read, Write}`.

Refactor only, no logic changes.
2023-12-12 11:48:29 +11:00
Tobin C. Harding ebeb21fa7a
Import fmt::Write using underscore
When we use the `fmt::Write` trait it is just to call its methods, we
can therefore, without any change to the logic, use `as _` when
importing the trait. This prevents naming conflicts.

Done in preparation for importing the `io::Write` trait.
2023-12-12 11:48:29 +11:00
Tobin C. Harding e2dbcb1d28
Use W for writer generic type
Generic types can be single letters, and a writer is conventionally, in
this codebase at least, called `W`.

Use `W` instead of `Write` with no loss of clarity.
2023-12-12 11:48:29 +11:00
Tobin C. Harding 8704d9f0ae
docs: Fix grammar 2023-12-12 11:48:29 +11:00
Andrew Poelstra 6fe073b324
Merge rust-bitcoin/rust-bitcoin#2279: Remove ToOwned from prelude
ae07bdbdbc Remove ToOwned from prelude (Tobin C. Harding)

Pull request description:

  We are not using the `ToOwned` trait, remove it.

  Found by clippy.

ACKs for top commit:
  apoelstra:
    ACK ae07bdbdbc

Tree-SHA512: 8d7d271a279027bd449a2c23c5a5df2217d456c7ca2f286bbe57934f776bb10cb882ceabb52cdd41d5d622f864eefd2bcbb49b68dcfa27203039fd62edcd9d73
2023-12-12 00:16:05 +00:00
Tobin C. Harding ae07bdbdbc
Remove ToOwned from prelude
We are not using the `ToOwned` trait, remove it.

Found by clippy.
2023-12-12 08:55:03 +11:00
Andrew Poelstra ada8c53ce2
Merge rust-bitcoin/rust-bitcoin#2272: hashes: Add Hash::from_bytes_iter to construct hashes from iterators
94a6caf204 hashes: Add Hash::from_byte_chunks to construct hashes from iterators (Steven Roose)

Pull request description:

  Is there any interest in a method like this? I'm not necessarily a fan myself, was just in a situation where I was doing this a lot and it would save the me the "engine, from_engine dance" each time.

ACKs for top commit:
  Kixunil:
    ACK 94a6caf204
  apoelstra:
    ACK 94a6caf204

Tree-SHA512: 96e74366dbf64d50fb6642024d18eeeee5b78154fa152c845a1073c904599af69328a141f0a7e2bd1a7b43a091c886da57dfe6e87bab5a5e01b0f167019caae0
2023-12-11 19:51:05 +00:00
Andrew Poelstra 199c482b26
Merge rust-bitcoin/rust-bitcoin#1832: Remove Network from AddressInner
1ee989a3af Remove private fmt_internal function (Tobin C. Harding)
923ce7402d Remove Network from AddressInner (Tobin C. Harding)
3490433618 Return error from wpubkey_hash (Tobin C. Harding)
f7ab253ce4 Remove stale comment (Tobin C. Harding)

Pull request description:

  An `AddressInner` struct (contains `Network` field) is created when parsing address strings however address strings do not map 1:1 to `Network` because signet and testnet use the same bech32 prefix "tb".

  We can fix this by inlining the `Payload` variants into `AddressInner` and adding prefix enums for legacy addresses and an `Hrp` for bech32 addresses.

  Fix: #1819

ACKs for top commit:
  Kixunil:
    ACK 1ee989a3af
  apoelstra:
    ACK 1ee989a3af

Tree-SHA512: 1c2749dc929a1e9ad9b9feb01bec5c96b5aec07c6d646d88652deca7abe485907403116e9e29a0ab7dc06223254c4b49a384043284ec0a68fd76f9ab551e9e8a
2023-12-11 18:01:47 +00:00
Andrew Poelstra 4777ec9a90
Merge rust-bitcoin/rust-bitcoin#1225: Add `bitcoin-units` crate
396e049a7a Use InputString instead of String (Tobin C. Harding)
acacf45edf Add ParseDenominationError (Tobin C. Harding)
69e56a64ed Add bitcoin-units crate (Tobin C. Harding)
4ecb1fe7da internals: Add docs to InputString (Tobin C. Harding)
fa8d3002cd internals: Fix docs typo (Tobin C. Harding)

Pull request description:

  Create a new  `bitcoin-units` crate as described [here](https://github.com/rust-bitcoin/rust-bitcoin/issues/550#issuecomment-1012103022).

  Only the `amount` module is currently included.

  I've resolved the `Encodale/Decodable` issue by keeping the `amount` module in `bitcoin`.

ACKs for top commit:
  Kixunil:
    ACK 396e049a7a
  apoelstra:
    ACK 396e049a7a

Tree-SHA512: caf5e9da0458435ab19d00d4506896257e898525a4472d435fdac1d1a37bb747befd56993b106673f938475e5777d952a13ba04a2d3cb710d7afe7f5faebb7b8
2023-12-11 17:54:30 +00:00
Andrew Poelstra e0886e6a5f
Merge rust-bitcoin/rust-bitcoin#2263: `TaprootMerkleBranch` improvements
e1cc98986c Put `#[inline]` on trivial functions (Martin Habovstiak)
e531fa612b Move `TaprootMerkleBranch` and impl `IntoIterator` (Martin Habovstiak)
9d23c1d0a8 Implement std traits for `TaprootMerkleBranch` (Martin Habovstiak)
93b415589d Rename `inner` to `slice`/`vec` (Martin Habovstiak)
bb0f839c2f Lint with nightly (Martin Habovstiak)

Pull request description:

  This contains several improvements to `TaprootMerkleBranch` that make the API more idiomatic.

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

Tree-SHA512: b2bf52b027e7c1f8588c54e8b8d7a5fa54011dc521bd917995011d5fcc16c50a486eb89c0cdae2557a58adbe7708a4f2bc8f4c492e3d88c679f2abf85b1e7c83
2023-12-11 14:46:31 +00:00
Andrew Poelstra c53402790e
Merge rust-bitcoin/rust-bitcoin#2255: Fix: TxOut::minimal_non_dust and Script::dust_value
1b23220d10 Fix: TxOut::minimal_non_dust and Script::dust_value (Jonathan Underwood)

Pull request description:

  Fixes #2192

  TxOut::minimal_non_dust has 3 problems.

  1. There is an invisible dependency on Bitcoin Core's default minrelaytxfee value. It has been made explicit.
  2. There is an off by one error. The dust limit comparison uses < and therefore `+ 1` was not needed. It has been fixed.
  3. It was not returning 0 amount for OP_RETURN outputs.

  Script::dust_value has 2 problems.

  1. The dust amount depends on minrelaytxfee which is configurable in Bitcoin Core. This method was not configurable.
  2. The division operation was done before multiplying the byte amount, which can cause small differences when using uncommon scripts and minrelaytxfee values.

ACKs for top commit:
  Kixunil:
    ACK 1b23220d10
  apoelstra:
    ACK 1b23220d10

Tree-SHA512: eafd5112fbf773d86e094e3a69c519dd32f5074f5c9c63a8d69b1c9796579a8f2c2d11ad0995d8252c25b7fed5cd7c968ab88a70588986981a0a63649d43e197
2023-12-11 13:24:16 +00:00
Steven Roose 94a6caf204
hashes: Add Hash::from_byte_chunks to construct hashes from iterators 2023-12-11 08:41:12 +00:00
Tobin C. Harding 396e049a7a
Use InputString instead of String
Done so that we can correctly support builds without an allocator.

Add two new error types that wrap `InputString`.
2023-12-11 08:53:13 +11:00
Tobin C. Harding acacf45edf
Add ParseDenominationError
We have two variants in the `ParseAmountError` that both come from
parsing a denomination, these should be a separate error.
2023-12-11 08:53:11 +11:00
Tobin C. Harding 69e56a64ed
Add bitcoin-units crate
Add a new crate `bitcoin-units`, move the `amount` module over to it and
re-export all types from `bitcoin::amount` so this as not a breaking
change.
2023-12-11 08:52:31 +11:00