Commit Graph

5518 Commits

Author SHA1 Message Date
Tobin C. Harding ffdd63fa8e
units: test for C-SEND-SYNC
Done as part of the Rust API guidelines checklist.

Add a unit test for `Send` and one for `Sync`.
2024-12-09 10:54:07 +11:00
Update Nightly Rustc Bot d3d20d3fb2 Automated update to Github CI to rustc nightly-2024-12-06 2024-12-07 01:48:31 +00:00
Update cargo-semver-checks Bot 78f61f55de Automated update to Github CI to cargo-semver-checks version-0.37.0 2024-12-07 01:10:28 +00:00
yancy ac74ed2144 Range check against SignedAmount::MAX instead of i64::MAX
Future proof this check by using SignedAmount::MAX in the case where the
MAX SignedAmount changes to something other then i64::MAX.
2024-12-06 09:20:12 -06:00
Tobin C. Harding 7e0501c03c
Add a script to query the API
Add a simple script that allows one to query the current API. Done by
parsing the API text files and grepping for things.

This is useful as a dev tool as we try to stabalize the leaf crates.
2024-12-06 15:42:28 +11:00
Tobin C. Harding e126a24307
Add API script
Add a script to generate API files using `cargo public-api` for the
crates that we are trying to stabalise (the so called 'leaf crates').

- hashes
- io
- primitives
- units

We already ran the script and committed the files last patch. The fact
that this patch does not include any changes to the `api/` directory and
that CI passes is enough to convince us that last patch was valid.

Add a CI job that runs the script and checks there are no changes to
the committed text files thereby proving no API changes are made in a
PR without explicitly modifying the API text files.

Add documentation to `CONTRIBUTING.md` on what is expected of devs.
2024-12-06 15:42:22 +11:00
Tobin C. Harding 219ecd5498
Add api text files
We are about to introduce a script that generates text files for the
public API surface of various crates.

Run the soon-to-be-introduced script and commit the changes. Covers:

- `hashes`
- `io`
- `primitives`
- `units`

The script and CI setup will be done in the next patch, this is just to
make review easier.
2024-12-06 15:20:52 +11:00
merge-script dde5f47ce4
Merge rust-bitcoin/rust-bitcoin#3630: Release tracking PR: `bitcoin 0.33.0-alpha.0`
edab380ac0 bitcoin: Bump version to v0.33.0-alpha.0 (Tobin C. Harding)

Pull request description:

  Needs release notes but there are 20 pages of them, that feels like too many to go through manually.

ACKs for top commit:
  apoelstra:
    ACK edab380ac096babf3d12f27d373d0900d10bc065; successfully ran local tests

Tree-SHA512: 318fc9a6a8a2142b2f5e11881dfa60748c51c693325503b35e0197ac18b2c2ebb37bad71846fea2dfe64f93c67aba018447ed4a3eb9beb481c094fc03ff271a2
2024-12-05 21:59:44 +00:00
Jamil Lambert, PhD 6950c0a7b5
Change `Amount::MAX` to equal `MAX_MONEY`
To prevent rounding errors converting to and from f64 change
`Amount::MAX` to `MAX_MONEY` which is below the limit in f64 that has
issues.

Add checks to `from_str_in`, `checked_add` and `checked_mul` that the
result is below MAX, where previously a u64 overflow was relied on.

Change tests to account for new lower MAX that is within the range of
SignedAmount and does not overflow so easily

Remove overflow tests

`Amount::MAX` is now below `u64::MAX` and within the range of values for
`SignedAmount`.   These tests therefore do not overflow.
In effective_value there is no error with `Amount::MAX` and the correct
value is returned.
In psbt the removed test is effectively the same as the previous test.

Modify `Amount` tests to work with new `MAX`

Tests need to be changed that checked values above the new `MAX` or
`Amount::MAX` was out of range for `SignedAmount` which it isn't anymore
2024-12-04 14:17:00 +00:00
Tobin C. Harding edab380ac0
bitcoin: Bump version to v0.33.0-alpha.0
Needs release notes but there are 20 pages of them, that feels like too
many to go through manually.

