Skip to content

Commit 44fdd58

Browse files
committed
Replace ToHex use with explicit string conversion
1 parent 53af544 commit 44fdd58

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

lightning-block-sync/src/convert.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ pub(crate) mod tests {
305305
"chainwork": chainwork.to_string()["0x".len()..],
306306
"height": height,
307307
"version": header.version.to_consensus(),
308-
"merkleroot": header.merkle_root.to_hex(),
308+
"merkleroot": header.merkle_root.to_string(),
309309
"time": header.time,
310310
"nonce": header.nonce,
311311
"bits": header.bits.to_hex(),
312-
"previousblockhash": header.prev_blockhash.to_hex(),
312+
"previousblockhash": header.prev_blockhash.to_string(),
313313
})
314314
}
315315
}
@@ -545,7 +545,7 @@ pub(crate) mod tests {
545545
fn into_block_hash_from_json_response_without_height() {
546546
let block = genesis_block(Network::Bitcoin);
547547
let response = JsonResponse(serde_json::json!({
548-
"bestblockhash": block.block_hash().to_hex(),
548+
"bestblockhash": block.block_hash().to_string(),
549549
}));
550550
match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
551551
Err(e) => panic!("Unexpected error: {:?}", e),
@@ -560,7 +560,7 @@ pub(crate) mod tests {
560560
fn into_block_hash_from_json_response_with_unexpected_blocks_type() {
561561
let block = genesis_block(Network::Bitcoin);
562562
let response = JsonResponse(serde_json::json!({
563-
"bestblockhash": block.block_hash().to_hex(),
563+
"bestblockhash": block.block_hash().to_string(),
564564
"blocks": "foo",
565565
}));
566566
match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
@@ -576,7 +576,7 @@ pub(crate) mod tests {
576576
fn into_block_hash_from_json_response_with_invalid_height() {
577577
let block = genesis_block(Network::Bitcoin);
578578
let response = JsonResponse(serde_json::json!({
579-
"bestblockhash": block.block_hash().to_hex(),
579+
"bestblockhash": block.block_hash().to_string(),
580580
"blocks": std::u64::MAX,
581581
}));
582582
match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {
@@ -592,7 +592,7 @@ pub(crate) mod tests {
592592
fn into_block_hash_from_json_response_with_height() {
593593
let block = genesis_block(Network::Bitcoin);
594594
let response = JsonResponse(serde_json::json!({
595-
"bestblockhash": block.block_hash().to_hex(),
595+
"bestblockhash": block.block_hash().to_string(),
596596
"blocks": 1,
597597
}));
598598
match TryInto::<(BlockHash, Option<u32>)>::try_into(response) {

lightning-block-sync/src/rest.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::convert::GetUtxosResponse;
88

99
use bitcoin::OutPoint;
1010
use bitcoin::hash_types::BlockHash;
11-
use bitcoin::hashes::hex::ToHex;
1211

1312
use std::convert::TryFrom;
1413
use std::convert::TryInto;
@@ -44,14 +43,14 @@ impl RestClient {
4443
impl BlockSource for RestClient {
4544
fn get_header<'a>(&'a self, header_hash: &'a BlockHash, _height: Option<u32>) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
4645
Box::pin(async move {
47-
let resource_path = format!("headers/1/{}.json", header_hash.to_hex());
46+
let resource_path = format!("headers/1/{}.json", header_hash.to_string());
4847
Ok(self.request_resource::<JsonResponse, _>(&resource_path).await?)
4948
})
5049
}
5150

5251
fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, BlockData> {
5352
Box::pin(async move {
54-
let resource_path = format!("block/{}.bin", header_hash.to_hex());
53+
let resource_path = format!("block/{}.bin", header_hash.to_string());
5554
Ok(BlockData::FullBlock(self.request_resource::<BinaryResponse, _>(&resource_path).await?))
5655
})
5756
}
@@ -73,7 +72,7 @@ impl UtxoSource for RestClient {
7372

7473
fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> {
7574
Box::pin(async move {
76-
let resource_path = format!("getutxos/{}-{}.json", outpoint.txid.to_hex(), outpoint.vout);
75+
let resource_path = format!("getutxos/{}-{}.json", outpoint.txid.to_string(), outpoint.vout);
7776
let utxo_result =
7877
self.request_resource::<JsonResponse, GetUtxosResponse>(&resource_path).await?;
7978
Ok(utxo_result.hit_bitmap_nonempty)

lightning-block-sync/src/rpc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::http::{HttpClient, HttpEndpoint, HttpError, JsonResponse};
66
use crate::gossip::UtxoSource;
77

88
use bitcoin::hash_types::BlockHash;
9-
use bitcoin::hashes::hex::ToHex;
109
use bitcoin::OutPoint;
1110

1211
use std::sync::Mutex;
@@ -120,14 +119,14 @@ impl RpcClient {
120119
impl BlockSource for RpcClient {
121120
fn get_header<'a>(&'a self, header_hash: &'a BlockHash, _height: Option<u32>) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
122121
Box::pin(async move {
123-
let header_hash = serde_json::json!(header_hash.to_hex());
122+
let header_hash = serde_json::json!(header_hash.to_string());
124123
Ok(self.call_method("getblockheader", &[header_hash]).await?)
125124
})
126125
}
127126

128127
fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, BlockData> {
129128
Box::pin(async move {
130-
let header_hash = serde_json::json!(header_hash.to_hex());
129+
let header_hash = serde_json::json!(header_hash.to_string());
131130
let verbosity = serde_json::json!(0);
132131
Ok(BlockData::FullBlock(self.call_method("getblock", &[header_hash, verbosity]).await?))
133132
})
@@ -150,7 +149,7 @@ impl UtxoSource for RpcClient {
150149

151150
fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> {
152151
Box::pin(async move {
153-
let txid_param = serde_json::json!(outpoint.txid.to_hex());
152+
let txid_param = serde_json::json!(outpoint.txid.to_string());
154153
let vout_param = serde_json::json!(outpoint.vout);
155154
let include_mempool = serde_json::json!(false);
156155
let utxo_opt: serde_json::Value = self.call_method(

lightning/src/ln/chan_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,9 @@ mod tests {
19801980
assert_eq!(tx.built.transaction.output.len(), 3);
19811981
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh());
19821982
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh());
1983-
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex(),
1983+
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex_string(),
19841984
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
1985-
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex(),
1985+
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_v0_p2wsh().to_hex_string(),
19861986
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
19871987

19881988
// Generate broadcaster output and received and offered HTLC outputs, with anchors
@@ -1992,9 +1992,9 @@ mod tests {
19921992
assert_eq!(tx.built.transaction.output.len(), 5);
19931993
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh());
19941994
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh());
1995-
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex(),
1995+
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex_string(),
19961996
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
1997-
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex(),
1997+
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_v0_p2wsh().to_hex_string(),
19981998
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
19991999
}
20002000

lightning/src/ln/channel.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use core::convert::TryInto;
5353
use core::ops::Deref;
5454
#[cfg(any(test, fuzzing, debug_assertions))]
5555
use crate::sync::Mutex;
56-
use bitcoin::hashes::hex::ToHex;
5756
use crate::sign::type_resolver::ChannelSignerType;
5857

5958
#[cfg(test)]
@@ -4474,12 +4473,12 @@ impl<SP: Deref> Channel<SP> where
44744473
assert_eq!(self.context.channel_state & ChannelState::ShutdownComplete as u32, 0);
44754474

44764475
if !script::is_bolt2_compliant(&msg.scriptpubkey, their_features) {
4477-
return Err(ChannelError::Warn(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_bytes().to_hex())));
4476+
return Err(ChannelError::Warn(format!("Got a nonstandard scriptpubkey ({}) from remote peer", msg.scriptpubkey.to_hex_string())));
44784477
}
44794478

44804479
if self.context.counterparty_shutdown_scriptpubkey.is_some() {
44814480
if Some(&msg.scriptpubkey) != self.context.counterparty_shutdown_scriptpubkey.as_ref() {
4482-
return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_bytes().to_hex())));
4481+
return Err(ChannelError::Warn(format!("Got shutdown request with a scriptpubkey ({}) which did not match their previous scriptpubkey.", msg.scriptpubkey.to_hex_string())));
44834482
}
44844483
} else {
44854484
self.context.counterparty_shutdown_scriptpubkey = Some(msg.scriptpubkey.clone());

lightning/src/routing/utxo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl PendingChecks {
464464
if script_pubkey != expected_script {
465465
return Err(LightningError{
466466
err: format!("Channel announcement key ({}) didn't match on-chain script ({})",
467-
expected_script.to_hex(), script_pubkey.to_hex()),
467+
expected_script.to_hex_string(), script_pubkey.to_hex_string()),
468468
action: ErrorAction::IgnoreError
469469
});
470470
}

lightning/src/util/persist.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use core::cmp;
1212
use core::convert::{TryFrom, TryInto};
1313
use core::ops::Deref;
14-
use bitcoin::hashes::hex::ToHex;
1514
use core::str::FromStr;
1615
use bitcoin::{BlockHash, Txid};
1716

@@ -195,7 +194,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
195194
// just shut down the node since we're not retrying persistence!
196195

197196
fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChannelSigner>, _update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
198-
let key = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
197+
let key = format!("{}_{}", funding_txo.txid.to_string(), funding_txo.index);
199198
match self.write(
200199
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
201200
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -207,7 +206,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore> Persist<ChannelSign
207206
}
208207

209208
fn update_persisted_channel(&self, funding_txo: OutPoint, _update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>, _update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
210-
let key = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
209+
let key = format!("{}_{}", funding_txo.txid.to_string(), funding_txo.index);
211210
match self.write(
212211
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
213212
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -814,7 +813,7 @@ impl TryFrom<&MonitorName> for OutPoint {
814813

815814
impl From<OutPoint> for MonitorName {
816815
fn from(value: OutPoint) -> Self {
817-
MonitorName(format!("{}_{}", value.txid.to_hex(), value.index))
816+
MonitorName(format!("{}_{}", value.txid.to_string(), value.index))
818817
}
819818
}
820819

0 commit comments

Comments
 (0)