Merge pull request #131 from tnull/2024-02-align-rustfmt
[ldk-sample] / src / convert.rs
index 7f1bf108828753df82a0a754e82c22bc332a8664..52373322c7e2b1b4eee92a9296bac5e150acf942 100644 (file)
@@ -1,4 +1,3 @@
-use bitcoin::hashes::hex::FromHex;
 use bitcoin::{Address, BlockHash, Txid};
 use lightning_block_sync::http::JsonResponse;
 use std::convert::TryInto;
@@ -68,7 +67,7 @@ impl TryInto<FeeResponse> for JsonResponse {
                                // to convert virtual-bytes into weight units.
                                Some(feerate_btc_per_kvbyte) => {
                                        Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
-                               }
+                               },
                                None => None,
                        },
                })
@@ -93,7 +92,7 @@ impl TryInto<MempoolMinFeeResponse> for JsonResponse {
                                // to convert virtual-bytes into weight units.
                                Some(feerate_btc_per_kvbyte) => {
                                        Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
-                               }
+                               },
                                None => None,
                        },
                })
@@ -111,7 +110,7 @@ impl TryInto<BlockchainInfo> for JsonResponse {
        fn try_into(self) -> std::io::Result<BlockchainInfo> {
                Ok(BlockchainInfo {
                        latest_height: self.0["blocks"].as_u64().unwrap() as usize,
-                       latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap())
+                       latest_blockhash: BlockHash::from_str(self.0["bestblockhash"].as_str().unwrap())
                                .unwrap(),
                        chain: self.0["chain"].as_str().unwrap().to_string(),
                })
@@ -141,7 +140,9 @@ impl TryInto<ListUnspentResponse> for JsonResponse {
                                amount: bitcoin::Amount::from_btc(utxo["amount"].as_f64().unwrap())
                                        .unwrap()
                                        .to_sat(),
-                               address: Address::from_str(&utxo["address"].as_str().unwrap().to_string()).unwrap(),
+                               address: Address::from_str(&utxo["address"].as_str().unwrap().to_string())
+                                       .unwrap()
+                                       .assume_checked(), // the expected network is not known at this point
                        })
                        .collect();
                Ok(ListUnspentResponse(utxos))