Commit Graph

355 Commits

Author SHA1 Message Date
Jamil Lambert, PhD a2bae3bb0b
Add test for impl Display for Script
Match arms in `impl fmt::Display for Script` were untested.

Add a regression test for the `OP_PUSHDATAx` match arms.
2025-07-02 13:01:21 +01:00
Jamil Lambert, PhD f3338655f1
Test OutPoint edge case to kill mutant
There is a mutant found in `FromStr for OutPoint`.

Add a test to check an edge case to kill the mutant.
2025-06-19 20:33:20 +01:00
Tobin C. Harding f6dea36e31
units: Make error constructor private
We typically do not want to have public constructors on error types.
Currently we do on the `TimeOverflowError` so that we can call it in
`primitives` but it turns out we can just use `NumberOf512Seconds`
constructors instead.
2025-06-19 13:13:37 +10:00
Jamil Lambert, PhD 8e60711265
Use the anonymous lifetime for paths
New clippy lint in rustc nightly "lifetime flowing from input to output
with different syntax can be confusing".

Apply the suggested fix and use the anonymous lifetime for paths.
2025-06-09 09:31:55 +01:00
yancy ebb9861c58 Add backticks around OPCodes
Item in documentation is missing backticks
2025-06-07 12:10:24 -05:00
merge-script c0d51ed9dc
Merge rust-bitcoin/rust-bitcoin#4591: chore: add missing backticks
3dd538d04b chore: add missing backticks (findmyhappy)

Pull request description:

  Add missing backtick in comment.

ACKs for top commit:
  tcharding:
    ACK 3dd538d04b
  apoelstra:
    ACK 3dd538d04bad6e07b04cd8c2b3fb14d09625389f; successfully ran local tests

Tree-SHA512: ae36752c1c097e3b72d59e6e77f45f0474c7703d0eb32f4df434b0a7bb1e037e4415cf385ef22e20f86ebb407d42bdd35b26fd7f7029a6210be29bc434231eb7
2025-06-05 15:49:42 +00:00
findmyhappy 3dd538d04b chore: add missing backticks
Signed-off-by: findmyhappy <findhappy@sohu.com>
2025-06-04 14:51:10 +08:00
Tobin C. Harding 4621d2bde1
Modify locktime serde implemenations
The `units::locktime` types are used for two things:

- They are the inner types of `primitives` `LockTime`s
- They are used ephemerally for checking satisfaction

Neither of these use cases requires `serde` impls for the `units` types.
Since we are trying to release 1.0 with minimal amounts of code we
should remove them.

For `LockTime`s that need to be stored on disk or go over the wire we
can manually implement the `serde` traits. For `absolute::LockTime` this
is done already and there is no reason the `relative::LockTime` impl
cannot be the same [0]. This differs from the current `serde` trait impls
but we have already decided that in 0.33 we are going to accept breakage
and direct users to use 0.32 to handle it.

- Remove `serde` stuff from `units::locktime`
- Manually implement `serde` traits on `relative::LockTime`
- Fix the regression test to use the new format

While we are at it use a uniform terse call in `serialize`.

[0] This is because there is an unambiguous encoding for the whole set
of locktimes - consensus encoding.
2025-06-01 14:07:33 +01:00
merge-script 6d8299e8b8
Merge rust-bitcoin/rust-bitcoin#4468: Improve lock times - fix off-by-one bug
4ccecf5dec Fix stale Height type link (Tobin C. Harding)
caebb1bf73 units: relative: Do minor rustdocs fixes (Tobin C. Harding)
40bb177bc2 Put is_satisfied_by functions together (Tobin C. Harding)
480a2cd62a Favour new function `from_mtp` over deprecated (Tobin C. Harding)
f9d6453d5b Shorten locktime type term (Tobin C. Harding)
727047bd39 Fix off-by-one-bug in absolute locktime (Tobin C. Harding)
3ffdc54ca5 Fix off-by-one bug in relative locktime (Tobin C. Harding)
a2ff8ddbbb Improve relative::LockTime is_satisfied_by_{height, time} (Tobin C. Harding)

