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
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
3 changes: 0 additions & 3 deletions crossbundle/cli/src/commands/build/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ pub struct AndroidBuildCommand {
/// Generating aab. By default crossbow generating apk
#[clap(long)]
pub aab: bool,
// Install bundletool in home directory
#[clap(long)]
pub bundletool_install: bool,
/// Path to the signing key
#[clap(long, requires_all = &["sign-key-pass", "sign-key-alias"])]
pub sign_key_path: Option<PathBuf>,
Expand Down
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
```
```
13 changes: 5 additions & 8 deletions examples/bevy-2d/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use bevy::{
log::{Level, LogSettings},
prelude::*,
};
use bevy::prelude::*;

fn main() {
println!("Initialization.");
std::thread::sleep(std::time::Duration::from_secs(2));
App::new()
.insert_resource(LogSettings {
level: Level::DEBUG,
filter: "wgpu=debug,wgpu_hal=debug,bevy_render=info".to_string(),
})
// .insert_resource(LogSettings {
// level: Level::DEBUG,
// filter: "wgpu=debug,wgpu_hal=debug,bevy_render=info".to_string(),
// })
.add_plugins(DefaultPlugins)
.add_startup_system(audio)
.add_startup_system(icon)
Expand Down
7 changes: 5 additions & 2 deletions examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ 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.20"
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"] }
jsonrpsee = { version = "0.9.0", features = ["async-client", "client-ws-transport"] }

[package.metadata]
app_name = "Bevy Explorer"
version_code = 1
target_sdk_version = 30
icon = "ic_launcher"

Expand Down
Binary file added examples/bevy-explorer/res/metadata.scale
Binary file not shown.
83 changes: 57 additions & 26 deletions examples/bevy-explorer/src/explorer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use bevy::{prelude::*, tasks::AsyncComputeTaskPool};
use substrate_subxt::{ClientBuilder, KusamaRuntime};
use subxt::{ClientBuilder, DefaultConfig, SubstrateExtrinsicParams};
use tokio::sync::mpsc;

use jsonrpsee::{
client_transport::ws::{Uri, WsTransportClientBuilder},
core::client::{CertificateStore, ClientBuilder as RpcClientBuilder},
};

#[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 +31,54 @@ 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 url: Uri = "wss://rpc.polkadot.io:443".parse().unwrap();
let (sender, receiver) = WsTransportClientBuilder::default()
// This thing needed to make it work on android
.certificate_store(CertificateStore::WebPki)
.build(url)
.await
.unwrap();
let rpc_client = RpcClientBuilder::default()
.max_notifs_per_subscription(4096)
.build(sender, receiver);

let api = ClientBuilder::new()
// .set_url("wss://rpc.polkadot.io:443")
.set_client(rpc_client)
.build()
.await
.unwrap()
.to_runtime_api::<bevy_explorer::RuntimeApi<
DefaultConfig,
SubstrateExtrinsicParams<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