Skip to content

Commit bfc8493

Browse files
committed
Replace ToHex with DisplayHex
1 parent 44fdd58 commit bfc8493

File tree

8 files changed

+22
-29
lines changed

8 files changed

+22
-29
lines changed

lightning-block-sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rpc-client = [ "serde_json", "chunked_transfer" ]
1919

2020
[dependencies]
2121
bitcoin = "0.30.2"
22+
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
2223
lightning = { version = "0.0.118", path = "../lightning" }
2324
tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true }
2425
serde_json = { version = "1.0", optional = true }

lightning-block-sync/src/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ pub(crate) mod tests {
292292
use super::*;
293293
use bitcoin::blockdata::constants::genesis_block;
294294
use bitcoin::hashes::Hash;
295-
use bitcoin::hashes::hex::ToHex;
296295
use bitcoin::network::constants::Network;
296+
use hex::DisplayHex;
297297
use serde_json::value::Number;
298298
use serde_json::Value;
299299

@@ -302,13 +302,13 @@ pub(crate) mod tests {
302302
fn from(data: BlockHeaderData) -> Self {
303303
let BlockHeaderData { chainwork, height, header } = data;
304304
serde_json::json!({
305-
"chainwork": chainwork.to_string()["0x".len()..],
305+
"chainwork": chainwork.to_be_bytes().as_hex().to_string(),
306306
"height": height,
307307
"version": header.version.to_consensus(),
308308
"merkleroot": header.merkle_root.to_string(),
309309
"time": header.time,
310310
"nonce": header.nonce,
311-
"bits": header.bits.to_hex(),
311+
"bits": header.bits.to_consensus().to_be_bytes().as_hex().to_string(),
312312
"previousblockhash": header.prev_blockhash.to_string(),
313313
})
314314
}

lightning/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1717

1818
[features]
1919
# Internal test utilities exposed to other repo crates
20-
_test_utils = ["hex", "regex", "bitcoin/bitcoinconsensus"]
20+
_test_utils = ["regex", "bitcoin/bitcoinconsensus"]
2121
# Unlog messages superior at targeted level.
2222
max_level_off = []
2323
max_level_error = []
@@ -43,14 +43,13 @@ default = ["std", "grind_signatures"]
4343
bitcoin = { version = "0.30.2", default-features = false, features = ["secp-recovery"] }
4444

4545
hashbrown = { version = "0.8", optional = true }
46-
hex = { package = "hex-conservative", version = "0.1.1", default-features = false, optional = true }
46+
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
4747
regex = { version = "1.5.6", optional = true }
4848
backtrace = { version = "0.3", optional = true }
4949

5050
core2 = { version = "0.3.0", optional = true, default-features = false }
5151

5252
[dev-dependencies]
53-
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
5453
regex = "1.5.6"
5554

5655
[dev-dependencies.bitcoin]

lightning/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern crate bitcoin;
6666
#[cfg(any(test, feature = "std"))]
6767
extern crate core;
6868

69-
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
69+
extern crate hex;
7070
#[cfg(any(test, feature = "_test_utils"))] extern crate regex;
7171

7272
#[cfg(not(feature = "std"))] extern crate core2;

lightning/src/ln/channel_id.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use crate::ln::msgs::DecodeError;
1313
use crate::sign::EntropySource;
1414
use crate::util::ser::{Readable, Writeable, Writer};
1515

16-
use bitcoin::hashes::hex::ToHex;
17-
1816
use crate::io;
19-
use crate::prelude::*;
2017
use core::fmt;
2118
use core::ops::Deref;
2219

@@ -79,12 +76,6 @@ impl Readable for ChannelId {
7976
}
8077
}
8178

82-
impl ToHex for ChannelId {
83-
fn to_hex(&self) -> String {
84-
self.0.to_hex()
85-
}
86-
}
87-
8879
impl fmt::Display for ChannelId {
8980
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9081
crate::util::logger::DebugBytes(&self.0).fmt(f)
@@ -93,17 +84,18 @@ impl fmt::Display for ChannelId {
9384

9485
#[cfg(test)]
9586
mod tests {
87+
use hex::DisplayHex;
88+
9689
use crate::ln::ChannelId;
9790
use crate::util::ser::{Readable, Writeable};
9891
use crate::util::test_utils;
99-
use bitcoin::hashes::hex::ToHex;
10092
use crate::prelude::*;
10193
use crate::io;
10294

10395
#[test]
10496
fn test_channel_id_v1_from_funding_txid() {
10597
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
106-
assert_eq!(channel_id.to_hex(), "0202020202020202020202020202020202020202020202020202020202020203");
98+
assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
10799
}
108100

109101
#[test]

lightning/src/ln/msgs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ impl_writeable_msg!(GossipTimestampFilter, {
28002800
mod tests {
28012801
use std::convert::TryFrom;
28022802
use bitcoin::{Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut};
2803-
use hex;
2803+
use hex::DisplayHex;
28042804
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
28052805
use crate::ln::ChannelId;
28062806
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
@@ -3462,7 +3462,7 @@ mod tests {
34623462
funding_pubkey: pubkey_1,
34633463
};
34643464
let encoded_value = splice.encode();
3465-
assert_eq!(hex::encode(encoded_value), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240000007d000000000031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
3465+
assert_eq!(encoded_value.as_hex().to_string(), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240000007d000000000031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
34663466
}
34673467

34683468
#[test]
@@ -3472,7 +3472,7 @@ mod tests {
34723472
initiator: 1,
34733473
};
34743474
let encoded_value = stfu.encode();
3475-
assert_eq!(hex::encode(encoded_value), "020202020202020202020202020202020202020202020202020202020202020201");
3475+
assert_eq!(encoded_value.as_hex().to_string(), "020202020202020202020202020202020202020202020202020202020202020201");
34763476
}
34773477

34783478
#[test]
@@ -3486,7 +3486,7 @@ mod tests {
34863486
funding_pubkey: pubkey_1,
34873487
};
34883488
let encoded_value = splice.encode();
3489-
assert_eq!(hex::encode(encoded_value), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
3489+
assert_eq!(encoded_value.as_hex().to_string(), "02020202020202020202020202020202020202020202020202020202020202026fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000001e240031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f");
34903490
}
34913491

34923492
#[test]
@@ -3495,7 +3495,7 @@ mod tests {
34953495
channel_id: ChannelId::from_bytes([2; 32]),
34963496
};
34973497
let encoded_value = splice.encode();
3498-
assert_eq!(hex::encode(encoded_value), "0202020202020202020202020202020202020202020202020202020202020202");
3498+
assert_eq!(encoded_value.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020202");
34993499
}
35003500

35013501
#[test]

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ use bitcoin::secp256k1::{PublicKey,SecretKey};
2222
use bitcoin::secp256k1::ecdh::SharedSecret;
2323
use bitcoin::secp256k1;
2424

25+
use hex::DisplayHex;
26+
2527
use crate::util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
2628
use crate::util::crypto::hkdf_extract_expand_twice;
2729
use crate::util::ser::VecWriter;
28-
use bitcoin::hashes::hex::ToHex;
2930

3031
use core::ops::Deref;
3132

@@ -235,7 +236,7 @@ impl PeerChannelEncryptor {
235236
}
236237

237238
let their_pub = match PublicKey::from_slice(&act[1..34]) {
238-
Err(_) => return Err(LightningError{err: format!("Invalid public key {}", &act[1..34].to_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
239+
Err(_) => return Err(LightningError{err: format!("Invalid public key {}", &act[1..34].as_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
239240
Ok(key) => key,
240241
};
241242

@@ -394,7 +395,7 @@ impl PeerChannelEncryptor {
394395
PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?;
395396
self.their_node_id = Some(match PublicKey::from_slice(&their_node_id) {
396397
Ok(key) => key,
397-
Err(_) => return Err(LightningError{err: format!("Bad node_id from peer, {}", &their_node_id.to_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
398+
Err(_) => return Err(LightningError{err: format!("Bad node_id from peer, {}", &their_node_id.as_hex()), action: msgs::ErrorAction::DisconnectPeer{ msg: None }}),
398399
});
399400

400401
let mut sha = Sha256::engine();

lightning/src/routing/utxo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
1616
use bitcoin::TxOut;
1717
use bitcoin::blockdata::constants::ChainHash;
18-
use bitcoin::hashes::hex::ToHex;
18+
19+
use hex::DisplayHex;
1920

2021
use crate::events::MessageSendEvent;
2122
use crate::ln::chan_utils::make_funding_redeemscript_from_slices;
2223
use crate::ln::msgs::{self, LightningError, ErrorAction};
2324
use crate::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
2425
use crate::util::logger::{Level, Logger};
25-
use crate::util::ser::Writeable;
2626

2727
use crate::prelude::*;
2828

@@ -473,7 +473,7 @@ impl PendingChecks {
473473
Err(UtxoLookupError::UnknownChain) => {
474474
Err(LightningError {
475475
err: format!("Channel announced on an unknown chain ({})",
476-
msg.chain_hash.encode().to_hex()),
476+
msg.chain_hash.to_bytes().as_hex()),
477477
action: ErrorAction::IgnoreError
478478
})
479479
},

0 commit comments

Comments
 (0)