Pull request description:

  Make the APIs uniform in relative and absolute locktimes in relation to the `is_satisfied_by` functions. In doing so improve the API and fix an off-by-one bug when checking satisfaction of locks by height.

  Done in three patches but maybe should be squashed? Probably easiest to review by looking at all the `is_satisfied_by*` functions and convincing yourself we got it right.

  EDIT: Now has 5 cleanup patches also (mostly docs cleanups).

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

Tree-SHA512: 9206cb464a06647510a35a7d564062823117e75df60251969be458616f4f5d04acf0aada53dbf7d493a2a2a72d26b3a300417a6499e45413d5f2a011538b7826
2025-05-31 15:48:29 +00:00
Tobin C. Harding e47836fb1e
Do not derive Default on CompactTarget
It is not immediately obvious what a zero value compact target is.
Because of this and the fact that we are trying to release minimal code
in `primitives 1.0` its best to remove the `Default` derive.

This is an API breaking change.
2025-05-27 08:09:56 +01:00
frankomosh 0a0e23fedf style: use Self:: instead of type aliases in error impls
Use  instead of 'use FooError as E' when pattern matching
on the same type in Display/Error trait implementations.
2025-05-22 20:28:33 +03:00
merge-script 3bf87d8bae
Merge rust-bitcoin/rust-bitcoin#4489: Fix link to BIP-113
c3102f04de Fix link to BIP-113 (Tobin C. Harding)

Pull request description:

  Current rustdocs link is not correct. Just remove the brackets because we have a fully labelled link right below.

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

Tree-SHA512: 71e41b3bd929fd8ed4e6aa790d73ba33132856dc1b3b7d36afde73f94c1953898814f851caf7004ba1a456d3af107513733a4df810c1b1ce74a3e332b156d97b
2025-05-14 00:10:34 +00:00
merge-script bc93498b3e
Merge rust-bitcoin/rust-bitcoin#4485: Add `Builder::with_capacity()`
d003d48592 Add `Builder::with_capacity()` (Daniel Roberts)
e492f94289 Update `ScriptBuf::with_capacity` docs (Daniel Roberts)

Pull request description:

  Enable the creation of `bitcoin::script::Builder` with a preallocated capacity.

  This is pretty minor, but it provides a small speedup if used correctly. I've observed a 0.4% speedup and a 0.7% speedup in two code bases that create lots of outputs (on the order of tens to hundreds of thousands). It provided a much larger speedup (5% or so) in the latter code base before some other optimizations dwarfed it.

  I have a branch that also uses it for `ScriptBufExt::new_*()` but while it provides a small performance improvement for all script types except one, `ScriptBufExt::new_p2tr()` actually causes a small performance regression. Since the only use case I have for creating lots and lots of scripts is in taproot with CHECKTEMPLATEVERIFY, I'm holding back that change if/until I figure out what's going on exactly (and hopefully resolve it).

ACKs for top commit:
  tcharding:
    ACK d003d48592
  apoelstra:
    ACK d003d4859251abb01929ccab6009a02e0c96b0cd; successfully ran local tests

Tree-SHA512: 51137574ca3d9dc5c319df124f470abd0f82413c093a5636af0439eb0fc2ad01dcf83df366a02279fc7d28feed24aa8c7db33b3c474d8bde7a9b6636343f8e9a
2025-05-13 17:16:54 +00:00
merge-script 9578ad3e50
Merge rust-bitcoin/rust-bitcoin#4469: Iterate on the script hex APIs
3b8164139f primitives: Add docs section for script hex API (Tobin C. Harding)
6b90e42e78 Finalize the script hex APIs (Tobin C. Harding)

Pull request description:

  In #4316 we made some 'improvements' to what script functions and trait implementations do and do not include the length prefix. Iterate again on it as described here: https://github.com/rust-bitcoin/rust-bitcoin/pull/4316#issuecomment-2847710436

  - Patch 1 does the changes
  - Patch 2 adds some more docs, requires a grammarian to check my Aussie lingua

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

