Skip to content
Open
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
88 changes: 88 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

on:
merge_group:
pull_request:
push:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
typos:
name: Check Typos
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Typos
uses: crate-ci/typos@v1.34.0

format:
name: Check Formatting
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain with rustfmt
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run cargo fmt --check
run: cargo fmt --all -- --check

lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev

- name: Install Rust toolchain with clippy
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} # Unified cache key

- name: Run Clippy (Linting)
run: cargo clippy --tests --examples -- -D warnings

- name: Run Rustdoc (Documentation Check)
run: cargo rustdoc -- -D warnings

test:
name: Build and Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Run Cargo Tests
run: cargo test
4 changes: 2 additions & 2 deletions examples/intro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn on_dojo_events(
for ev in ev_retrieve_entities.read() {
info!(entity_id = ?ev.entity_id, "Torii update");

// Felt::ZERO is being emitted once, when the subcription is initialized.
// Felt::ZERO is being emitted once, when the subscription is initialized.
// We don't want to spawn a cube for this.
if ev.entity_id == Felt::ZERO {
continue;
Expand All @@ -215,7 +215,7 @@ fn on_dojo_events(
"di-Position" => {
ev_position_updated.write(PositionUpdatedEvent(m.into()));
}
name if name == "di-Moves".to_string() => {}
"di-Moves" => {}
_ => {
warn!("Model not handled: {:?}", m);
}
Expand Down
17 changes: 11 additions & 6 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ pub struct StarknetConnection {
>,
}

type SubscriptionMessage = (Felt, Vec<Struct>);

type SubscriptionSender = Option<Arc<Mutex<Sender<SubscriptionMessage>>>>;
type SubscriptionReceiver = Option<Arc<Mutex<Receiver<SubscriptionMessage>>>>;

/// Torii connection state.
#[derive(Default)]
pub struct ToriiConnection {
Expand All @@ -85,8 +90,8 @@ pub struct ToriiConnection {
pub pending_retrieve_entities:
VecDeque<JoinHandle<Result<RetrieveEntitiesResponse, torii_grpc_client::Error>>>,
pub subscriptions: Arc<Mutex<HashMap<String, JoinHandle<()>>>>,
pub subscription_sender: Option<Arc<Mutex<Sender<(Felt, Vec<Struct>)>>>>,
pub subscription_receiver: Option<Arc<Mutex<Receiver<(Felt, Vec<Struct>)>>>>,
pub subscription_sender: SubscriptionSender,
pub subscription_receiver: SubscriptionReceiver,
}

/// Dojo resource that embeds Starknet and Torii connection.
Expand Down Expand Up @@ -228,7 +233,7 @@ fn check_torii_task(
mut ev_initialized: EventWriter<DojoInitializedEvent>,
) {
if let Some(task) = &mut dojo.torii.init_task {
if let Ok(Ok(client)) = tokio.runtime.block_on(async { task.await }) {
if let Ok(Ok(client)) = tokio.runtime.block_on(task) {
info!("Torii client initialized.");
dojo.torii.client = Some(Arc::new(Mutex::new(client)));
dojo.torii.init_task = None;
Expand All @@ -238,7 +243,7 @@ fn check_torii_task(

if !dojo.torii.pending_retrieve_entities.is_empty() {
if let Some(task) = dojo.torii.pending_retrieve_entities.pop_front() {
if let Ok(Ok(response)) = tokio.runtime.block_on(async { task.await }) {
if let Ok(Ok(response)) = tokio.runtime.block_on(task) {
debug!("Retrieve entities response: {:?}", response);
for e in response.entities {
ev_retrieve_entities.write(DojoEntityUpdated {
Expand Down Expand Up @@ -270,7 +275,7 @@ fn check_torii_task(
/// that have been queued to be sent to the blockchain.
fn check_sn_task(tokio: Res<TokioRuntime>, mut dojo: ResMut<DojoResource>) {
if let Some(task) = &mut dojo.sn.connecting_task {
if let Ok(account) = tokio.runtime.block_on(async { task.await }) {
if let Ok(account) = tokio.runtime.block_on(task) {
info!("Connected to Starknet.");
dojo.sn.account = Some(account);
dojo.sn.connecting_task = None;
Expand All @@ -279,7 +284,7 @@ fn check_sn_task(tokio: Res<TokioRuntime>, mut dojo: ResMut<DojoResource>) {

if !dojo.sn.pending_txs.is_empty() && dojo.sn.account.is_some() {
if let Some(task) = dojo.sn.pending_txs.pop_front() {
match tokio.runtime.block_on(async { task.await }) {
match tokio.runtime.block_on(task) {
Ok(tx_result) => match tx_result {
Ok(result) => {
info!("Transaction completed: {:#x}", result.transaction_hash);
Expand Down