Skip to content

Commit 9fe42a5

Browse files
authored
Merge pull request #5 from TheBlueMatt/main
Trivial Usability Fixes
2 parents 6199433 + 01b091b commit 9fe42a5

File tree

6 files changed

+64
-41
lines changed

6 files changed

+64
-41
lines changed

Cargo.lock

Lines changed: 18 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,26 @@ edition = "2018"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
# lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
12-
lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
13-
# lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
11+
lightning = "0.0.14"
12+
lightning-block-sync = { version = "0.0.14", features = [ "rpc-client" ] }
13+
lightning-invoice = "0.5"
14+
lightning-net-tokio = "0.0.14"
15+
lightning-persister = "0.0.14"
16+
lightning-background-processor = "0.0.14"
17+
1418
base64 = "0.13.0"
1519
bitcoin = "0.26"
1620
bitcoin-bech32 = "0.7"
1721
bech32 = "0.7"
1822
hex = "0.3"
1923

20-
# lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
21-
lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
22-
# lightning = { path = "../rust-lightning/lightning" }
23-
24-
# lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], branch = "main" }
25-
lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], rev = "d4d322580994857b1222488f8467311d6db61482" }
26-
# lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client"] }
27-
28-
# lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
29-
lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
30-
# lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
31-
32-
# lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
33-
lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
34-
# lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
35-
36-
# lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
37-
lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
38-
# lightning-persister = { path = "../rust-lightning/lightning-persister" }
39-
4024
time = "0.2"
4125
rand = "0.4"
4226
serde_json = { version = "1.0" }
4327
tokio = { version = "1.0", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
28+
29+
[profile.release]
30+
panic = "abort"
31+
32+
[profile.dev]
33+
panic = "abort"

src/bitcoind_client.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ impl BitcoindClient {
6767
let http_endpoint = HttpEndpoint::for_host(host.clone()).with_port(port);
6868
let rpc_credentials =
6969
base64::encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));
70-
let bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
70+
let mut bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
71+
let _dummy = bitcoind_rpc_client
72+
.call_method::<BlockchainInfo>("getblockchaininfo", &vec![])
73+
.await
74+
.map_err(|_| {
75+
std::io::Error::new(std::io::ErrorKind::PermissionDenied,
76+
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
77+
})?;
7178
let mut fees: HashMap<Target, AtomicU32> = HashMap::new();
7279
fees.insert(Target::Background, AtomicU32::new(253));
7380
fees.insert(Target::Normal, AtomicU32::new(2000));

src/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ pub(crate) async fn poll_for_user_input(
103103
event_notifier: mpsc::Sender<()>, ldk_data_dir: String, logger: Arc<FilesystemLogger>,
104104
network: Network,
105105
) {
106-
println!("LDK startup successful. To view available commands: \"help\".\nLDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
106+
println!("LDK startup successful. To view available commands: \"help\".");
107+
println!("LDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
108+
println!("Local Node ID is {}.", channel_manager.get_our_node_id());
107109
let stdin = io::stdin();
108110
print!("> ");
109111
io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print

src/convert.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl TryInto<FeeResponse> for JsonResponse {
7272
pub struct BlockchainInfo {
7373
pub latest_height: usize,
7474
pub latest_blockhash: BlockHash,
75+
pub chain: String,
7576
}
7677

7778
impl TryInto<BlockchainInfo> for JsonResponse {
@@ -81,6 +82,7 @@ impl TryInto<BlockchainInfo> for JsonResponse {
8182
latest_height: self.0["blocks"].as_u64().unwrap() as usize,
8283
latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap())
8384
.unwrap(),
85+
chain: self.0["chain"].as_str().unwrap().to_string(),
8486
})
8587
}
8688
}

src/main.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ async fn handle_ldk_events(
168168
let status = match loop_channel_manager.claim_funds(payment_preimage.unwrap()) {
169169
true => {
170170
println!(
171-
"\nEVENT: received payment from payment hash {} of {} millisatoshis",
172-
hex_utils::hex_str(&payment_hash.0),
173-
amt
174-
);
171+
"\nEVENT: received payment from payment hash {} of {} millisatoshis",
172+
hex_utils::hex_str(&payment_hash.0),
173+
amt
174+
);
175175
print!("> ");
176176
io::stdout().flush().unwrap();
177177
HTLCStatus::Succeeded
@@ -290,6 +290,22 @@ async fn start_ldk() {
290290
}
291291
};
292292

293+
// Check that the bitcoind we've connected to is running the network we expect
294+
let bitcoind_chain = bitcoind_client.get_blockchain_info().await.chain;
295+
if bitcoind_chain
296+
!= match args.network {
297+
bitcoin::Network::Bitcoin => "main",
298+
bitcoin::Network::Testnet => "test",
299+
bitcoin::Network::Regtest => "regtest",
300+
bitcoin::Network::Signet => "signet",
301+
} {
302+
println!(
303+
"Chain argument ({}) didn't match bitcoind chain ({})",
304+
args.network, bitcoind_chain
305+
);
306+
return;
307+
}
308+
293309
// ## Setup
294310
// Step 1: Initialize the FeeEstimator
295311

0 commit comments

Comments
 (0)