Tree-SHA512: 481db88ae1b6f5751e81e4cd126f545cfc34bef6dcfcf857f1c7464aeb41f5de95fc4582c015abde04372fe025efa13cdf2906e75517f62cff3ddec05c4d9711
2025-05-12 11:13:50 +00:00
Tobin C. Harding 40bb177bc2
Put is_satisfied_by functions together
Move the `_by_{height,time}` functions to be underneath the
`is_satisfied_by` function.

Code move only, no logic change.
2025-05-12 12:35:01 +10:00
Tobin C. Harding 480a2cd62a
Favour new function `from_mtp` over deprecated
Use the new function and not the deprecated on in rustdcos and tests.
2025-05-12 12:32:37 +10:00
Tobin C. Harding f9d6453d5b
Shorten locktime type term
Use lock-by-time and lock-by-height instead of lock-by-blocktime and
lock-by-blockheight respectively with no loss of clarity.
2025-05-12 12:30:53 +10:00
Tobin C. Harding 727047bd39
Fix off-by-one-bug in absolute locktime
When checking a locktime against block height we add 1 because when the
next block is being validated that is what the height will be and
`is_satisfied_by` is defined to return true if a transaction with this
locktime can be included in the next block.

As we have in `relative`, and for the same reasons, add an API to the
absolute `Height` and `MedianTimePast`: `is_satisfied_by`. Also add
`is_satisfied_by_{height, time}` variants to `absolute::LockTime`.
Call through to the new functions in `units`.
2025-05-12 12:30:53 +10:00
Tobin C. Harding 3ffdc54ca5
Fix off-by-one bug in relative locktime
Define 'is satisfied by' - this is a classic off-by-one problem, if a
relative lock is satisfied does that mean it can go in this block or the
next? Its most useful if it means 'it can go in the next' and this is
how relative height and MTP are used in Core.

Ramifications:

- When checking a time based lock we check against the chain tip MTP,
then when Core verifies a block with the output in it it uses the
previous block (and this is still the chain tip).
- When checking a height base lock we check against chain tip height + 1
because Core checks against height of the block being verified.

Additionally we currently have a false negative in the satisfaction
functions when the `crate` type (height or MTP) is to big to fit in a
u16 - in this case we should return true not false because a value too
big definitely is > the lock value.

One final API paper cut - currently if the caller puts the args in the
wrong order they get a false negative instead of an error.

Fix all this by making the satisfaction functions return errors, update
the docs to explicitly define 'satisfaction'.

For now remove the examples in rustdocs, we can circle back to these
once the dust settles.

API test of Errors:

Some of the errors are being 'API tested' tested in `primitives` but
they should be being done in `units/tests/api.rs` - put all the new
errors in the correct places.
2025-05-12 12:17:31 +10:00
Tobin C. Harding a2ff8ddbbb
Improve relative::LockTime is_satisfied_by_{height, time}
We recently improved the relative locktime function `is_satisfied_by` by
adding mined at and chain tip. We can now do the same for the
height/time satisfaction functions.

Note I believe these functions should still be provided because a user
may for some reason have either blocktime data or height data and not
have the other.

Requires some work to the errors, elect to just remove the original
field that held the function argument.

For now remove the examples in rustdocs, we can circle back to these
once the dust settles.
2025-05-12 12:16:08 +10:00
Tobin C. Harding c3102f04de
Fix link to BIP-113
Current rustdocs link is not correct. Just remove the brackets because
we have a fully labelled link right below.
2025-05-12 11:22:55 +10:00
Daniel Roberts e492f94289 Update `ScriptBuf::with_capacity` docs
Document that `ScriptBuf::with_capacity` may overallocate.
2025-05-10 19:20:42 -05:00
merge-script 79a6840490
Merge rust-bitcoin/rust-bitcoin#4078: primitives: Add an API test module
e2d9a8a0d8 primitives: Add an API test module (Tobin C. Harding)
8ec2d353c9 primitives: Derive Clone on witness::Iter (Tobin C. Harding)

