Skip to content

Commit fbb0e40

Browse files
committed
Merge rust-bitcoin#4628: Use new type names instead of deprecated aliases
f746aec Use NumberOfBlocks in rustdoc (Tobin C. Harding) dc5249a Use new type names instead of deprecated aliases (Tobin C. Harding) Pull request description: Recently we changed the names of some locktime types but kept aliases to the original names. To assist with ongoing maintenance lets use the new names already. ~Internal change only.~ Added a patch that does the same in some rustdocs. ACKs for top commit: jamillambert: ACK f746aec apoelstra: ACK f746aec; successfully ran local tests Tree-SHA512: f3304fcc62069f72fa6c49b4aee5579e4ef6e81cb466b9c7e79ddd1a04b63f2f4d3f0ffdcb9303c3bee2501beead3fceb9be79cefe35d7615223738291535152
2 parents f746aec + ea73194 commit fbb0e40

25 files changed

+915
-730
lines changed

Cargo-minimal.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ name = "bitcoin-fuzz"
7777
version = "0.0.1"
7878
dependencies = [
7979
"bitcoin",
80+
"bitcoin-p2p-messages",
8081
"honggfuzz",
8182
"serde",
8283
"serde_json",
@@ -109,6 +110,15 @@ dependencies = [
109110
[[package]]
110111
name = "bitcoin-p2p-messages"
111112
version = "0.1.0"
113+
dependencies = [
114+
"bitcoin",
115+
"bitcoin-internals",
116+
"bitcoin-io 0.2.0",
117+
"bitcoin-units",
118+
"bitcoin_hashes 0.16.0",
119+
"hex-conservative 0.3.0",
120+
"hex_lit",
121+
]
112122

113123
[[package]]
114124
name = "bitcoin-primitives"

Cargo-recent.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ name = "bitcoin-fuzz"
7676
version = "0.0.1"
7777
dependencies = [
7878
"bitcoin",
79+
"bitcoin-p2p-messages",
7980
"honggfuzz",
8081
"serde",
8182
"serde_json",
@@ -108,6 +109,15 @@ dependencies = [
108109
[[package]]
109110
name = "bitcoin-p2p-messages"
110111
version = "0.1.0"
112+
dependencies = [
113+
"bitcoin",
114+
"bitcoin-internals",
115+
"bitcoin-io 0.2.0",
116+
"bitcoin-units",
117+
"bitcoin_hashes 0.16.0",
118+
"hex-conservative 0.3.0",
119+
"hex_lit",
120+
]
111121

112122
[[package]]
113123
name = "bitcoin-primitives"

bitcoin/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ rustdoc-args = ["--cfg", "docsrs"]
5656
[[example]]
5757
name = "bip32"
5858

59-
[[example]]
60-
name = "handshake"
61-
required-features = ["rand-std"]
62-
6359
[[example]]
6460
name = "ecdsa-psbt"
6561
required-features = ["std", "bitcoinconsensus"]

bitcoin/src/bip32.rs

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ impl ChildNumber {
193193
ChildNumber::Hardened { index: idx } => ChildNumber::from_hardened_idx(idx + 1),
194194
}
195195
}
196+
197+
/// Formats the child number using the provided formatting function.
198+
///
199+
/// For hardened child numbers appends a `'` or `hardened_alt_suffix`
200+
/// depending on the formatter.
201+
fn format_with<F>(
202+
&self,
203+
f: &mut fmt::Formatter,
204+
format_fn: F,
205+
hardened_alt_suffix: &str,
206+
) -> fmt::Result
207+
where
208+
F: Fn(&u32, &mut fmt::Formatter) -> fmt::Result,
209+
{
210+
match *self {
211+
ChildNumber::Hardened { index } => {
212+
format_fn(&index, f)?;
213+
let alt = f.alternate();
214+
f.write_str(if alt { hardened_alt_suffix } else { "'" })
215+
}
216+
ChildNumber::Normal { index } => format_fn(&index, f),
217+
}
218+
}
196219
}
197220

198221
impl From<u32> for ChildNumber {
@@ -216,14 +239,31 @@ impl From<ChildNumber> for u32 {
216239

217240
impl fmt::Display for ChildNumber {
218241
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
219-
match *self {
220-
ChildNumber::Hardened { index } => {
221-
fmt::Display::fmt(&index, f)?;
222-
let alt = f.alternate();
223-
f.write_str(if alt { "h" } else { "'" })
224-
}
225-
ChildNumber::Normal { index } => fmt::Display::fmt(&index, f),
226-
}
242+
self.format_with(f, fmt::Display::fmt, "h")
243+
}
244+
}
245+
246+
impl fmt::LowerHex for ChildNumber {
247+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
248+
self.format_with(f, fmt::LowerHex::fmt, "h")
249+
}
250+
}
251+
252+
impl fmt::UpperHex for ChildNumber {
253+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
254+
self.format_with(f, fmt::UpperHex::fmt, "H")
255+
}
256+
}
257+
258+
impl fmt::Octal for ChildNumber {
259+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
260+
self.format_with(f, fmt::Octal::fmt, "h")
261+
}
262+
}
263+
264+
impl fmt::Binary for ChildNumber {
265+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
266+
self.format_with(f, fmt::Binary::fmt, "h")
227267
}
228268
}
229269

