Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions docs/using-subxt-with-bevy.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

```sh
[dependencies]
substrate-subxt = "0.15"
substrate-subxt = "0.21"
bevy = "0.7.0"
```

## ❗ Bevy explorer example

To learn how to use subxt with bevy engine, you can go to the examples/bevy-explorer or install bevy explorer template. Follow next steps:
To learn how to use subxt with bevy engine, you can go to the [examples/bevy-explorer](https://github.com/dodorare/crossbow/tree/main/examples/bevy-explorer) or install bevy explorer template. Follow next steps:

1. Install cargo-generate:

Expand Down
4 changes: 2 additions & 2 deletions examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition = "2021"
crossbow = { version = "0.1.0", path = "../../" }
log = "0.4"
anyhow = "1.0"
subxt = "0.20"
subxt = "0.21"
tokio = { version = "1.17", features = ["sync", "macros", "rt-multi-thread"] }
bevy = { version = "0.7.0", features = ["mp3"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] }
jsonrpsee = { version = "0.9.0", features = ["async-client", "client-ws-transport"] }
jsonrpsee = { version = "0.10.1", features = ["async-client", "client-ws-transport"] }

[package.metadata]
app_name = "Bevy Explorer"
Expand Down
33 changes: 17 additions & 16 deletions examples/bevy-explorer/src/explorer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bevy::{prelude::*, tasks::AsyncComputeTaskPool};
use subxt::{ClientBuilder, DefaultConfig, SubstrateExtrinsicParams};
use tokio::sync::mpsc;

use jsonrpsee::{
client_transport::ws::{Uri, WsTransportClientBuilder},
core::client::{CertificateStore, ClientBuilder as RpcClientBuilder},
use jsonrpsee::core::client::CertificateStore;
use subxt::{
rpc::{RpcClientBuilder, Uri, WsTransportClientBuilder},
ClientBuilder, DefaultConfig, SubstrateExtrinsicParams,
};
use tokio::sync::mpsc;

#[subxt::subxt(runtime_metadata_path = "res/metadata.scale")]
pub mod bevy_explorer {}
Expand All @@ -14,6 +13,8 @@ pub mod bevy_explorer {}
pub const TEXT_FONT_SIZE: f32 = 30.0;
#[cfg(target_os = "android")]
pub const TEXT_FONT_SIZE: f32 = 30.0;
pub const URL: &str = "wss://rpc.polkadot.io:443";
pub const BUFFER: usize = 1;

pub struct ExplorerStateChannel {
pub tx: mpsc::Sender<ExplorerState>,
Expand All @@ -22,32 +23,32 @@ pub struct ExplorerStateChannel {

impl ExplorerStateChannel {
pub fn new() -> Self {
let (tx, rx) = mpsc::channel(1);
let (tx, rx) = mpsc::channel(BUFFER);
Self { tx, rx }
}
}

pub fn explorer_startup(task_pool: Res<AsyncComputeTaskPool>, channel: Res<ExplorerStateChannel>) {
let tx = channel.tx.clone();
#[cfg(target_os = "android")]
let certificate = CertificateStore::WebPki;
#[cfg(not(target_os = "android"))]
let certificate = CertificateStore::Native;

task_pool
.spawn(async move {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
println!("Connecting to Substrate Node");

let url: Uri = "wss://rpc.polkadot.io:443".parse().unwrap();
info!("Connecting to Substrate Node");
let url: Uri = URL.parse().unwrap();
let (sender, receiver) = WsTransportClientBuilder::default()
// This thing needed to make it work on android
.certificate_store(CertificateStore::WebPki)
.certificate_store(certificate)
.build(url)
.await
.unwrap();
let rpc_client = RpcClientBuilder::default()
.max_notifs_per_subscription(4096)
.build(sender, receiver);
let rpc_client = RpcClientBuilder::default().build(sender, receiver);

let api = ClientBuilder::new()
// .set_url("wss://rpc.polkadot.io:443")
.set_client(rpc_client)
.build()
.await
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy-explorer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::{core::FixedTimestep, prelude::*};
use explorer::*;

fn main() {
println!("Initialization.");
info!("Initialization.");
std::thread::sleep(std::time::Duration::from_secs(2));
App::new()
.insert_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9)))
Expand Down