Commit Graph

29 Commits

Author SHA1 Message Date
Tobin C. Harding 1bac1fd518
Rename the network module to p2p
The `network` module deals with data types and logic related to
internetworking bitcoind nodes, this is commonly referred to as the p2p
layer.

Rename the `network` module to `p2p` and fix all the paths.
2023-08-01 16:36:12 +10:00
Tobin C. Harding a70b1b9c6c
Use standard set of derives on all error types
As part of an ongoing effort to make our error types stable and useful
add a stand set of derives to all error types in the library.

    `#[derive(Debug, Clone, PartialEq, Eq)]`

Add `Copy` if possible and the error type does not include
`#[non_exhaustive]`.

If an error type includes `io::Error` it only gets `#[derive(Debug)]`.
2023-07-28 06:15:49 +10:00
Tobin C. Harding 2268b44911
Depend on hex-conservative
We have just released the `hex-conservative` crate, we can now use it.

Do the following:

- Depend on `hex-conservative` in `bitcoin` and `hashes`
- Re-export `hex-conservative` as `hex` from both crate roots.
- Remove all the old hex code from `hashes`
- Fix all the import statements (makes up the bulk of the lines changed
  in this patch)
2023-07-21 10:59:46 +10:00
Steven Roose 4c18ba779c
network: Implement Default on ServiceFlags 2023-06-06 00:06:28 +01:00
Andrew Poelstra 67ff453a3a
Merge rust-bitcoin/rust-bitcoin#1801: Adds as_core_arg serde module to network
aa6a3530a6 Adds as_core_arg serde module to network (Sergi Delgado Segura)

Pull request description:

  The new module provides serde functions to convert from/to Bitcoin Core network variants.

  Fixes #1799

ACKs for top commit:
  Kixunil:
    ACK aa6a3530a6
  tcharding:
    ACK aa6a3530a6
  sanket1729:
    ACK aa6a3530a6

Tree-SHA512: f536d0e41144928b71dc9b58735d4e0b883ee84a7a84e868f1d74b284c2e2be746ddcb30028dd099515bc933e7efa2cf26717f506edde84c40c3f523a5a8ed27
2023-05-02 01:45:41 +00:00
Tobin C. Harding 984fe69448
bitcoin: Remove attribution from all files
Currently we have a mishmash of attribution lines accompanying the SPDX
identifier. These lines are basically meaningless because:

- The date is often wrong
- The original author attributed is not the only contributor to a file
- The term "rust bitcoin developers" is basically just noise

Just remove all the attribution lines and be done with it. While we are
at it add an SPDX line to the few files missing it, whether this license
nonsense is even needed is left as an argument for another day.
2023-05-01 09:22:48 +10:00
Sergi Delgado Segura aa6a3530a6 Adds as_core_arg serde module to network
The new module provides serde functions to convert from/to Bitcoin Core
network variants

Includes tests suggested by @tcharding
2023-04-17 12:28:13 +02:00
Tobin C. Harding fabcde036f
Use package in manifest and shorten import
We can use `package` to rename `bitcoin_hashes` to `hashes` and
`bitcoin_internals` to `internals`. This makes imports more terse with
no loss of meaning.
2023-03-28 12:20:04 +11:00
Tobin C. Harding 122188f7dd
Use shorter import statements
As per discussion [0] use the shorter form for importing crates that we
re-export (`hashes` and `secp256k1`).

[0] https://github.com/rust-bitcoin/rust-bitcoin/discussions/1661
2023-03-22 14:09:58 +11:00
Tobin C. Harding a11cf07501
Run the formatter
Various formatting issues have crept into the codebase because we do not
run the formatter in CI.

In preparation for enabling formatting checks in CI run `cargo +nightly
fmt` to fix current formatting issues. No changes other than those
create by the formatter.
2023-03-06 10:22:29 +11:00
Andrew Poelstra 13143d0f6f
Merge rust-bitcoin/rust-bitcoin#1675: Add utils to convert ChainHash to a Network
56569b32ef Add utils to convert ChainHash to a Network (benthecarman)

Pull request description:

ACKs for top commit:
  Kixunil:
    ACK 56569b32ef
  tcharding:
    ACK 56569b32ef

