Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DogLooksGood committed Dec 24, 2023
1 parent df4da80 commit 0cac06e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,29 @@ pub struct LaunchSubGame {
pub init_data: Vec<u8>,
}

impl LaunchSubGame {
pub fn try_new<S: BorshSerialize>(id: usize, bundle_addr: String, init_data: S) -> Result<Self> {
Ok(Self {
id, bundle_addr, init_data: init_data.try_to_vec()?
})
}
}

#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq, Clone)]
pub struct EmitBridgeEvent {
pub dest: usize,
pub raw: Vec<u8>,
}

impl EmitBridgeEvent {
pub fn try_new<E: BridgeEvent>(dest: usize, bridge_event: E) -> Result<Self> {
Ok(Self {
dest, raw: bridge_event.try_to_vec()?
})
}
}


/// An effect used in game handler provides reading and mutating to
/// the game context. An effect can be created from game context,
/// manipulated by game handler and applied after event processing.
Expand Down
10 changes: 10 additions & 0 deletions test/src/account_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ impl TestGameAccountBuilder {
self
}

pub fn with_checkpoint<T: BorshSerialize>(self, checkpoint: T) -> Self {
let checkpoint = checkpoint.try_to_vec().expect("Serialize data failed");
self.with_checkpoint_vec(checkpoint)
}

pub fn with_checkpoint_vec(mut self, checkpoint: Vec<u8>) -> Self {
self.account.checkpoint = checkpoint;
self
}

pub fn with_data<T: BorshSerialize>(self, account_data: T) -> Self {
let data = account_data.try_to_vec().expect("Serialize data failed");
self.with_data_vec(data)
Expand Down
1 change: 1 addition & 0 deletions test/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub use race_api::error::{Error, Result};
pub use race_api::types::{Settle, SettleOp, Transfer};
pub use race_core::context::{DispatchEvent, GameContext};
pub use race_core::types::GameAccount;
pub use race_api::effect::{LaunchSubGame, EmitBridgeEvent};

0 comments on commit 0cac06e

Please sign in to comment.