Skip to content

Commit

Permalink
Merge pull request #2 from niklasad1/na-impl-subxt-rpc-client
Browse files Browse the repository at this point in the history
feat: implement subxt rpc client trait
  • Loading branch information
niklasad1 authored Dec 12, 2023
2 parents cf2684e + 104ff61 commit cf67a26
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 85 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
120 changes: 120 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Continuous integration

on:
push:
branches:
- master
tags:
- v*
paths-ignore:
- 'README.md'
pull_request:
branches:
- master

jobs:
check-style:
name: Check style
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4.1.1

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true
components: clippy, rustfmt

- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.1

- name: Cargo fmt
uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check

- name: Check clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features

check-docs:
name: Check rustdoc
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4.1.1

- name: Install Rust nightly toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: nightly
override: true

- name: Check rustdoc
run: RUSTDOCFLAGS="--cfg docsrs --deny rustdoc::broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items --all-features

check-code:
name: Check
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4.1.1

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- name: Install cargo-hack
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-hack
version: 0.5

- name: Install cargo-machete
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-machete
version: 0.5

- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.1

- name: Cargo check all targets and features
run: cargo hack check --workspace --each-feature --all-targets

- name: Check unused dependencies
run: cargo machete

tests_ubuntu:
name: Run tests Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4.1.1

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.1

- name: Cargo test
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --workspace

17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.28"
futures = "0.3.29"
jsonrpsee = { version = "0.20.1", features = ["ws-client"] }
serde_json = "1.0.107"
tokio = { version = "1.32.0", features = ["full"] }
tokio-retry = "0.3.0"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
serde_json = { version = "1", features = ["raw_value"] }
tokio = { version = "1.35", features = ["rt-multi-thread", "sync"] }
tokio-stream = "0.1"
tokio-retry = "0.3"
tracing = "0.1"

subxt = { version = "0.33", optional = true }

[dev-dependencies]
jsonrpsee = { version = "0.20.1", features = ["server"] }
anyhow = "1"
anyhow = "1"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# reconnecting-jsonrpsee-ws-client

Wrapper crate over the jsonrpsee ws client which automatically reconnects under the hood
without that the user has to restart it manually by re-transmitting pending calls
and re-establish subscriptions that where closed when the connection was terminated.

This is crate is temporary fix for subxt because it's not easy to implement
reconnect-logic on-top it at the moment.

The tricky part is subscription which may loose a few notifications then re-connecting
where it's not possible to know which ones.
Lost subscription notifications may be very important to know in some scenarios then
this crate is not recommended.

## Example

```rust
let client = ReconnectingWsClient::new(
"ws://example.com",
ExponentialBackoff::from_millis(10),
PingConfig::Enabled(Duration::from_secs(6))
).await.unwrap();
let mut sub = client.subscribe("subscribe_lo".to_string(), rpc_params![], "unsubscribe_lo".to_string()).await.unwrap();
let msg = sub.recv().await.unwrap();
```
Loading

0 comments on commit cf67a26

Please sign in to comment.