Tree-SHA512: a489fcb1c1208db4271076d88288658988a63209e56e7433bde82d7d5719450433348fcc3cb6aae59ffa6ed8aff510d6b031c6899d5cf64c503a53b2d4c692b8
2023-02-27 23:55:24 +00:00
benthecarman 56569b32ef
Add utils to convert ChainHash to a Network 2023-02-27 12:28:04 -06:00
benthecarman a4b5fb4002
Fix docs for UnknownMagic to be accurate 2023-02-27 00:33:20 -06:00
Andrew Poelstra 1b15a13e5a
run cargo clippy and fmt 2022-12-13 14:52:43 +00:00
Andrew Poelstra c93e83e94b
Merge rust-bitcoin/rust-bitcoin#1428: Adds Network::from_core_arg and links it to Network::from_str
d7006ef80d Adds roundtrip tests for Network::from_core_arg (Sergi Delgado Segura)
bd1eb29f61 Adds Network::to_core_arg (Sergi Delgado Segura)

Pull request description:

  Comming from https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/247

  `Network::from_str` only considers `rust-bitcoin` string as possible inputs to create a `Network` instance. This PR adds a new method to `Network`, `from_core_arg`, which is complementary to the existing `Network::to_core_arg`. This method allows the conversion between `bitcoind -network` string and `Network` variants.

  This also links `Network::from_str` to `Network::from_core_arg` so the default case on the former calls the latter, and an error is only returned if none of the cases match.

ACKs for top commit:
  Kixunil:
    ACK d7006ef80d
  apoelstra:
    ACK d7006ef80d

Tree-SHA512: 97a66f858a7d4a3642bdef9016457833cfc1181e276f7ead7c6b87f6fcdcb7c5d1cfdb4b621225b806bc5949c3c5cc6a32b7df934157542d7c79aa00a9e20f41
2022-12-08 15:12:40 +00:00
Sergi Delgado Segura d7006ef80d Adds roundtrip tests for Network::from_core_arg 2022-12-08 07:19:22 -05:00
Sergi Delgado Segura bd1eb29f61 Adds Network::to_core_arg
This allows users to create `Network` instances from `bitcoind -chain` values
2022-12-08 06:33:24 -05:00
Tobin C. Harding 13d94cbc47 Remove no_run
`no_run` is not needed since we already mark this up as `bash` which
rustc doesn't run when running examples.

While the keyword `bash` is not currently supported it may well be in
the future and since only the `rust` keyword causes code to run any
other string is effectively a wildcard, `no_run` is therefore meaningful
only as a convention. Lets keep `bash` in case support is added later on.
2022-12-02 07:25:41 +11:00
connormullett 519db4d951 add Network::to_core_arg() method 2022-11-18 23:12:10 -05:00
Tobin C. Harding e04a7a926d network: Run cargo fmt
We just removed the `bitcoin/src/network/` exclude from `rustfmt` config
file. Run the command `cargo +nightly fmt`.

No other changes than those introduced by `rustfmt`.
2022-11-18 13:11:09 +11:00
Tobin C. Harding 5a8a5ff6c9 Move debug_from_display to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put
`debug_from_display` in it.
2022-10-20 06:15:23 +11:00
Noah d1b7dff094 return custom error from `Network::from_str` 2022-10-10 19:37:14 +11:00
Noah bfb4977be9 implement `AsMut<[u8]>` and `AsMut<[u8;4]>` for `Magic` 2022-09-29 16:04:37 +10:00
Noah 6e5e8d80a6 add error implementations for `ParseMagicError` and `UnknownMagic` 2022-09-28 19:43:10 +10:00
Noah a79c69894a new type network magic 2022-09-28 10:32:47 +10:00
Tobin C. Harding f429c22599 Remove user_enum macro
The `user_enum` macro is only used a single time. The macro includes
custom serde logic which can be trivially derived instead.

Remove the `user_enum` macro and just implement `Network` the old
fashioned way. Doing so simplifies the code.
2022-09-20 16:53:38 +10:00
Tobin C. Harding ad29084582 Add Network serde roundtrip test
In preparation for patching the `Network` serde impls; add a roundtrip
test for `serde` (de)serializing  the `Network` type.
2022-09-20 15:29:55 +10:00
Tobin C. Harding 7a1aa2098a Remove code deprecated last release
We give one release cycle for deprecating old code so as to make the
upgrade path easier for downstream users.

Remove code deprecated during the last release (v0.29.0).
2022-09-16 08:08:53 +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/network/constants.rs (Browse further)