We do not want `bech32` to appear in the public API of the `address`
module in case `bech32` does not stabalize before the soon-to-be-created
`address` crates does.
We already had a go at removing it but forgot one error variant - wrap
the variant in a new type with a private inner bech32 error field.
Roll the `serde_macros` module into `macros`, requires making `macros`
public but since it explicitly holds public macros this is reasonable.
Keep the original module and deprecate it.
The private and public modules are already grouped, add a line of
whitespace to make it _even_ more clear. Trivial I know, this patch got
smaller during rebase.
Up until recently we were using wildcard re-exports for types moved to
`units` and `primitives`. We have decided against doing so in favour of
explicit re-exports.
Audit `units` and `primitives` using `git grep 'pub enum'` (and
`struct`) and explicitly re-export all types.
Remove all wildcards except for the re-exports from `opcodes`, there are
too many opcodes, explicitly re-exporting them does not aid clarity.
5633b10f5c Manually implement compute_txid and compute_wtxid (Tobin C. Harding)
Pull request description:
We would like to move the `Transaction` type over to `primitives` including the `compute_txid` and `compute_wtxid` functions however currently the implementations, as expected, use `Encodable`.
Manually implement `Encodable` by hashing all the fields in the correct order.
Note we have unit tests already that check the output string of the txid returned so these act as regression tests for this patch.
ACKs for top commit:
apoelstra:
ACK 5633b10f5c826e0b2ac47dd85f697f12710898d7; successfully ran local tests; nice
Tree-SHA512: 66a955d3d896801cfefe0388aade3a31f22fac5b6da7b996be61f374b93772487c0c203320aaf5165fcef26874564bce375ecb364175b0a01c3008b7ea8db981
b22db6268c Remove unnecessary lifetimes (Jamil Lambert, PhD)
Pull request description:
New lint warnings from a recent nightly toolchain in #3467 show some explicit lifetimes that can be omitted.
The unnecessary lifetimes have been removed.
ACKs for top commit:
storopoli:
ACK b22db6268c
apoelstra:
ACK b22db6268c609af5bc739168de4fde4a6e82fc43; successfully ran local tests; will one-ACK merge
Tree-SHA512: fa7057a3f2d8d84dfc21baf9784773fa331d808ed7e5153847fba455bf18d1daa1e95661e887fad74e21c953dc01655da6c2797e1fc0d4f546e4852ef1d99ad0
003dc9cf4d Move TxOut to primitives (Tobin C. Harding)
4d37d7efc6 Move TxIn to primitives (Tobin C. Harding)
ce0d517383 Use explicit re-export of transaction types (Tobin C. Harding)
4c5dba82f4 Introduce TxInExt trait (Tobin C. Harding)
b7e6c698f8 Split the TxIn impl block in two (Tobin C. Harding)
265589d93d Make TxIn::BASE_WEIGHT a file level const (Tobin C. Harding)
Pull request description:
Turn the crank; move `TxIn` and `TxOut` to `primitives`.
ACKs for top commit:
apoelstra:
ACK 003dc9cf4d80c2a6d614de1e3a1c7c4b1d5372e0; successfully ran local tests
Tree-SHA512: fa9ffb7677999f0e07231d4603db5c005d4dc1c1b9d1faa8df9e90bd8a8088f853c3e0cd2997ca724f6a4e13941afedf5877ba95ac70f31e7b3438b34c205034
We would like to move the `Transaction` type over to `primitives`
including the `compute_txid` and `compute_wtxid` functions however
currently the implementations, as expected, use `Encodable`.
Manually implement `Encodable` by hashing all the fields in the correct
order.
Note we have unit tests already that check the output string of the txid
returned so these act as regression tests for this patch.
ddde3162ff Remove unnecessary lifetimes (Tobin C. Harding)
Pull request description:
Linter with new nightly toolchain finds another lifetime that can be elided, do so.
ACKs for top commit:
storopoli:
ACK ddde3162ff
apoelstra:
ACK ddde3162ff8417531920aa16e12d7ac73bc5207d; successfully ran local tests; not bad, just one
Tree-SHA512: cc7fde0f586ba0ca7435933a80d0409b9220df0e65d7b71b89a691dbbfaea19117cae65dc1ea61784640a77a62f0794c6c3e65bca203a62ca55731eb5d1a9fd4
In preparation for moving the `TxIn` over to `primitives` make the
private `TxIn::BASE_WEIGHT` associated const into a file-scoped constant
because the other alternative is to make it public.
5ec17a2ee8 CI: Hobble WASM job (Tobin C. Harding)
Pull request description:
The WASM job is not working. `wasm-pack build` works fine but `wasm-pack test` doesn't compile.
Comment out the line that runs `wasm-pack test`.
ACKs for top commit:
apoelstra:
ACK 5ec17a2ee8c963d182777a9661b1bab786956bd4; successfully ran local tests; LGTM
Tree-SHA512: 5ea88bd99f625a8c669dc1dec02486dd549e9ac83d7670c6c7b3b25c86de3fc9a8dbc959dc39de92305dd5e254e0b8ed9424cae5e5941b66a6476ee433009fdd
9c2ac46902 Split up ParseError (Jamil Lambert, PhD)
3d994f7bdb Decode an address string based on prefix (Jamil Lambert, PhD)
Pull request description:
When a decoding error occurs for a bech32 address string the error is discarded and the same address string is attempted to be decoded as base58. This then incorrectly returns a base58 error.
Check the string prefix and decode as bech32 or base58 and return the relevant error. If the prefix is unknown return an `UnknownHrpError`.
Close#3044
ACKs for top commit:
tcharding:
ACK 9c2ac46902
apoelstra:
ACK 9c2ac46902ae2e6f2513ee125ea5c89953ac89a2; successfully ran local tests
Tree-SHA512: 40c94328828af86723e84d4196e8949430fb9a15efd8865c18cb5048fe59b8a2514d97f4809d828353b78c010544a8a6d4589a8c9c7fbd75d9d0ecceb3151e8f
bbffa3db43 Remove the IO error from DecodeError (Tobin C. Harding)
713196be0d Return DeserError from encode::deserialize (Tobin C. Harding)
33566ac58c Split encode::Error into two parts (Tobin C. Harding)
b04142c745 Add encode::Error::MissingData variant (Tobin C. Harding)
5a42ef2850 Do not manually map IO error (Tobin C. Harding)
efd7f9f06c Add error constructor parse_failed_error (Tobin C. Harding)
ebfef3f114 Return generic error as Some (Tobin C. Harding)
a6254212dc Move consensus error code to submodule (Tobin C. Harding)
Pull request description:
The `consensus::deserialize` and `consensus::deserilaize_partial` functions should not return an I/O error. Doing so causes various other error types to include an `io::Error` and the `io::Error` is an annoying type to work with.
This PR is a bunch of steps, and it took me a good while with quite a bit of backtracking to get here. As such you may want to review the final state before looking at each patch.
The `consensus` errors can be further cleaned up but I'd prefer not to spend more time on this unless it has some chance of merging.
ACKs for top commit:
apoelstra:
ACK bbffa3db43802b30d23259c0372f16a877a0ef8b; successfully ran local tests
Tree-SHA512: 522fdd29638a214cb7fcee29dd3b9f5c846f041fba087a56a91b83e6d85f033cbed95f659dc4321cd4596943ff233bdd184cdfbfcc787fe89172bb93aa4ab186
1b521dce99 Move taproot hash types to primitives (Tobin C. Harding)
24e944ed82 Introduce taproot hash type extension traits (Tobin C. Harding)
c30ef617fb Move combine_node_hashes out of TapNodeHash (Tobin C. Harding)
Pull request description:
Move the three `taproot` hash types and their associated tags over to the `primitives` crate.
First two patches are preparation, third on is the move - this one is a no-brainer.
ACKs for top commit:
apoelstra:
ACK 1b521dce99db1900326eec29c47445f522f94ee6; successfully ran local tests; nice! will one-ACK merge
Tree-SHA512: 076f017dad6263144ac1a7e0e0251cfb5f1790898ec1d344107471875fc73157116c04f698ff8a02f1b17dee5306b5054d10c990abc84d8098de9ff74f8fc302
1cb24c1f15 hashes:: Polish crate level rustdocs (Tobin C. Harding)
98691186dc hashes: Move engine functions (Tobin C. Harding)
12f261c009 hashes: Re-order from_byte_array (Tobin C. Harding)
c11587d60d hashes: Rename hash_type macro (Tobin C. Harding)
62617cf9ac hashes: Move from_engine function to other macro (Tobin C. Harding)
bb7dd2c479 hashes: Move DISPLAY_BACKWARD to top of impl block (Tobin C. Harding)
71013afe07 hashes: Put attribute under doc (Tobin C. Harding)
Pull request description:
`hashes 1.0.0` can't be far away, here is a quick polish (done while I waited for my car to get fixed).
Everything here is internal except stuff to docs. Note please I claim "internal change only" in a bunch of patches that do code moves but these effect the docs build because order is preserved in some instances.
ACKs for top commit:
apoelstra:
ACK 1cb24c1f150bc2d65d0be439f2005f41d95ad23c; successfully ran local tests
Tree-SHA512: 430c451afab8fc92fb4596bf2d4b36c086333fe72b3fe5858925b75597641b8c4f5e49f7643888fa19b675d3070ce9a3606623cd56bdba6cfc59e459fbdda440
Currently `combine_node_hashes` is an associated function, it is also
private. It is called from within other methods of the `TapNodeHash`.
In preparation for moving the `TapNodeHash` to `primitives` while
leaving all the methods in `bitcoin` in an extension trait; move the
associated function out of `TapNodeHash` and make it a stand alone
private function.
e7d326f071 Seal extension traits (Tobin C. Harding)
Pull request description:
The extension traits are temporary just while we try to stabalize `primitives`, they are not intended to be implemented by downstream.
Seal the extension traits so that downstream crates cannot implement them.
Fix: #3231
ACKs for top commit:
apoelstra:
ACK e7d326f071a368389f087ddb10ee9bbf3552c33a; successfully ran local tests; thanks! I know this is tedious and annoying
Tree-SHA512: 365979aeabb7941b9c8fa526f71aaadae3ab1cdd6a39e992c5eea2c1057b4b7c2b3a846ffd96a7eab47b9ad4e3e4de4fb141c24c62747e5cee45c74f52f9a172
The `DecodeError` (badly named) consensus decodes an object from an
iterator that implements `Read`. The `Read` impl never returns a real IO
error, we use the `io::Error` to temporarily wrap the error returned by
the inner iterator and unwrap it in `IterReader::decode`. As such there
is no reason for the `DecodeError` to hold an `encode::Error`, it can
hold an `encode::ParseError`.
The value of this change is easily seen in the removal of calls to
`unreachable`.
The `consensus::encode::Error` contains an IO error but reading from a
buffer only ever errors for EOF. We converted all instances of EOF to
`MissingData` already so now we can split the IO error apart from the
actual encoding errors variants.
The `io::Error` is troublesome because it contains a bunch of stuff that
never happens when reading from a buffer. However the EOF variant can
occur if the buffer is too short. As an initial step towards reducing
usage of the `io::Error` add a `MissingData` variant to the
`encode::Error` and when converting from an IO error map to
`MissingData` if EOF is encountered.
The `encode::Error::ParseFailed` variant holds an inner string, this is
suboptimal.
In an effort to patch the `encode::Error` while mimizing the diffs
required add a helper function that creates the variant. The benefit is
that later patches that effect this variant will only need to update the
constructor function and not every call site.
Internal change only.
The `consensus` module has a bunch of error types, move them all to a
separate module. Add re-exports so the types are still available at the
same place they were. Make the `error` module private and re-export all
errors from the `consensus` module root.
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
ParseError is too general and the functions returning it do not have an
error path for all variants.
Split out the Bech32 and Base58 related errors into their own enums.
1d2cfb036c Make `Amount::to_sat` and `SignedAmount::to_sat` const (Casey Rodarmor)
Pull request description:
Fixes#3491.
ACKs for top commit:
tcharding:
ACK 1d2cfb036c
apoelstra:
ACK 1d2cfb036cff1088420e42a817b4a672e65e5d4b; successfully ran local tests
Tree-SHA512: fc88202176afefb7ff75ad362cb9f139523db0a3d57821e5078af9fead9276b36fa7c915f197c45d4097c73e6bac6a1e72c012007ba9789d92a5514ab1d30f32
The extension traits are temporary just while we try to stabalize
`primitives`, they are not intended to be implemented by downstream.
Seal the extension traits so that downstream crates cannot implement
them.
Fix: #3231
8fffdc8a52 Automated update to Github CI to cargo-semver-checks version-0.36.0 (Update cargo-semver-checks 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 8fffdc8a52
Tree-SHA512: 9f9056c0efdd68a58fc5a2e96628e9327820868a880a2126c98a17ece9858064dc176b565325cfc4daa29f11dc1911c929eb92ebd2768115706be278c0d4540a
c1eccfde25 Move Witness to primitives (Tobin C. Harding)
6ce76cd7c8 Add unstable constructor to Witness (Tobin C. Harding)
Pull request description:
Patch 1 introduces a new policy to the codebase, we use `foo__unstable` for public unstable functions and there are zero semver guarantees if you call these functions.
Patch 2 does the move.
Close#3406
ACKs for top commit:
apoelstra:
ACK c1eccfde25fd4c2b19e7ec6759352b46ac246113; successfully ran local tests
Tree-SHA512: 2388066be2b6bb2cf3d6757c8f6334beeda6115ef1ce7c537955d32aa5e466add5162d0d2adee27f416fe622fc93c4e94bd848326463ee55e08d1c0f4e03719c