diff --git a/api/src/engine.rs b/api/src/engine.rs index 96c92c26..8288b97c 100644 --- a/api/src/engine.rs +++ b/api/src/engine.rs @@ -4,7 +4,8 @@ use crate::{ effect::Effect, error::{HandleError, HandleResult}, event::Event, - prelude::GamePlayer, types::EntryType, + prelude::GamePlayer, + types::EntryType, }; /// A subset of on-chain account, used for game handler @@ -66,7 +67,7 @@ impl Default for InitAccount { entry_type: EntryType::Cash { min_deposit: 100, max_deposit: 200, - } + }, } } } diff --git a/transactor/src/handle.rs b/transactor/src/handle.rs index d582794c..7d0d804e 100644 --- a/transactor/src/handle.rs +++ b/transactor/src/handle.rs @@ -7,6 +7,7 @@ use crate::component::{ }; use crate::frame::{EventFrame, SignalFrame}; use race_api::error::{Error, Result}; +use race_api::prelude::InitAccount; use race_core::context::GameContext; use race_core::transport::TransportT; use race_core::types::{ @@ -228,6 +229,11 @@ impl SubGameHandle { .await? .ok_or(Error::GameBundleNotFound)?; + // Build an InitAccount + let mut init_account = InitAccount::default(); + init_account.addr = addr.clone(); + init_account.data = spec.init_data.clone(); + let game_context = GameContext::try_new_with_sub_game_spec(spec)?; let handler = WrappedHandler::load_by_bundle(&bundle_account, encryptor.clone()).await?; @@ -244,6 +250,7 @@ impl SubGameHandle { event_bus.attach(&mut bridge_handle).await; event_bus.attach(&mut broadcaster_handle).await; event_bus.attach(&mut event_loop_handle).await; + event_bus.send(EventFrame::InitState { init_account }).await; Ok(Self { addr: format!("{}:{}", game_addr, sub_id), diff --git a/transactor/src/utils.rs b/transactor/src/utils.rs index 141946a9..d0a1a391 100644 --- a/transactor/src/utils.rs +++ b/transactor/src/utils.rs @@ -13,5 +13,6 @@ pub fn base64_decode(data: &str) -> Result, race_api::error::Error> { } pub fn addr_shorthand(addr: &str) -> String { - format!("[{}]", &addr[0..3]) + let l = addr.len(); + format!("[{}]", &addr[(l - 6)..l]) }