Commit Graph

36 Commits

Author SHA1 Message Date
Tobin C. Harding d557caf552
Run the formatter 2025-05-08 10:16:56 +10:00
Tobin C. Harding 7c2115b68f
Rename MtpInterval to NumberOf512Seconds
Name the type exactly what it is. This used to be `Time`, then we tried
`MtpInterval`.

Note that this makes some of the original function names overly verbose
e.g., `NumberOf512seconds::from_512_second_intervals()` but given the
curlyness of locktimes too verbose is better than too terse. Also this
type, along with `NumberOfBlocks` is not going to be in very wide use so
the ergonomic hit is worth the additional clarity.
2025-05-08 10:12:23 +10:00
Tobin C. Harding 3a97ea2259
Rename HeightInterval to NumberOfBlocks
Name this type exactly what it is. Note for the error we just use
'height' even though this is a bit stale but the general concept is ok
in the error type because the name is long already.
2025-05-08 10:12:22 +10:00
Andrew Poelstra 826acb8273
units: rename relative::HeightInterval constructors
Rename `value` to `to_height` to be symmetric with `from_height`;
deprecate `to_consensus_u32` which had no symmetric `from_consensus_u32`
and was only used to implement the corresponding methods in primitives
and bitcoin.
2025-05-03 03:12:08 +00:00
Andrew Poelstra 39b4f7670d
units: rename relative::Height to HeightInterval
This is disruptive, but makes the type name consistent with
`MtpInterval` and also greatly improves clarity, helping to distinguish
between absolute and relative locktimes and reminding the author (and
reviewer) of locktime code that this needs to be a diff.
2025-05-03 03:12:08 +00:00
Andrew Poelstra d3619cc1bc
units: deprecate relative::MtpInterval::to_consensus_u32
This method is weird. It's basically just used internally to implement
the locktime methods in `primitives` and `bitcoin`. It has no symmetric
from_consensus_u32.

Conversely the constructors from 512-second intervals have no symmetric
to_* method -- the inverse of these functions is called `value`, which
is a meaningless and undiscoverable name.
2025-05-03 03:12:07 +00:00
Andrew Poelstra 1a6b8b4c7a
units: rename relative::Time to MtpInterval
The name `Time` is misleading. In fact this represents an interval
between MTPs.
2025-05-03 03:12:07 +00:00
Jamil Lambert, PhD 82da8a599e
Add regression tests for Display impl
The output of `Display` should not change in stable crates for types
that have well defined formatting and ones that implement `FromStr`.
Error types do not need to be tested.

Add missing tests for all implementations in `primitives` and round
trips for types that implement `FromStr`.
2025-04-30 16:14:05 +01:00
Jamil Lambert c4d9c1b9f8
Use a consistent rustdoc heading level of H1 `#`
There was and inconsistent usage of `#`, `##` and `###` in rustdoc
headings.  The difference in the rendered rustdocs is a minimal font
size change.

Change all headings to be H1 `#`.

Change all subheadings to be `###` to have a noticeable difference in
font size in the rendered docs.
2025-04-22 13:06:32 +01:00
Tobin C. Harding df500e9b71
primitives: Enable pedantic lints
Enable all the pedantic lints and fix warnings.

Notable items:

- `enum_glob_used` import types with a single character alias
- `doc_markdown`: add a whitelist that includes SegWit and OpenSSL
2025-03-06 10:58:17 +11:00
Jamil Lambert, PhD b656d7a16c
Inline small functions
Functions that just delegate or do trivial operations should be inline.

Add `#[inline]` to all functions in `primitives` that fit the criteria.
2025-03-03 12:26:52 +00:00
Jamil Lambert, PhD 963dba2bdf
Test sequence formatting
Add a test to kill the mutants in Sequence formatting.
2025-02-07 17:50:45 +00:00
Jamil Lambert, PhD 6c3d7f6443
Test Sequence properties
Cargo mutants found multiple mutants in the functions that return true
or false for various Sequence properties.

Add a test to kill the mutants.
2025-02-07 17:48:17 +00:00
Tobin C. Harding adaf4ac086
Set avoid-breaking-exported-api to false
These lints are valuable, lets get at em.

Changes are API breaking but because the changes make functions consume
self for types that are `Copy` downstream should not notice the breaks.
2024-12-11 10:11:50 +11:00
Tobin C. Harding 6ae35be0db
primitives: Reduce alloc requirements
Recently we reduced the `alloc` requirements in `units` but we did not
propagate these changes up to `primitives`.

