Skip to content

Commit d64d557

Browse files
committed
electrsd: fix README examples
The previous examples would not run.
1 parent 3ec5e81 commit d64d557

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

electrsd/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ useful in integration testing environment.
88

99
```rust
1010
let bitcoind = bitcoind::BitcoinD::new("/usr/local/bin/bitcoind").unwrap();
11-
let electrsd = electrsd::ElectrsD::new("/usr/local/bin/electrs", bitcoind).unwrap();
11+
let electrsd = electrsd::ElectrsD::new("/usr/local/bin/electrs", &bitcoind).unwrap();
1212
let header = electrsd.client.block_headers_subscribe().unwrap();
1313
assert_eq!(header.height, 0);
1414
```
@@ -24,10 +24,19 @@ electrsd = { version= "0.23", features = ["bitcoind_30_2", "bitcoin_download", "
2424
Then use it:
2525

2626
```rust
27-
let bitcoind_exe = bitcoind::downloaded_exe_path().expect("bitcoind version feature must be enabled");
28-
let bitcoind = bitcoind::BitcoinD::new(bitcoind_exe).unwrap();
29-
let electrs_exe = electrsd::downloaded_exe_path().expect("electrs version feature must be enabled");
30-
let electrsd = electrsd::ElectrsD::new(electrs_exe, bitcoind).unwrap();
27+
use bitcoind::P2P;
28+
use electrsd::electrum_client::ElectrumApi;
29+
30+
fn main() {
31+
let bitcoind_exe = bitcoind::downloaded_exe_path().expect("bitcoind version feature must be enabled");
32+
let mut conf = bitcoind::Conf::default();
33+
conf.p2p = P2P::Yes;
34+
let bitcoind = bitcoind::BitcoinD::with_conf(&bitcoind_exe, &conf).unwrap();
35+
let electrs_exe = electrsd::downloaded_exe_path().expect("electrs version feature must be enabled");
36+
let electrsd = electrsd::ElectrsD::new(&electrs_exe, &bitcoind).unwrap();
37+
let header = electrsd.client.block_headers_subscribe().unwrap();
38+
assert_eq!(header.height, 1);
39+
}
3140
```
3241

3342
When the `ELECTRSD_DOWNLOAD_ENDPOINT`/`BITCOIND_DOWNLOAD_ENDPOINT` environment variables are set,
@@ -39,9 +48,12 @@ When you don't use the auto-download feature you have the following options:
3948
- provide the `electrs` executable via the `ELECTRS_EXEC` env var
4049

4150
```rust
42-
if let Ok(exe_path) = electrsd::exe_path() {
43-
let electrsd = electrsd::electrsD::new(exe_path).unwrap();
44-
}
51+
use bitcoind::P2P;
52+
53+
let mut conf = bitcoind::Conf::default();
54+
conf.p2p = P2P::Yes;
55+
let bitcoind = bitcoind::BitcoinD::with_conf(bitcoind::exe_path().unwrap(), &conf).unwrap();
56+
let electrsd = electrsd::ElectrsD::new(electrsd::exe_path().unwrap(), &bitcoind).unwrap();
4557
```
4658

4759
Startup options could be configured via the `Conf` struct using `electrsD::with_conf` or `electrsD::from_downloaded_with_conf`.

0 commit comments

Comments
 (0)