bitcoindevkit / bitcoindevkit/rust-electrum-client
Bug: blockchain.headers.subscribe and blockchain.scripthash.subscribe method not work
- Dominant language
- Rust
- Stars
- 89
- Forks
- 82
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 1
Description
```rust
use electrum_client::{Client, ElectrumApi};
fn main() {
let client = electrum_client::raw_client::RawClient::new(("blockstream.info", 143), None).unwrap();
let r = client.block_headers_subscribe().unwrap();
// print, but just once
dbg!(r);
loop {
std::thread::sleep(std::time::Duration::from_secs(5));
let x = client.block_headers_pop().unwrap();
// always is None
dbg!(x);
}
}
```
`client.block_headers_pop()` is always None.
All clinet's jsonrpc calls use the `self.call` method. The `self.call` method constructs a request containing the id, and uses [`self.recv`](https://github.com/bitcoindevkit/rust-electrum-client/blob/898f230081106ba0c000c4914d8d241ac063374c/src/raw_client.rs#L615) to wait for the result of the corresponding id. In `self.recv`, use [`self._reader_thread`](https://github.com/bitcoindevkit/rust-electrum-client/blob/898f230081106ba0c000c4914d8d241ac063374c/src/raw_client.rs#L475) to wait for the result of this id, and then exit, ignoring the subsequent results of the subscription method.
Since this is a synchronous library, I looked for some trace of std::thead::spawn in the code, but couldn't find it.
1. Is my calling method wrong? This is a library that has been around for a long time. I think this is the reason. If yes, is it possible to add example code? This problem is really a headache.
2. When calling the subscription method, can a channel be returned instead of putting all the results into a VecDeque, which still requires the user to constantly check whether there is new data?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.