Includes a missing changelog entry in `units` for an already released
change that is included in this `bitcoin` release.
2024-12-04 15:58:36 +11:00
Tobin C. Harding c27f443520
Add basic unit tests for Amount serde
Add a test each for serializing `Amount` as sat, as BTC, and as str.
2024-12-03 08:43:35 +11:00
Tobin C. Harding 22530f6a2b
Support serde serializing Amount as string
Sometimes JSON parsers may munge floats. Instead of using `f64` we can
serialize BTC amounts as strings.

Includes addition of `alloc` feature gate to `DisplayFullError` to
remove lint warnings when building with `--no-default-features`.

Close: #894
2024-12-03 08:42:41 +11:00
merge-script aa25adfc64
Merge rust-bitcoin/rust-bitcoin#3687: Automated daily update to rustc (to nightly-2024-12-01)
75297a68f6 Automated update to Github CI to rustc nightly-2024-12-01 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 75297a68f6

Tree-SHA512: 8a36d0f3e660195a1ba6811994b0df70962c4dd31eafe0ad125966883c63f09f18b1d073516e136677b72d17f54487670ed1745fd68e17b38b554f72d315e4a3
2024-12-02 14:10:30 +00:00
merge-script 37c5818297
Merge rust-bitcoin/rust-bitcoin#3689: Fix typo in re-export
8b41ecb427 Fix typo in re-export (Shing Him Ng)

Pull request description:

  Fix typo in re-export

ACKs for top commit:
  apoelstra:
    ACK 8b41ecb4270585652259277e7f132c8fbdcae953; successfully ran local tests
  tcharding:
    ACK 8b41ecb427

Tree-SHA512: 72de9268a509647d4ad4de931478582198071e5e26e5cb44beeca341e80b1fe380d45721ba8d8e871ae828c1e3740cb23dbc6fc635078fb39f909c625364e710
2024-12-02 13:28:04 +00:00
Shing Him Ng 8b41ecb427 Fix typo in re-export 2024-12-01 21:32:43 -06:00
merge-script 58b087d946
Merge rust-bitcoin/rust-bitcoin#3674: Close `amounts` error types
fd2a5c1ec7 Close amounts error types (Tobin C. Harding)
23c77275b1 Reduce code comment lines (Tobin C. Harding)
d595f421c6 Remove whitespace between enum variants (Tobin C. Harding)

Pull request description:

  Close the two pubic enum error types in `units::amounts`. All the other structs are closed already because they either have private fields or marked `non_exhaustive`.

ACKs for top commit:
  apoelstra:
    ACK fd2a5c1ec79f337fb3695c030c9fb6b4671468f2; successfully ran local tests; thanks!

Tree-SHA512: f8d68ef821449e0829c926cf527df4b226b29c8d1d41b320a016fbf70b4b39cc54c8c218955caa0c3776158eeeae0ebacc1cc89dab67bafc399b94063324ab0e
2024-12-02 03:04:07 +00:00
merge-script 7ba24e9f4d
Merge rust-bitcoin/rust-bitcoin#3686: Run nightly update bot once a week
01ec48cfb8 Re-name cron nightly update jobs (Tobin C. Harding)
f428833bdd Only update nightly once a week (Tobin C. Harding)

Pull request description:

  Merging the nightly update PRs is boring and annoying. We can just do it once a week without too much risk of falling behind.

  This does mean that I (Tobin) can't be lazy and skip merging the bot's PRs (which I find myself doing when its twice a week).

ACKs for top commit:
  apoelstra:
    ACK 01ec48cfb83389759c1c83ec85d008533ddef74d; successfully ran local tests

Tree-SHA512: 72bd138399cc742cba89912fd576bf8b8ef23db123c197278f9910f6ce9470607b37e26ceb690e7140faa3493ad7e370c157285ffb2adfc1321b0dc0e0f9f9c9
2024-12-02 02:28:21 +00:00
Update Nightly Rustc Bot 75297a68f6 Automated update to Github CI to rustc nightly-2024-12-01 2024-12-02 01:59:35 +00:00
merge-script 8acf3ec30a
Merge rust-bitcoin/rust-bitcoin#3684: refactor: remove unnecessary if block
b5a0731a23 refactor: remove unnecessary if block (Chris Hyunhum Cho)

