Skip to content

Commit 3a72c19

Browse files
committed
Remove dependency on bitcoin-internals
Currently we have a dependency on `bitcoin_internals` just for the `write_err` macro. Copy the macro here and remove the dependency. Make the macro and module private.
1 parent 27dbc0c commit 3a72c19

File tree

10 files changed

+31
-9
lines changed

10 files changed

+31
-9
lines changed

Cargo-minimal.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ name = "corepc-types"
120120
version = "0.5.0"
121121
dependencies = [
122122
"bitcoin",
123-
"bitcoin-internals",
124123
"serde",
125124
"serde_json",
126125
]

Cargo-recent.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ name = "corepc-types"
120120
version = "0.5.0"
121121
dependencies = [
122122
"bitcoin",
123-
"bitcoin-internals",
124123
"serde",
125124
"serde_json",
126125
]

types/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ exclude = ["tests", "contrib"]
1414

1515
[features]
1616
default = ["std"]
17-
std = ["bitcoin/std", "internals/std"]
17+
std = ["bitcoin/std"]
1818

1919
[dependencies]
2020
bitcoin = { version = "0.32.0", default-features = false, features = ["serde", "base64"] }
21-
internals = { package = "bitcoin-internals", version = "0.3.0", default-features = false, features = ["alloc"]}
2221
serde = { version = "1.0.103", default-features = false, features = [ "derive", "alloc" ] }
2322
serde_json = { version = "1.0.117" }
2423

types/src/error.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
/// Formats error.
4+
///
5+
/// If `std` feature is OFF appends error source (delimited by `: `). We do this because
6+
/// `e.source()` is only available in std builds, without this macro the error source is lost for
7+
/// no-std builds.
8+
macro_rules! write_err {
9+
($writer:expr, $string:literal $(, $args:expr)*; $source:expr) => {
10+
{
11+
#[cfg(feature = "std")]
12+
{
13+
let _ = &$source; // Prevents clippy warnings.
14+
write!($writer, $string $(, $args)*)
15+
}
16+
#[cfg(not(feature = "std"))]
17+
{
18+
write!($writer, concat!($string, ": {}") $(, $args)*, $source)
19+
}
20+
}
21+
}
22+
}
23+
pub(crate) use write_err;

types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod v26;
2727
pub mod v27;
2828
pub mod v28;
2929

30+
mod error;
3031
// JSON types that model _all_ `bitcoind` versions.
3132
pub mod model;
3233

types/src/v17/blockchain/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use bitcoin::amount::{self, ParseAmountError};
66
use bitcoin::consensus::encode;
77
use bitcoin::error::UnprefixedHexError;
88
use bitcoin::{address, hex, network};
9-
use internals::write_err;
109

10+
use crate::error::write_err;
1111
use crate::NumericError;
1212

1313
/// Error when converting a `GetBlockVerbosityOne` type into the model type.

types/src/v17/network/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use core::fmt;
44

55
use bitcoin::amount::ParseAmountError;
6-
use internals::write_err;
6+
7+
use crate::error::write_err;
78

89
/// Error when converting a `GetTransaction` type into the model type.
910
#[derive(Debug)]

types/src/v17/wallet/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use bitcoin::amount::ParseAmountError;
66
use bitcoin::consensus::encode;
77
use bitcoin::psbt::PsbtParseError;
88
use bitcoin::{address, bip32, hex, key, witness_program, witness_version};
9-
use internals::write_err;
109

10+
use crate::error::write_err;
1111
use crate::NumericError;
1212

1313
/// Error when converting a `AddMultisigAddress` type into the model type.

types/src/v19/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use core::fmt;
99

1010
use bitcoin::error::UnprefixedHexError;
1111
use bitcoin::{hex, network, BlockHash, Network, Work};
12-
use internals::write_err;
1312
use serde::{Deserialize, Serialize};
1413

14+
use crate::error::write_err;
1515
use crate::{model, NumericError};
1616

1717
/// Result of JSON-RPC method `getblockchaininfo`.

types/src/v28/raw_transactions/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use core::fmt;
44

55
use bitcoin::amount::ParseAmountError;
66
use bitcoin::hex::HexToArrayError;
7-
use internals::write_err;
87

8+
use crate::error::write_err;
99
use crate::NumericError;
1010

1111
/// Error when converting a `SubmitPackage` type into the model type.

0 commit comments

Comments
 (0)