@@ -1123,6 +1163,54 @@ mod tests {
11231163
assert_eq!(format!("{:#}", path), "84h/0h/0h/0/0");
11241164
}
11251165

1166+
#[test]
1167+
fn test_lowerhex_formatting() {
1168+
let normal = Normal { index: 42 };
1169+
let hardened = Hardened { index: 42 };
1170+
1171+
assert_eq!(format!("{:x}", normal), "2a");
1172+
assert_eq!(format!("{:#x}", normal), "0x2a");
1173+
1174+
assert_eq!(format!("{:x}", hardened), "2a'");
1175+
assert_eq!(format!("{:#x}", hardened), "0x2ah");
1176+
}
1177+
1178+
#[test]
1179+
fn test_upperhex_formatting() {
1180+
let normal = Normal { index: 42 };
1181+
let hardened = Hardened { index: 42 };
1182+
1183+
assert_eq!(format!("{:X}", normal), "2A");
1184+
assert_eq!(format!("{:#X}", normal), "0x2A");
1185+
1186+
assert_eq!(format!("{:X}", hardened), "2A'");
1187+
assert_eq!(format!("{:#X}", hardened), "0x2AH");
1188+
}
1189+
1190+
#[test]
1191+
fn test_octal_formatting() {
1192+
let normal = Normal { index: 42 };
1193+
let hardened = Hardened { index: 42 };
1194+
1195+
assert_eq!(format!("{:o}", normal), "52");
1196+
assert_eq!(format!("{:#o}", normal), "0o52");
1197+
1198+
assert_eq!(format!("{:o}", hardened), "52'");
1199+
assert_eq!(format!("{:#o}", hardened), "0o52h");
1200+
}
1201+
1202+
#[test]
1203+
fn test_binary_formatting() {
1204+
let normal = Normal { index: 42 };
1205+
let hardened = Hardened { index: 42 };
1206+
1207+
assert_eq!(format!("{:b}", normal), "101010");
1208+
assert_eq!(format!("{:#b}", normal), "0b101010");
1209+
1210+
assert_eq!(format!("{:b}", hardened), "101010'");
1211+
assert_eq!(format!("{:#b}", hardened), "0b101010h");
1212+
}
1213+
11261214
#[test]
11271215
fn parse_derivation_path_out_of_range() {
11281216
let invalid_path = "2147483648";

bitcoin/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ extern crate serde;
9494
mod internal_macros;
9595

9696
#[macro_use]
97-
pub mod p2p;
9897
pub mod address;
9998
pub mod bip152;
10099
pub mod bip158;

bitcoin/src/p2p/deser.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)