Pull request description:

  This `if...else` block can be replaced with one `if` block, by changing `==` to `!=`.

ACKs for top commit:
  jamillambert:
    ACK b5a0731a23
  apoelstra:
    ACK b5a0731a23f945f7e4cc7d8f3c0f1d3f83875272; successfully ran local tests
  tcharding:
    ACK b5a0731a23

Tree-SHA512: eee0d63532953d27fe081c36180ae9adb63c0ab7f1fb8324d9fc5e4a408f421d8df894efcccfc4bd3142625d6be6ea1258c9478faa025ce147ebe1b4e9377738
2024-12-01 23:25:32 +00:00
Tobin C. Harding 01ec48cfb8
Re-name cron nightly update jobs
We just changed the cron nightly update job to be once a week instead of
twice - re-name the file appropriately.
2024-12-02 09:47:11 +11:00
Tobin C. Harding f428833bdd
Only update nightly once a week
Merging the nightly update PRs is boring and annoying. We can just do it
once a week without too much risk of falling behind.

This does mean that I (Tobin) can't be lazy and skip merging the bot's
PRs (which I find myself doing when its twice a week).
2024-12-02 09:44:35 +11:00
merge-script fe956ccb4e
Merge rust-bitcoin/rust-bitcoin#3683: Automated weekly update to rustc stable (to 1.83.0)
a1260b06ed Automated update to Github CI to rustc stable-1.83.0 (Update Stable Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `semver-checks.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK a1260b06ed

Tree-SHA512: 1f8cdfe3336109608afd786430c8f37544ba866405c63c6032f214fcb8f15815eef785748188efbe9436e010496701b7f4a831602843cf94c73afcbf16b98b83
2024-12-02 09:30:02 +11:00
Tobin C. Harding fd2a5c1ec7
Close amounts error types
Close the two pubic enum error types in `units::amounts`. All the other
structs are closed already because they either have private fields or
marked `non_exhaustive`.
2024-12-02 09:14:14 +11:00
Tobin C. Harding 23c77275b1
Reduce code comment lines
Make the comment more terse by using 'info' instead of 'information' and
reduce the line count by 2.
2024-12-02 09:14:06 +11:00
merge-script a4ad864370
Merge rust-bitcoin/rust-bitcoin#3685: Automated nightly rustfmt (2024-12-01)
0990b30035 2024-12-01 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:
  apoelstra:
    ACK 0990b30035a01e6e75aa5e82412d79bd1eb9e267; successfully ran local tests

Tree-SHA512: 56e2f0de98868d4ce958764924a6a0f7c245ffa8c7898638b7d316b5b56d4fd2c9f5e01fe5e3da5ebcec44d135d44fdf99be5d912a7b1dbd93da8a6b1d82b14d
2024-12-01 03:42:09 +00:00
Fmt Bot 0990b30035 2024-12-01 automated rustfmt nightly 2024-12-01 01:41:12 +00:00
merge-script 230b9e5ca0
Merge rust-bitcoin/rust-bitcoin#3681: hashes: Documents C-QUESTION-MARK
91268bba67 Examples use ?, not try!, not unwrap (Jamil Lambert, PhD)

Pull request description:

  To conform to Rust API guidelines in Issue #3633 examples should use ?, not try!, not unwrap (C-QUESTION-MARK).

  The examples were originally labelled `## Commonly used operations`, change the label to `# Examples`.
  Replace `unwrap()` with `expect()` since these cases cannot error.

  Two uses of `unwrap()` have been left since they are in a set of three writes with an engine that can not error and the first case uses `expect()` with the relevant error message.

ACKs for top commit:
  tcharding:
    ACK 91268bba67
  sanket1729:
    ACK 91268bba67
  apoelstra:
    ACK 91268bba672d7dea9e29cccfa83f3b34df27fe91; successfully ran local tests

Tree-SHA512: 4c7836b2e8d67ac5d6f85229ca9ad3c9c5f0f1dc7062bda398c48ef72fd6bb965effee313151f70c86bd7cebda78a651cc12b2d59bc331d689089cf17b8c3dc8
2024-11-29 17:20:48 +00:00
merge-script 85d1eb8289
Merge rust-bitcoin/rust-bitcoin#3677: units: Implement `iter::Sum` for all types that implement `ops::Add`
433f70939c Implement iter::Sum for BlockInterval (Tobin C. Harding)
0369e64b56 Implement Sum for an iterator of references to amounts (Tobin C. Harding)
31f883ac00 Implement iter::Sum for FeeRate (Tobin C. Harding)

Pull request description:

  Enables summing an iterator of values. Note that this does not include either `LockTime`s. `absolute::LockTime` should not be added and for `relative::LockTime` we have https://github.com/rust-bitcoin/rust-bitcoin/issues/3676

  Close: #1638

ACKs for top commit:
  apoelstra:
    ACK 433f70939c3ecc10702ab6502e3f9bcd94dab739; successfully ran local tests; nice!
  sanket1729:
    utACK 433f70939c

Tree-SHA512: 1eda00f3bbbc61f795198ce8525a5a9b690478a8abc268da6d2e40de7d91decc28dd8211df0c6abeaf30148c7ec3907b85e3c5351972c354590569840e84d562
2024-11-29 13:28:30 +00:00
Chris Hyunhum Cho b5a0731a23 refactor: remove unnecessary if block 2024-11-29 08:06:51 +00:00
merge-script 7d8b9bd883
Merge rust-bitcoin/rust-bitcoin#3673: units: Close the hex parse errors
22769268f3 units: Close the hex parse errors (Tobin C. Harding)

Pull request description:

  As part of the 1.0 effort close the errors in the `units::parse` module.

ACKs for top commit:
  apoelstra:
    ACK 22769268f34b45c0bd86c548eb13cfe1e290f0d7; successfully ran local tests; thanks!
  sanket1729:
    ACK 22769268f3

Tree-SHA512: 598ba236f8c08c3f750112e0d8b8e0aa0568be2700a328e4a2d8999ca59eada8a16a6a1d9e9121e7f42ce9bbe3da3f87221ba67c36056996a687e489f4c6007c
2024-11-29 03:41:48 +00:00
merge-script 031b402b26
Merge rust-bitcoin/rust-bitcoin#3678: Remove unused extern statement
667b7f1010 Remove unused extern statement (yancy)

Pull request description:

  `extern crate` keywords are no longer needed to import a crate as of Rust 2018

ACKs for top commit:
  tcharding:
    ACK 667b7f1010
  apoelstra:
    ACK 667b7f1010bc0745d3e39181e15ec795aeca68dc; successfully ran local tests
  sanket1729:
    ACK 667b7f1010

Tree-SHA512: d157aa881dfce12b65bb676425cb5f17fa5a193d0001f37c26f74cab1254ab08fdcc9b7462b9a74210f85028299af9e14c0071ba390642b59bb7e986ba85933d
2024-11-29 03:01:13 +00:00
Update Stable Rustc Bot a1260b06ed Automated update to Github CI to rustc stable-1.83.0 2024-11-29 00:59:16 +00:00
merge-script d1276b6e3b
Merge rust-bitcoin/rust-bitcoin#3671: Automated daily update to rustc (to nightly-2024-11-27)
987e31a188 Automated update to Github CI to rustc nightly-2024-11-27 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 987e31a188

Tree-SHA512: d0ef5b7796178aed1e7b59ac2b85e7ecbb8640b8f30847c6cd3d14f3a0ec4291a668ecd2ba213b6a756ed4324aaaf82c54268f81eb53fc4a153ebd7edee6e00e
2024-11-29 10:58:45 +11:00
merge-script 99bf3f74b9
Merge rust-bitcoin/rust-bitcoin#3680: units: Test C-COMMON-TRAITS
c49f40fd9a units: Test C-COMMON-TRAITS (Tobin C. Harding)

Pull request description:

  Add structs to the `api` integration test file that verify the set of common traits.

ACKs for top commit:
  apoelstra:
    ACK c49f40fd9af1b9446a7c9a35aefdc02b30801275; successfully ran local tests; good idea!

Tree-SHA512: bc60ed8912e705d4c07714e9d19c0eee4fb2eb6be17a6ee67c2bb922ea27ef3a737eda3f7de690fa3a9fa364c34029989f20361d03f706fd3152ec4f20f33aab
2024-11-28 23:27:42 +00:00
merge-script 31bf3f1931
Merge rust-bitcoin/rust-bitcoin#3659: Add string regression tests in leaf crates
7e17eaf21c units: Add stringy regression tests (Tobin C. Harding)

Pull request description:

  Add regression tests for `Display` and `FromStr` impls. Exclude error types and helper types (`amount::Display`).

  Done as part of #2498 and also as part of the 1.0'ing effort.

ACKs for top commit:
  apoelstra:
    ACK 7e17eaf21c479338d5161b493f02578ef4186e62; successfully ran local tests; nice

Tree-SHA512: 6484806777501fe38557987c9c39b377f972fd4406cf3cfd8ac36f8426041484caab45d4ccff87221dbc5c34507d1be6a7b23839367bd3010855c92fd898c835
2024-11-28 22:47:53 +00:00
Jamil Lambert, PhD 91268bba67
Examples use ?, not try!, not unwrap
To conform to Rust API guidelines examples should Examples use ?, not
try!, not unwrap (C-QUESTION-MARK).

Label the examples as `# Examples`.
Replace one `unwrap()` with `expect()` .  The others don't technically
conform to the guidelines but are warranted.
2024-11-28 22:20:57 +00:00
merge-script 1f731e9162
Merge rust-bitcoin/rust-bitcoin#3672: units: Remove serde from amounts
77085a1fa1 units: Remove serde from amounts (Tobin C. Harding)

Pull request description:

  The `Amount` and `SignedAmount` were not supposed to implement `serde` traits by design because doing so implicitly uses sats. We provide two modules `as_sat` and `as_btc` to allow users to explicitly serialize in their preferred format.

  In commit: `d57ec019d5 Use Amount type for TxOut value field` derives were added for `serde` and we did not notice it during review.

ACKs for top commit:
  apoelstra:
    ACK 77085a1fa1f39e7358202e49189282e48a965747; successfully ran local tests

Tree-SHA512: ff4c1f34191e12d955e66737493af4b2dad761fa6f95eb334b86715906e70d2180e7f15d8b4af302d53fb0b1c8b5fb50b4924e9fcdee8824840ba555e73c1c17
2024-11-28 16:32:23 +00:00
merge-script bcc54fb9d0
Merge rust-bitcoin/rust-bitcoin#3670: Remove duplicate test case
60f43a893d Remove duplicate test case (Tobin C. Harding)

Pull request description:

  In commit:

   `a10d5e15b3 Extract the Script assembly creator from fmt::Debug`

  A test case was refactored and where there used to be two test case, one for `Debug` and one for `Display`, two identical test cases were left.

  Remove duplicate test case.

ACKs for top commit:
  apoelstra:
    ACK 60f43a893d67c221f61e289cab6394418411cf55; successfully ran local tests

Tree-SHA512: 8d21f07b33c9f88ac820422b9f5471bf53e36050a31854a7152ab14c6e25654455f4eb366ea2b497a80f741af36bf068b1df8a69321a0299c9bae60f001b354e
2024-11-28 15:20:24 +00:00
merge-script 88da0674f2
Merge rust-bitcoin/rust-bitcoin#3642: Add p2wpkh address creation example
d9b48cc2ce Add p2wpkh address creation example (yancy)

Pull request description:

  Add example for creating p2wpkh address.  It would be helpful to add examples the other address types (p2tr etc) either in separate files or in one.  Note this should be created in the Address crate however that crate is currently empty.

ACKs for top commit:
  tcharding:
    ACK d9b48cc2ce
  apoelstra:
    ACK d9b48cc2ce68b065640caa22da6fbcb1f3ad85f8; successfully ran local tests

Tree-SHA512: b383c1aca2d3669f66f0dcaf858526793ffc9e62671cf4985c44a11f7717c8e02d359b4d7d8b5822ebdde27595612e10bc831c84a2c4b654f69d4137ad16ba2f
2024-11-28 13:27:47 +00:00
merge-script 4123f2c00f
Merge rust-bitcoin/rust-bitcoin#3663: Fix internal weight calculation
f961f3c0ec Add test (yancy)
3352032892 Fix internal weight calculation (yancy)

Pull request description:

  A fix for 261c8d8ae6.  Maybe it's better to roll back that commit instead.  Clearly there needs to be a test or two added here as well since this change causes not test failures.

ACKs for top commit:
  apoelstra:
    ACK f961f3c0eca4e9b175761756f48699012b63d70a; successfully ran local tests
  sanket1729:
    utACK f961f3c0ec
  tcharding:
    ACK f961f3c0ec

Tree-SHA512: e6bb6d492b6a85f328bdfae6d0e5df9ea48c9c06bd0c310816826c893163bd0a6071af893fa7012fbd4eea0394bc8997277151486807fb8bd06ac78ce8cfc5fd
2024-11-28 12:52:53 +00:00
Tobin C. Harding c49f40fd9a
units: Test C-COMMON-TRAITS
Add structs to the `api` integration test file that verify the set of
common traits.
2024-11-28 16:59:00 +11:00
yancy 667b7f1010 Remove unused extern statement
extern crate keywords are no longer needed to import a crate
2024-11-27 23:06:55 -06:00
Tobin C. Harding 433f70939c
Implement iter::Sum for BlockInterval
We support adding two intervals; no obvious reason not to support
summing an iterator of intervals.
2024-11-28 15:56:07 +11:00
Tobin C. Harding 0369e64b56
Implement Sum for an iterator of references to amounts
We have `iter::Sum` already for `Amount` and `SignedAmount`. Add
an implementation for each to support iterators that yield references.
2024-11-28 15:51:29 +11:00
Tobin C. Harding 31f883ac00
Implement iter::Sum for FeeRate
The `FeeRate` implements `ops::Add`, no reason not to enable summing an
iterator of fee rates.
2024-11-28 15:49:01 +11:00
merge-script f95d877d56
Merge rust-bitcoin/rust-bitcoin#3660: Update `from_next_work_required` to take an i64 for timespan
4d0d78a3af Fix typo in from_next_work_required documentation (Shing Him Ng)
5e47c4123d Update CompactTarget::from_next_work_required to take timespan as i64 (Shing Him Ng)

Pull request description:

  [In Core](f7144b24be/src/pow.cpp (L56)), the timespan is defined as a signed int64. This PR will update `from_next_work_required` to take in an `i64` instead of a `u64`

  Fixes #3652

ACKs for top commit:
  tcharding:
    ACK 4d0d78a3af
  apoelstra:
    ACK 4d0d78a3af2ca300c6b40348724e806bd51ef27a; successfully ran local tests

Tree-SHA512: eea33ec18b081a97ae2a22c681982ad8693200ff8de3a3fc8f46b84b5e72f41589b79140ddd79ba3fce628f1539baf8387422bcc2c6b409fcadc4c2043aa2901
2024-11-28 03:17:08 +00:00
Tobin C. Harding d595f421c6
Remove whitespace between enum variants
We don't tend to put whitespace between enum variants.
2024-11-28 13:45:01 +11:00
Tobin C. Harding 22769268f3
units: Close the hex parse errors
As part of the 1.0 effort close the errors in the `units::parse` module.
2024-11-28 13:36:09 +11:00
Tobin C. Harding 77085a1fa1
units: Remove serde from amounts
The `Amount` and `SignedAmount` were not supposed to implement `serde`
traits by design because doing so implicitly uses sats. We provide two
modules `as_sat` and `as_btc` to allow users to explicitly serialize in
their preferred format.

In commit: `d57ec019d5 Use Amount type for TxOut value field` derives
were added for `serde` and we did not notice it during review.
2024-11-28 12:55:43 +11:00
Update Nightly Rustc Bot 987e31a188 Automated update to Github CI to rustc nightly-2024-11-27 2024-11-28 01:55:33 +00:00