Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,4 @@ jobs:
- name: Run all tests
run: |
export BUNDLETOOL_PATH="$HOME/bundletool.jar"
cargo update -p jsonrpsee-utils --precise 0.2.0-alpha.3
cargo test --all
10 changes: 1 addition & 9 deletions docs/using-subxt-with-bevy.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,4 @@ To build AAB and run it on the device using the command. If you want to build an
crossbundle run android --aab
# or
crossbundle run apple --aab
```

## Known issues

You can face the problem with jsonrpsee-utils library used in subxt. One of the solutions is to downgrade the version. Use the command below:

```sh
cargo update -p jsonrpsee-utils --precise 0.2.0-alpha.3
```
```
5 changes: 3 additions & 2 deletions examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ edition = "2021"
crossbow = { version = "0.1.0", path = "../../" }
log = "0.4"
anyhow = "1.0"
substrate-subxt = "0.15"
tokio = { version = "1.2", features = ["sync", "macros"] }
subxt = "0.19"
tokio = { version = "1.17", features = ["sync", "macros", "rt-multi-thread"] }
bevy = { version = "0.6.0", features = ["mp3"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }

[package.metadata]
app_name = "Bevy Explorer"
Expand Down
Binary file added examples/bevy-explorer/res/metadata.scale
Binary file not shown.
65 changes: 39 additions & 26 deletions examples/bevy-explorer/src/explorer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use bevy::{prelude::*, tasks::AsyncComputeTaskPool};
use substrate_subxt::{ClientBuilder, KusamaRuntime};
use subxt::{ClientBuilder, DefaultConfig, DefaultExtra};
use tokio::sync::mpsc;

#[subxt::subxt(runtime_metadata_path = "res/metadata.scale")]
pub mod bevy_explorer {}

#[cfg(not(target_os = "android"))]
pub const TEXT_FONT_SIZE: f32 = 30.0;
#[cfg(target_os = "android")]
Expand All @@ -23,31 +26,41 @@ pub fn explorer_startup(task_pool: Res<AsyncComputeTaskPool>, channel: Res<Explo
let tx = channel.tx.clone();
task_pool
.spawn(async move {
println!("Connecting to Substrate Node");
let client = ClientBuilder::<KusamaRuntime>::new()
// .set_url("wss://rpc.polkadot.io")
.set_url("ws://207.154.228.105:9944")
.build()
.await
.unwrap();
loop {
let (best, finalized) =
tokio::try_join!(client.block_hash(None), client.finalized_head()).unwrap();
let (best, finalized) =
tokio::try_join!(client.header(best), client.header(Some(finalized))).unwrap();
let best = best.unwrap();
let finalized = finalized.unwrap();
tx.send(ExplorerState {
best_block_number: best.number,
best_block_hash: best.hash().to_string(),
best_block_parent_hash: best.parent_hash.to_string(),
finalized_block_number: finalized.number,
finalized_block_hash: finalized.hash().to_string(),
finalized_block_parent_hash: finalized.parent_hash.to_string(),
})
.await
.unwrap();
}
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
println!("Connecting to Substrate Node");
let api = ClientBuilder::new()
.set_url("wss://rpc.polkadot.io:443")
.build()
.await
.unwrap()
.to_runtime_api::<bevy_explorer::RuntimeApi<DefaultConfig, DefaultExtra<DefaultConfig>>>();
let client = api.client.rpc();
loop {
let (block_hash, finalized_head) = tokio::try_join!(
client.block_hash(None),
client.finalized_head()
)
.unwrap();
let (best, finalized) = tokio::try_join!(
client.header(block_hash),
client.header(Some(finalized_head))
)
.unwrap();
let best = best.unwrap();
let finalized = finalized.unwrap();
tx.send(ExplorerState {
best_block_number: best.number,
best_block_hash: best.hash().to_string(),
best_block_parent_hash: best.parent_hash.to_string(),
finalized_block_number: finalized.number,
finalized_block_hash: finalized.hash().to_string(),
finalized_block_parent_hash: finalized.parent_hash.to_string(),
})
.await
.unwrap();
}
});
})
.detach();
}
Expand Down