Remove a bunch of `alloc` feature gating from `primitives`.
2024-12-09 13:57:26 +11:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
Tobin C. Harding 32bc68d4dc
primitives: Add rustdoc links back in
During move of code to `primitives` we removed a few links to types that
were not yet moved, we can now put these back in.

Feature all rustdoc imports on `alloc` and `doc`.

Close: #2997
2024-11-02 08:26:39 +11:00
Tobin C. Harding bafe11d7e4
Correctly feature gate impl_to_hex_from_lower_hex
Currently we feature gate code within the `impl_to_hex_from_lower_hex`
 macro on "alloc" but `bitcoin` does not have the "alloc" feature so
 this code is never built in. This can be seen by the lack of a
 `to_hex` function on `LeafVersion`.

Remove the feature gate from the macro and put it on the individual
call sites as needed.
2024-10-31 13:43:47 +11:00
Tobin C. Harding 57769f5f28
Fix ugly rustfmt
Fix some ugly formatting introduced by the fmt bot recently.

Whitespace only, no logic changes.
2024-10-31 13:38:27 +11:00
merge-script 7e5911923f
Merge rust-bitcoin/rust-bitcoin#3284: Add a few unit tests for Sequence
4a8e2c3704 Add tests for sequence (Shing Him Ng)

Pull request description:

  Add a few unit tests for Sequence

ACKs for top commit:
  apoelstra:
    ACK 4a8e2c3704 successfully ran local tests; sure
  tcharding:
    ACK 4a8e2c3704

Tree-SHA512: fb793a6a94a9d3f1522357f98a73a87618ba70776875b3ce051631970ca6c15998401dece47e426f7040770b8d24ee1b72f206d3164b7ca76492e12e86116677
2024-10-21 23:58:55 +00:00
Jamil Lambert, PhD 88b53a471e
Unify deprecated note field format
All the deprecated note fields have been changed to be lower case and in
the format "use `a` instead".
2024-10-15 15:16:01 +01:00
Shing Him Ng 4a8e2c3704 Add tests for sequence 2024-10-14 22:41:23 -05:00
ChrisCho-H 3565f70df9 feat: replace ENABLE_RBF_NO_LOCKTIME with ENABLE_LOCKTIME_AND_RBF 2024-10-12 12:42:43 +09:00
Tobin C. Harding 5e0a07e74f
Use new Sequence::ENABLE_RBF_AND_LOCKTIME
We just renamed this and forgot to use the new name. This should have
been caught by CI.
2024-10-11 11:46:34 +11:00
ChrisCho-H 4499b5c95b feat: rename ENABLE_RBF_NO_LOCKTIME to ENABLE_LOCKTIME_AND_RBF 2024-10-05 18:39:26 +09:00
ChrisCho-H 861d97de36 feat: add FINAL constant to disable all 2024-10-03 22:51:49 +09:00
Fmt Bot a65d2a0ee4 2024-09-29 automated rustfmt nightly 2024-09-29 01:21:14 +00:00
yancy d39334e651 Refactor Arbitrary for Sequence 2024-09-27 11:26:33 -05:00
Shing Him Ng 9d9872711f Refine Sequence and Version Arbitrary impls 2024-09-26 14:31:29 -05:00
Fmt Bot 2009763ae5 2024-09-22 automated rustfmt nightly 2024-09-22 01:20:08 +00:00
Shing Him Ng 5b4e81b379 Implement Arbitrary for Transaction 2024-09-16 22:02:46 -05:00
Fmt Bot 9a5ba9b6df 2024-09-08 automated rustfmt nightly 2024-09-08 01:17:12 +00:00
Shing Him Ng 30bb93c676 Implement impl_to_hex_from_lower_hex macro for types that implement fmt::LowerHex 2024-08-31 22:41:40 -05:00
Martin Habovstiak c72069e921 Bump MSRV to 1.63
The version 1.63 satisfies our requirements for MSRV and provides
significant benefits so this commit bumps it. This commit also starts
using some advantages of the new MSRV, namely namespaced features, weak
dependencies and the ability to use trait bounds in `const` context.

This however does not yet migrade the `rand-std` feature because that
requires a release of `secp256k1` with the same kind of change - bumping
MSRV to 1.63 and removing `rand-std` in favor of weak dependency.
2024-07-27 07:24:32 +02:00
Tobin C. Harding 64c31cfb97
Move locktimes and Sequence to primitives
The `absolute` and `relative` locktimes as well as the `Sequence` are
all primitive bitcoin types.

Move the `Sequence`, and `locktime` stuff over to `primitives`.

There is nothing surprising here, the consensus encoding stuff stays in
`bitcoin` and we re-export everything from `blockdata`.
2024-07-15 08:53:51 +10:00