This macro is a helper for `impl_parse_str_from_int_infallible` used to
reduce code duplication. It does not, and should not, need to be part of
the public API - hide it.
We have a public macro `impl_parse_str_from_int_infallible` and a helper
macro used by it, both pubicly exported.
To assist readers understanding what is going on put the helper below
the other.
Code move only, no logic change.
7f2cf1dce8 api: Include generics in regex (Tobin C. Harding)
Pull request description:
The regex is still wrong, it misses structs with generics.
Currently `contrib/api.sh io types` returns:
ErrorKind
Error
Sink
But with this patch applied it returns:
FromStd<T>
ToStd<T>
ErrorKind
Cursor<T>
Error
Sink
Take<'a, R: bitcoin_io::Read + ?core::marker::Sized>
Thanks ChatGPT, good robot.
ACKs for top commit:
storopoli:
ACK 7f2cf1dce8
apoelstra:
ACK 7f2cf1dce8236c60931f729748c487d401878067; successfully ran local tests; nice!
Tree-SHA512: 92fde9788edf8bf3e9b0639aec0aa0c4d7509c46cb048505e8018af57d671e893dccb7e0e018246438cceeb9c64232b8a0639bfe1ee7a35983b9e2bf1f2d4a4a
20b798175c Update to latest rust-ordered (Tobin C. Harding)
Pull request description:
I just went to town on the `rust-ordered` crate to get it ready for releasing a `1.0` version. None of the changes effect our usage here in `rust-bitcoin`.
Upgrade to the latest version of `rust-ordered` - `v0.3.0`.
ACKs for top commit:
apoelstra:
ACK 20b798175c23e40988f821c9a90e28e216df2937; successfully ran local tests
Tree-SHA512: b21608ad1992df3a0c5c93a454c08c8e3fab4d9e10c2f05ee2d929e585134ad26045f707f77083e6b6c3952dd04e611db7a35389ffe8fd487acad5344e9d36f3
ae129d84ac api: Run just check-api (Tobin C. Harding)
3f433f1cde Improve Cursor ref API (Tobin C. Harding)
Pull request description:
Our `Cursor` is a replacement of sorts for the `std::io::Cursor`. Users of the `Cursor` are likely to expect the same API so to get a reference and/or mutable reference users will likely reach for `get_ref` and `get_mut`. We should provide these.
Deprecate `inner` since it is the same as `get_ref` but less idiomatically named (should have been `as_inner`).
Add `get_ref` and `get_mut` methods to the `Cursor` type.
ACKs for top commit:
apoelstra:
ACK ae129d84ace03fba57bb980cace5aa60ff6bc10e; successfully ran local tests
Tree-SHA512: 664d08cc977c9d6e3319767c49bbabc8f21d681d570f50c514797a7737469cf861af60158ccc1c71d28baed542dabbbca586968144d60691ee0183a549a7b765
2042d91be5 api: Run just check-api (Tobin C. Harding)
04bae4bb91 Use _unchecked in unit tests (Tobin C. Harding)
8e6784dd41 Introduce Amount::from_sat_unchecked (Tobin C. Harding)
f32af7dac6 Use ua_sat throughout test function (Tobin C. Harding)
75f0afd0a3 Add local variable to use as constructor (Tobin C. Harding)
940a244132 Replace Amount::from_sat(0) with ZERO (Tobin C. Harding)
Pull request description:
This is a small-ish changeset in order to mirror what was started in #3769 and reduce the diff in #3794
- Patch 1: Trivial refactor to use `Amount::ZERO`.
- Patch 2: Add the constructor and refactor a single unit test to use it.
- Patch 3: Use the two `_unchecked` constructors throughout `units/src/amount/tests.rs`.
- Patch 4: Add the API text file changes.
ACKs for top commit:
jamillambert:
ACK 2042d91be5
apoelstra:
ACK 2042d91be59a1d47afb986cef0152f9b5250f476; successfully ran local tests
Tree-SHA512: 8f9c3816509bb3fc0707cd4a47426130d001358e82273457b24170522644e10fe36b596e16500ce1778738f5546dfad592f1f3c4de552ec0afcb146442176cf5
I just went to town on the `rust-ordered` crate to get it ready for
releasing a `1.0` version. None of the changes effect our usage here in
`rust-bitcoin`.
Upgrade to the latest version of `rust-ordered` - `v0.3.0`.
87293dfdd3 api: Run just check-api (Tobin C. Harding)
ed387e5f1d hashes: Hide both macros (Tobin C. Harding)
Pull request description:
We have two macro definitions feature gated on `serde`. At some stage we added the `doc(hidden)` attribute to one of them but forgot to add it to the other. This technically makes our features non-additive. This macro is "internal" so its unlikely that this is being used in the wild.
Add `doc(hidden)` to the `serde_impl` macro that is missing it.
Found by `cargo semver-checks` after recent upgrade to 0.38
ACKs for top commit:
storopoli:
ACK 87293dfdd3
apoelstra:
ACK 87293dfdd38be71938ae9d6a9981eb4569de3521; successfully ran local tests
Tree-SHA512: 3773eb42684bce56928f2d3f87993d010dd36634fda8dfa6b18b27a36b6c4bb521d711340a4868270dbd2d0c6a11715f9a1998ff3deb6900bd4227a44722a11e
We now have both `Amount::from_sat_unchecked` and
`SignedAmount::from_sat_unchecked`. These constructors are explicitly
for ignoring any invariant (implied or otherwise) especially in test
code.
Note we do not enforce an invariant currently. This patch is a baby step
towards getting the `amount` module in order.
Replace all calls to `from_sat` for const int values with the
`_unchecked` constructor. Done in `amount::tests` only.
As we did for `SignedAmount` add a constructor to the `Amount` type that
does no checks on its argument.
(This is in preparation for enforcing the MAX_MONEY invariant.)
Use the `_unchecked` version in a single unit test. The rest of the unit
tests will be refactored later to minimise the size of this patch.
As we already do in this test function for other constructors; add a
local variable and bind it to the `SignedAmount::from_sat` constructor.
Refactor only, no logic change.
2e482f0fdd Remove unnecessary floating code comment (Tobin C. Harding)
Pull request description:
Code comments that comment and arbitrary block "section" of code are almost always pointless and almost always go stale over time.
These particular code comments add almost no value.
Remove code comments.
ACKs for top commit:
jamillambert:
ACK 2e482f0fdd
apoelstra:
ACK 2e482f0fddb55da897f0ba8ea4d3fa5bb0fba1b5; successfully ran local tests; yeah, in this case I agree
Tree-SHA512: 9cd5891e4d91af5206d99b5a2021bc82cc33e3c11d66364442a1a16866d2329ed3a005865cec1a76db80eb3191495a1710a683bc5a69284a29f164a1285b42ea
e13355318e Add From impl (yancy)
364e9ff775 Change method return type (yancy)
fdf3336ed5 Add unchecked variant (yancy)
Pull request description:
Any SignedAmount can now be cast to Amount since the range is the same. Specifically, the range for SignedAmount is (- 21 million, 21 million) while the range for Amount is (0, 21 million). Therefore any value from Amount can be cast to a SignedAmount and it will work. Note it's not the same and still requires checking when going from SignedAmount to Amount since Amount can't handle the negative range.
ACKs for top commit:
tcharding:
ACK e13355318e
Tree-SHA512: c016b51bdd87a12eb09d9c1a82699dad1e866bf96bd3235eeb131f216f02422acb992ddb3a8135af00bbc10e240178fde5e37fb7860d9e6eaf433cf917d4d16a
Our `Cursor` is a replacement of sorts for the `std::io::Cursor`. Users
of the `Cursor` are likely to expect the same API so to get a reference
and/or mutable reference users will likely reach for `get_ref` and
`get_mut`. We should provide these.
Deprecate `inner` since it is the same as `get_ref` but less
idiomatically named (should have been `as_inner`).
Add `get_ref` and `get_mut` methods to the `Cursor` type.
The regex is still wrong, it misses structs with generics.
Currently `contrib/api.sh io types` returns:
ErrorKind
Error
Sink
But with this patch applied it returns:
FromStd<T>
ToStd<T>
ErrorKind
Cursor<T>
Error
Sink
Take<'a, R: bitcoin_io::Read + ?core::marker::Sized>
We have two macro definitions feature gated on `serde`. At some stage we
added the `doc(hidden)` attribute to one of them but forgot to add it to
the other. This technically makes our features non-additive. This macro
is "internal" so its unlikely that this is being used in the wild.
Add `doc(hidden)` to the `serde_impl` macro that is missing it.
Found by `cargo semver-checks` after recent upgrade to 0.38
de0f940b90 Automated update to Github CI to rustc nightly-2024-12-26 (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 de0f940b90
Tree-SHA512: 83ba49d2df44853ac2179edf432fb05e77b2e2d98d515eb86743f96bbf637b4ea1b75e5975991049635e5372847cafdb96a2503beb5a8915c4d5af3335f86dce
Code comments that comment and arbitrary block "section" of code are
almost always pointless and almost always go stale over time.
These particular code comments add almost no value.
Remove code comments.
Any SignedAmount can now be cast to Amount since the range is the same.
Specifically, the range for SignedAmount is (- 21 million, 21 million)
while the range for Amount is (0, 21 million). Therefore any value from
Amount can be cast to a SignedAmount and it will work. Note it's not
the same and still requires checking when going from SignedAmount to
Amount since Amount can't handle the negative range.
As a side effect of changing the return type, TryFrom is no longer valid
and does not compile. Therefore in addition to changing the return
type, TryFrom is also removed.
774f066879 refactor: Change from u64 to Amount (yancy)
Pull request description:
Separate out refactor commit from https://github.com/rust-bitcoin/rust-bitcoin/pull/3794. Can be merged independently.
ACKs for top commit:
tcharding:
ACK 774f066879
apoelstra:
ACK 774f066879c8ad1af81c7e46b404fa63682a0b4c; successfully ran local tests
Tree-SHA512: 9ec5121d823ee3ec506eee5b5187bd496221bd3576afcaa6daf647099720d87b58b69521f29ae9537f123e2958771bc867b123da3f2ba941cba403a6c98e46de
29811ba82c api: Run just check-api (Tobin C. Harding)
0a16382fa3 Rename rhs to weight (Tobin C. Harding)
Pull request description:
In ops functions we typically use `rhs` but for the more unconventional `checked_*_by_*` functions lets use a more descriptive parameter name.
Interestingly `cargo public-api` thinks this is an API breaking change. This is obviously an internal change but the api files are updated because the parameter names appear in the api text files.
ACKs for top commit:
apoelstra:
ACK 29811ba82cc598d08dc877825ecf8890c48d23b7; successfully ran local tests; sure
sanket1729:
ACK 29811ba82c
Tree-SHA512: b44c958ab3ef024c867d81f12819775afa62f1762b96afb93831bb4857ddb9bc95ae5b5f42f32b1a1d23832c69c3cae55f12a80d109fadda7d6763bc764d06aa
The Amount type provides better type safety and is more appropriate in
this context than u64. Currently the checked arithmetic operations for
Amount and u64 are identical in behavior. Therefore, this refactor does
not result in any behavior change and is purely cosmetic.
6e78c05e03 api: Run just check-api (Tobin C. Harding)
760f0715dd units: Make amount::error module private (Tobin C. Harding)
Pull request description:
The `untis::error` module is just a code organisation thing it should never have been public. We already re-export all the error types and this is verified by the `units/tests/api.rs` test file.
Make the module private and remove it from the paths in the `api` test.
ACKs for top commit:
apoelstra:
ACK 6e78c05e0394773c18c1cbd6d140b9f57a6575b1; successfully ran local tests; man, these API tests are awesome
Tree-SHA512: eb1fd6d0a9c49b49c275782e6525e904ff72536260a1fba965140fab5a62f53db13d06a294e5efbc54d500a03d9fc7322b16b8154e587a5f0ff4e7d5e2c0288e
The `untis::error` module is just a code organisation thing it should
never have been public. We already re-export all the error types and
this is verified by the `units/tests/api.rs` test file.
Make the module private and remove it from the paths in the `api` test.
In ops functions we typically use `rhs` but for the more unconventional
`checked_*_by_*` functions lets use a more descriptive parameter name.
This is an internal change but the api files are updated because the
paramater names appear in the api text files.
73140b5fb7 Automated update to Github CI to rustc nightly-2024-12-20 (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 73140b5fb7
Tree-SHA512: 107f7d799481a64719daa478c0c4b6f20855837ad0ca0fd3f255be275b45747cb64b8141d1486cf6dacbc6e721604ca56b24b5bc99ecec1c0829c70db21424fc
04dfe8dd45 Add api test to check Arbitrary impls (Shing Him Ng)
678fc71b88 Implement Arbitrary for units types (Shing Him Ng)
Pull request description:
Implement Arbitrary for the rest of the types in `units`. Also moved the implementation in `FeeRate` right before the `tests` module
Closes#3705
ACKs for top commit:
apoelstra:
ACK 04dfe8dd45fae9b55dacfe9eb0d73ea306db14ba; successfully ran local tests
tcharding:
ACK 04dfe8dd45
Tree-SHA512: 156bd26d4de85d484711d476df1d2758805387125209f0307aa786dd1585ff9953dbe41b0864b00ae101419176647e3bde7994ed9257c18307d161463b1c8d2e
23f75a098c Update regex lookahead to match when there are no characters (Shing Him Ng)
Pull request description:
Was working on #3777 and noticed that `amount::Denomination` didn't show up when running `contrib/api.sh units types`. There are some structs/enums in `api/<crate>/all-features.txt` that dont have a `\(`, `;`, or ` ` after the struct/enum name, and the line just ends, so matching the end of line `$` should also be added.
This allows the script to find the additional type from `units`:
`#[non_exhaustive] pub enum bitcoin_units::amount::Denomination`
Also tested this in `primitives`, and it returned:
```
script::Script
BlockChecked
BlockUnchecked
absolute::LockTime
block::Checked
block::Unchecked
locktime::absolute::LockTime
locktime::relative::LockTime
opcodes::Class
opcodes::ClassifyContext
relative::LockTime
BlockHash
BlockHeader
CompactTarget
Sequence
TapBranchTag
TapLeafHash
TapLeafTag
TapNodeHash
TapTweakHash
TapTweakTag
Transaction
TxIn
TxMerkleNode
TxOut
Txid
Witness
WitnessCommitment
WitnessMerkleNode
Wtxid
block::BlockHash
block::Header
block::Version
block::WitnessCommitment
merkle_tree::TxMerkleNode
merkle_tree::WitnessMerkleNode
opcodes::Opcode
pow::CompactTarget
script::ScriptBuf
script::ScriptHash
script::WScriptHash
sequence::Sequence
taproot::TapBranchTag
taproot::TapLeafHash
taproot::TapLeafTag
taproot::TapNodeHash
taproot::TapTweakHash
taproot::TapTweakTag
transaction::OutPoint
transaction::Transaction
transaction::TxIn
transaction::TxOut
transaction::Txid
transaction::Version
transaction::Wtxid
witness::Witness
```
vs without this update (on `master`):
```
script::Script
BlockHash
CompactTarget
Sequence
TapLeafHash
TapNodeHash
TapTweakHash
TxMerkleNode
Txid
WitnessCommitment
WitnessMerkleNode
Wtxid
block::BlockHash
block::Version
block::WitnessCommitment
merkle_tree::TxMerkleNode
merkle_tree::WitnessMerkleNode
pow::CompactTarget
script::ScriptBuf
script::ScriptHash
script::WScriptHash
sequence::Sequence
taproot::TapLeafHash
taproot::TapNodeHash
taproot::TapTweakHash
transaction::Txid
transaction::Version
transaction::Wtxid
```
ACKs for top commit:
tcharding:
ACK 23f75a098c
storopoli:
ACK 23f75a098c
apoelstra:
ACK 23f75a098ca38aeb1b79473bfe231ae27e20c6df; successfully ran local tests
Tree-SHA512: ce6a43d017bb4bc6317853a4646ce4a8dcf5ce957bb2b9cc50bbd333c6854efd7527c25571c1b30736ae496305fedcf876022ad26c50bee232150d308cb62d08
937a3da8dd Add rustdoc errors (Jamil Lambert, PhD)
78f1628bf6 Add Examples to rustdocs (Jamil Lambert, PhD)
09e184015e Fix rustdocs in SignedAmount (Jamil Lambert, PhD)
Pull request description:
Update rustdocs in `units::SignedAmount` to conform to the API guidelines. Add examples to `Amount` to match the ones added to `SignedAmount`.
ACKs for top commit:
tcharding:
ACK 937a3da8dd
apoelstra:
ACK 937a3da8dde74128f79486cf2668f9abaf133bea; successfully ran local tests
Tree-SHA512: a7ad926a33d0943d7334cf3990392d9ca5911603c5ddda69601dd2f744ff0784bd123317179c88d9841c3e9f25f9d75e745100c5b4db7a5b801a7d6a5e15f948