I have this system which needs to run in Bevy and update game state variables that are stored on the Solana blockchain. Because it needs to wait for a response from the blockchain, I need to use async make the calls. The problem for me is how to get the data out of the async thread so I can update the resource. I don't seem to be able to alter the lifetime for Commands. Here is the code:
fn get_game_state_variables (mut commands : Commands, time: Res<Time>, mut timer: ResMut<QueryTimer>) {
if timer.0.tick(time.delta()).just_finished(){
let thread_pool = AsyncComputeTaskPool::get();
let task = thread_pool.spawn(async move {
let client : WasmClient = WasmClient::new_with_commitment("http://127.0.0.1:8899", CommitmentConfig::confirmed());
let version = client.get_version().await.unwrap();
let storage = Pubkey::from_str("PUBKEY-HERE").unwrap();
let game_state_account = client.get_account(&storage).await.unwrap();
let account_data = game_state_account.data;
let decoded = ResultSchema::try_from_slice(&account_data[8..18]).unwrap();
console::log_1(&decoded.wheel_speed.into());
console::log_1(&version.solana_core.into());
console::log_1(&"Test".into());
let tests = decoded.wheel_speed;
});
commands.insert_resource(ResultSchema { time_of_last_update : 0, wheel_speed : tests, current_state : 0});
}