Commit Graph

9 Commits

Author SHA1 Message Date
Tobin C. Harding 6151d4c841 base58: Rename public functions
The `base58` module is for encoding and decoding, it makes sense for the
public functions to be called `encode` and `decode`. We also have some
functions that operate on data with a checksum, for these it makes sense
to tack `check` onto the _end_ of the function name.

With this applied the public API is:

- decode
- decode_check
- encode
- encode_check
- encode_check_to_fmt
2022-10-29 10:35:08 +11:00
Tobin C. Harding a94af5c052 base58: Re-order code
Code is arguably easier to read if the most important stuff comes first.
In the old days, when writing C, we had to put definitions before they
were used but in Rust this is not the case

Re-order the `base58` file so that the public API functions are up the top
then other helper functions are defined _after_ they are called.

Refactor only, no logic changes.
2022-10-29 10:35:08 +11:00
Tobin C. Harding d362e6286a base58: Improve rustdocs
Improve the rustdocs by doing:

- Use full sentences
- Use typical project line length
- Use third person tense for functions
2022-10-29 10:35:08 +11:00
Tobin C. Harding a43234e7ab base58: Make SmallVec methods private
The `SmallVec` type is private, it does not need public methods.
2022-10-29 10:35:08 +11:00
Tobin C. Harding 27f2cba623 base58: Use alternate form to print hex
Currently we are manually adding `0x` in calls to `write!`, this is
unnecessary since the alternate form already adds the `0x`.

Was verified with
```
    #[test]
    fn bad_checksum_error_hex_format() {
        let want = "invalid base58 character 0xab";
        let got = format!("{}", Error::BadByte(0xAB));
        assert_eq!(got, want)
    }
```

Use alternate form to print hex.
2022-10-29 10:35:08 +11:00
Tobin C. Harding f659a7aca3 base58: Remove key related errors
The key related errors are incorrect because they are circular, we have
a base58 error variant in `key::Error` and two key error variants in
`base58::Error`.

Remove the key errors from the `base58::Error` type.
2022-10-29 10:33:14 +11:00
Tobin C. Harding 2674327c93 Remove the endian module
Now we have MSRV of 1.41.1 we can use the `from_le_bytes` and
`to_be_bytes` methods, these became available in Rust 1.32.

Remove the `endian` module replacing its logic with calls to methods on
the respective stdlib integer types.
2022-10-28 11:01:57 +11:00
Tobin C. Harding 834bbf461f Introduce bitcoin-internals crate
Add a new crate `bitcoin-internals` to be used for internal code needed
by multiple soon-to-be-created crates.

Add the `write_err` macro to `bitcoin-internals`, nothing else.

This patch uses a `path` dependency which means `rust-bitcoin` cannot be
released in its current state, will need to be changed once we release
the `bitcoin-internals` crate on `crates.io`.
2022-09-13 08:59:57 +10:00
Tobin C. Harding 022730bd8d Add a workspace to the top level directory.
Create a directory `bitcoin` and move into it the following as is with
no code changes:

- src
- Cargo.toml
- contrib
- test_data
- examples

Then do:

- Add a workspace to the repository root directory.
- Add the newly created `bitcoin` crate to the workspace.
- Exclude `fuzz` and `embedded` crates from the workspace.
- Add a contrib/test.sh script that runs contrib/test.sh in each
  sub-crate
- Fix the bitcoin/contrib/test.sh script
2022-09-13 08:44:57 +10:00
Renamed from src/util/base58.rs (Browse further)