Pull request description:

  In preparation for 1.0-ing `primitives` add an `api` test module that makes an effort to verify the API surface.

  This is similar to what is in `units` and what is in development for `hashes` (in #4017).

  Note, there is a WIP attempt at this in #3992.

  Close: #3928

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

Tree-SHA512: 5ec5c87c9aa5e86e579283a5485dcb2b3b5ae59359ae5ab96f8e6634285072bef0d0f111b6780852fd88fe29677f1a84c791a3343a0cb2b09093e77125f3962b
2025-05-09 13:05:36 +00:00
Tobin C. Harding e2d9a8a0d8
primitives: Add an API test module
In preparation for 1.0-ing `primitives` add an `api` test module that
makes an effort to verify the API surface.

This is similar to what is in `units` and what is in development for
`hashes` (in #4017).
2025-05-09 09:10:19 +10:00
Tobin C. Harding 8ec2d353c9
primitives: Derive Clone on witness::Iter
There is no obvious reason why the witness iterator cannot be cloned.
2025-05-09 08:59:31 +10:00
Tobin C. Harding 3b8164139f
primitives: Add docs section for script hex API
In an effort to bring developer attention to the myriad of APIs for
parsing and formatting scripts as hex add a section to the rustodcs of
`Script` and `ScriptBuf` (same text for both).
2025-05-08 15:25:52 +10:00
Tobin C. Harding 6b90e42e78
Finalize the script hex APIs
Recently we made an attempt at making the hex APIs for scripts easier to
use, better documented, and shown via an example.

After that work we decided it would be better if `LowerHex`/`UpperHex`
did not have the prefix. We also wanted to further clarify the inherent
function names to make the all explicit.

See GitHub issue #4316 for the thread of discussion.

Note that this PR does not require changes to the serde regression test
which were non changed in the original work either.
2025-05-08 15:12:05 +10:00
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
Tobin C. Harding c3b7457f6c
Rename Mtp to MedianTimePast
Favour expressiveness over terseness for
`units::locktime::absolute::Mtp` (formerly `Time`) because in general
locktimes are curly AF.
2025-05-08 10:09:09 +10:00
merge-script 4ca6cd6065
Merge rust-bitcoin/rust-bitcoin#4458: locktimes: replace `MtpAndHeight` type with pair of `BlockMtp` and `BlockHeight`
47c77afaac units: delete MtpAndHeight type (Andrew Poelstra)
d82b8c0bcb primitives: stop using MtpAndHeight (Andrew Poelstra)
72d5fbad73 units: stop using MtpAndHeight in locktime::relative is_satisfied_by methods (Andrew Poelstra)
d933c754f5 units: change type of MtpHeight::to_mtp to BlockMtp (Andrew Poelstra)
dcbdb7ca8a units: add checked arithmetic to Block{Height,Mtp}{Interval,} (Andrew Poelstra)
4300271f0c units: add constructor for absolute::Mtp from timestamps (Andrew Poelstra)
4e4601b3d5 units: rename BlockInterval to BlockHeightInterval (Andrew Poelstra)
cb882c5ce1 units: add global `BlockMtpInterval` type (Andrew Poelstra)
4e3af5162f units: add global `BlockMtp` type (Andrew Poelstra)
a3228d4636 units: pull u32 conversions for BlockHeight/BlockInterval into macro (Andrew Poelstra)

Pull request description:

  This is a more involved PR than I'd expected but hopefully the individual commits make sense and are well-motivated. Essentially, my goal was to replace `MtpAndHeight` as used by relative locktimes with a pair of `Mtp` and `Height`.

  However, relative locktimes, when given a MTP/Height for the UTXO creation and the chain tip, are roughly modeled as "take a diff of MTPs to get a `relative::MtpInterval`, a diff of heights to get a `relative::HeightInterval`, and compare to the locktimes". *However*, we have no standalone MTP type to "take a diff of", and also there are failure modes when creating the diffs (e.g. if the diff would exceed the range of `MtpInterval` or `HeightInterval`).

  So I backed up and decided to use the existing `BlockHeight`/`BlockInterval` as the type to "take a diff of". I needed to introduce a `BlockMtp`/`BlockMtpInterval` to work with MTPs. These types have full-u32 range, unlike the similarly-named types in `units::locktimes::absolute`. I then needed to add some conversion methods. Along the way, I cleaned up the APIs and documentation, added checked arithmetic, etc., as needed.

  See the individual commit messages for more detail.

  I believe the resulting API is much more consistent and discoverable, even though it has more surface than the old API.

  I considered splitting this into 2 PRs but I think the first half of the changes aren't well-motivated with out the second half. Let me know.

ACKs for top commit:
  tcharding:
    ACK 47c77afaac

Tree-SHA512: ebe19a5b1684db8c2d913274347c994026aaa0dcdd79349c237920a82fe55560777278efdbbc7f1b1424c9391d9bbd891ae844db885deea75288000437a8a287
2025-05-07 22:32:16 +00:00
merge-script 10657865c3
Merge rust-bitcoin/rust-bitcoin#4457: rustdoc: Fix unused lint warnings
52940d4e12 Prefix unused variables with _ in rustdocs (Jamil Lambert, PhD)
a852aef4b8 Remove unused imports in rustdocs (Jamil Lambert, PhD)

Pull request description:

  There is a lint warning about unused variables and imports in the rustdoc examples.

  Remove the unused imports and prefix the unused variables with an underscore.

ACKs for top commit:
  apoelstra:
    ACK 52940d4e1216ad5118f7980cb2e6b8b425c61589; successfully ran local tests
  tcharding:
    ACK 52940d4e12

Tree-SHA512: 953862d546dc6e0bcd64172e8b383f0fc2a1a851971a1bcad0c1e30cbaeeaea993a0de7dd8b424c4ac1410053e179c52d0b5c90cd1b6560c27123b6b7fa49732
2025-05-07 18:56:53 +00:00
Andrew Poelstra d82b8c0bcb
primitives: stop using MtpAndHeight 2025-05-06 19:23:17 +00:00
Andrew Poelstra 72d5fbad73
units: stop using MtpAndHeight in locktime::relative is_satisfied_by methods
Keep using it in primitives; will remove it there in the next commit.
2025-05-06 18:51:03 +00:00
Andrew Poelstra 4e4601b3d5
units: rename BlockInterval to BlockHeightInterval
Now that we have BlockMtpInterval we want to distinguish BlockInterval
from it.
2025-05-06 15:50:43 +00:00
Andrew Poelstra 4e3af5162f
units: add global `BlockMtp` type
For our relative locktime API, we are going to want to take differences
of arbitrary MTPs in order to check whether they meet some relative
timelock threshold.

However, the `locktime::absolute::Mtp` type can only represent MTPs that
exceed 500 million. In practice this is a non-issue; by consensus MTPs
must be monotonic and every real chain (even test chains) have initial
real MTPs well above 500 million, which as a UNIX timestamp corresponds
to November 5, 1985.

But in theory this is a big problem: if we were to treat relative MTPs
as "differences of absolute-timelock MTPs" then we will be unable to
construct relative timelocks on chains with weird timestamps (and on
legitimate chains, we'd have .unwrap()s everywhere that would be hard to
justify). But we need to treat them as a "difference of MTPs" in *some*
sense, because otherwise they'd be very hard to construct.
2025-05-06 15:19:35 +00:00
Jamil Lambert, PhD a852aef4b8
Remove unused imports in rustdocs
There is a lint warning about unused imports in the rustdoc examples.

Remove them.
2025-05-06 10:26:00 +01:00
Jamil Lambert, PhD 2fbbc825c9
Allow uninlined format args
There is a new lint error on nightly-2025-04-25 "variables can be used
directly in the `format!` string".

Exclude the lint to allow the existing syntax in `format!` strings.
2025-05-06 09:49:02 +01:00
merge-script 1b04f5df65
Merge rust-bitcoin/rust-bitcoin#4431: units: rename relative locktime types, absolute::Time, and constructors
826acb8273 units: rename relative::HeightInterval constructors (Andrew Poelstra)
39b4f7670d units: rename relative::Height to HeightInterval (Andrew Poelstra)
d3619cc1bc units: deprecate relative::MtpInterval::to_consensus_u32 (Andrew Poelstra)
1a6b8b4c7a units: rename relative::Time to MtpInterval (Andrew Poelstra)
39b057fade units: rename absolute::Height consensus functions (Andrew Poelstra)
5a8f33f380 units: rename absolute::Mtp consensus functions (Andrew Poelstra)
8ffcd2cf30 units: rename absolute::Time to absolute::Mtp (Andrew Poelstra)

Pull request description:

  This PR does a whole bunch of renames to the `units` locktime modules. These modules contain the underlying units for locktime types and hopefully aren't used directly too often, which should minimize the disruption from these renames.

  This fixes a number of issues:

  * Confusion between blocktimes and MTPs (which in fairness, *are* blocktimes, but they're not the one that users are likely to reach for)
  * Constructor and conversion names that imply there is a "consensus encoding" for these bare units, which corresponded to the consensus encoding of the corresponding locktimes/sequence numbers
  * `from_*` methods without `to_*` methods and vice-versa (overlaps with the above)
  * the horribly named `value` method on relative heights and times (but not absolute ones)

  This PR does **not** remove the `MtpAndHeight` type, nor does it add constructors for `Mtp` from lists of blocktimes. This is because the PR was too big already and I felt I should split it up.

  Alternate to #4427

ACKs for top commit:
  tcharding:
    ACK 826acb8273

Tree-SHA512: 6e0491e17927625cde85c2cf92ff152a10613e632474122a626ee31b662d21c09fcb9fa3014c44708c97536535a33845cbbcd81e73dcdf98e9ee9fd6143c698f
2025-05-05 09:08:30 +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
Andrew Poelstra 39b057fade
units: rename absolute::Height consensus functions
As with absolute::Mtp, there is no "consensus encoding" of a block
height, except that obtained by converting it to a locktime. For
symmetry with `Mtp`, rename the methods.
2025-05-03 03:12:05 +00:00
merge-script 903b2a5a18
Merge rust-bitcoin/rust-bitcoin#4426: Improve docs on absolute::LockTime::is_implied_by
16f6fc6b5b Improve docs on absolute::LockTime::is_implied_by (Tobin C. Harding)

Pull request description:

  If one wishes to verify a script that contains CLTV is valid in a transaction then one must compare the argument to CLTV (the locktime) to the transaction locktime. And to be valid the CLTV locktime must be less than or equal to the transaction locktime. This usage kind of lends itself to the term 'implied by' and we have a function already `is_implied_by` that does exactly this.

  Improve the docs by adding a section mentioning this usecase.

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

Tree-SHA512: f7de177927150ae27b3db187465e0f699da9e8e00a490b0354176b2dedc34d731fda40bf4d55324aa28b0d55f2f036653ab14d99b82d56705c929986db8fb30e
2025-05-02 23:53:01 +00:00
Andrew Poelstra 5a8f33f380
units: rename absolute::Mtp consensus functions
There is no "consensus encoding" for a MTP. The intention for these
methods was that a user could interpret the MTP as a locktime and then
consensus-encode that locktime. However, it was instead interpreted as
the MTP representing a *blocktime* as it is consensus-encoded in a block
header.

Evidence of this misinterpretation is in several doccomments, which
casually refer to the Mtp (which used to be just called Time) as a
"block time", which is simply incorrect.
2025-05-02 17:44:58 +00:00
Andrew Poelstra 8ffcd2cf30
units: rename absolute::Time to absolute::Mtp
This is not a generic UNIX timestamp, but rather a MTP restricted to
have values between 500 million and u32::MAX. Most importantly, it is
*not* a blocktime, which is what is implied by its name and
constructors.
2025-05-02 17:44:58 +00:00
Tobin C. Harding 16f6fc6b5b
Improve docs on absolute::LockTime::is_implied_by
If one wishes to verify a script that contains CLTV is valid in a
transaction then one must compare the argument to CLTV (the locktime) to
the transaction locktime. And to be valid the CLTV locktime must be less
than or equal to the transaction locktime. This usage kind of lends
itself to the term 'implied by' and we have a function already
`is_implied_by` that does exactly this.

Improve the docs by adding a section mentioning this usecase.
2025-05-01 13:33:08 +10: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