pub struct GameContext { /* private fields */ }Expand description
The context for public data.
This information is not transmitted over the network, instead it’s
calculated independently at each node. This struct will neither
be passed into the WASM runtime, instead Effect will be used.
§Access Version and Settle Version
Version numbers used in synchronization with on-chain data. Every
time a settlement is made, the settle_version will increase by
1.
§Handler State
The state of game handler will be serialized as JSON string, and stored. It will be passed into the WASM runtime, and get deseralized inside.
§Player Exiting
Players are not always allowed to leave a game. When leaving,
the player will be ejected from the game account, and assets will
be paid out. The property allow_exit decides whether leaving is
allowed at the moment. If it’s disabled, leaving event will be
rejected.
Implementations§
Source§impl GameContext
impl GameContext
pub fn try_new(game_account: &GameAccount) -> Result<Self>
pub fn set_timestamp(&mut self, timestamp: u64)
pub fn is_allow_exit(&self) -> bool
pub fn get_handler_state_raw(&self) -> &Vec<u8> ⓘ
pub fn set_handler_state_raw(&mut self, state: Vec<u8>)
pub fn get_handler_state<H>(&self) -> Hwhere
H: GameHandler,
pub fn get_checkpoint(&self) -> Option<Vec<u8>>
pub fn set_handler_state<H>(&mut self, handler: &H)where
H: GameHandler,
pub fn get_servers(&self) -> &Vec<Server>
pub fn get_game_addr(&self) -> &str
pub fn get_transactor_addr(&self) -> &str
pub fn get_player_by_index(&self, index: usize) -> Option<&Player>
pub fn get_player_mut_by_index(&mut self, index: usize) -> Option<&mut Player>
pub fn get_player_by_address(&self, addr: &str) -> Option<&Player>
pub fn get_player_mut_by_address(&mut self, addr: &str) -> Option<&mut Player>
pub fn count_players(&self) -> u16
pub fn count_servers(&self) -> u16
pub fn gen_start_game_event(&self) -> Event
pub fn get_server_by_address(&self, addr: &str) -> Option<&Server>
pub fn get_transactor_server(&self) -> &Server
pub fn dispatch_event(&mut self, event: Event, timeout: u64)
pub fn dispatch_event_instantly(&mut self, event: Event)
pub fn wait_timeout(&mut self, timeout: u64)
pub fn action_timeout(&mut self, player_addr: String, timeout: u64)
pub fn start_game(&mut self)
pub fn shutdown_game(&mut self)
pub fn dispatch_custom<E>(&mut self, e: &E, timeout: u64)where
E: CustomEvent,
pub fn get_players(&self) -> &Vec<Player>
pub fn get_timestamp(&self) -> u64
pub fn is_checkpoint(&self) -> bool
pub fn get_status(&self) -> GameStatus
pub fn list_random_states(&self) -> &Vec<RandomState>
pub fn list_random_states_mut(&mut self) -> &mut Vec<RandomState>
pub fn list_decision_states(&self) -> &Vec<DecisionState>
pub fn get_dispatch(&self) -> &Option<DispatchEvent>
pub fn cancel_dispatch(&mut self)
pub fn get_access_version(&self) -> u64
pub fn get_settle_version(&self) -> u64
Sourcepub fn get_random_state(&self, id: RandomId) -> Result<&RandomState>
pub fn get_random_state(&self, id: RandomId) -> Result<&RandomState>
Get the random state by its id.
pub fn get_random_state_unchecked(&self, id: RandomId) -> &RandomState
pub fn get_decision_state_mut( &mut self, id: DecisionId, ) -> Result<&mut DecisionState>
Sourcepub fn get_random_state_mut(&mut self, id: RandomId) -> Result<&mut RandomState>
pub fn get_random_state_mut(&mut self, id: RandomId) -> Result<&mut RandomState>
Get the mutable random state by its id.
Sourcepub fn assign<S: Into<String>>(
&mut self,
random_id: RandomId,
player_addr: S,
indexes: Vec<usize>,
) -> Result<()>
pub fn assign<S: Into<String>>( &mut self, random_id: RandomId, player_addr: S, indexes: Vec<usize>, ) -> Result<()>
Assign random item to a player
pub fn reveal(&mut self, random_id: RandomId, indexes: Vec<usize>) -> Result<()>
pub fn release(&mut self, decision_id: DecisionId) -> Result<()>
pub fn is_random_ready(&self, random_id: RandomId) -> bool
pub fn is_secrets_ready(&self) -> bool
Sourcepub fn set_game_status(&mut self, status: GameStatus)
pub fn set_game_status(&mut self, status: GameStatus)
Set game status
Sourcepub fn set_player_status(
&mut self,
addr: &str,
status: NodeStatus,
) -> Result<()>
pub fn set_player_status( &mut self, addr: &str, status: NodeStatus, ) -> Result<()>
Set player status by address. Using it in custom event handler is not allowed.
Sourcepub fn add_player(&mut self, player: &PlayerJoin) -> Result<()>
pub fn add_player(&mut self, player: &PlayerJoin) -> Result<()>
Add player to the game.
Sourcepub fn add_server(&mut self, server: &ServerJoin) -> Result<()>
pub fn add_server(&mut self, server: &ServerJoin) -> Result<()>
Add server to the game.
pub fn set_access_version(&mut self, access_version: u64)
pub fn set_allow_exit(&mut self, allow_exit: bool)
Sourcepub fn remove_player(&mut self, addr: &str) -> Result<()>
pub fn remove_player(&mut self, addr: &str) -> Result<()>
Remove player from the game.
Sourcepub fn dispatch_safe(&mut self, event: Event, timeout: u64)
pub fn dispatch_safe(&mut self, event: Event, timeout: u64)
Dispatch an event if there’s none
Sourcepub fn dispatch(&mut self, event: Event, timeout: u64) -> Result<()>
pub fn dispatch(&mut self, event: Event, timeout: u64) -> Result<()>
Dispatch event after timeout.
pub fn init_random_state(&mut self, spec: RandomSpec) -> Result<RandomId>
pub fn randomize_and_mask( &mut self, addr: &str, random_id: RandomId, ciphertexts: Vec<Ciphertext>, ) -> Result<()>
pub fn lock( &mut self, addr: &str, random_id: RandomId, ciphertexts_and_tests: Vec<(Ciphertext, Ciphertext)>, ) -> Result<()>
pub fn dispatch_randomization_timeout( &mut self, random_id: RandomId, ) -> Result<()>
pub fn settle(&mut self, settles: Vec<Settle>)
pub fn transfer(&mut self, transfers: Vec<Transfer>)
pub fn get_settles(&self) -> &Option<Vec<Settle>>
pub fn bump_settle_version(&mut self)
pub fn take_settles_and_transfers( &mut self, ) -> Result<Option<(Vec<Settle>, Vec<Transfer>, Vec<u8>)>>
pub fn add_settle(&mut self, settle: Settle)
pub fn add_revealed_random( &mut self, random_id: RandomId, revealed: HashMap<usize, String>, ) -> Result<()>
pub fn add_revealed_answer( &mut self, decision_id: DecisionId, revealed: String, ) -> Result<()>
pub fn ask(&mut self, owner: String) -> DecisionId
pub fn answer_decision( &mut self, id: DecisionId, owner: &str, ciphertext: Ciphertext, digest: SecretDigest, ) -> Result<()>
pub fn get_revealed( &self, random_id: RandomId, ) -> Result<&HashMap<usize, String>>
pub fn derive_effect(&self) -> Effect
pub fn apply_effect(&mut self, effect: Effect) -> Result<()>
pub fn set_node_ready(&mut self, access_version: u64)
pub fn apply_checkpoint( &mut self, access_version: u64, settle_version: u64, ) -> Result<()>
pub fn prepare_for_next_event(&mut self, timestamp: u64)
Trait Implementations§
Source§impl BorshDeserialize for GameContextwhere
Addr: BorshDeserialize,
u64: BorshDeserialize,
GameStatus: BorshDeserialize,
Vec<Player>: BorshDeserialize,
Vec<Server>: BorshDeserialize,
Option<DispatchEvent>: BorshDeserialize,
Vec<u8>: BorshDeserialize,
bool: BorshDeserialize,
Vec<RandomState>: BorshDeserialize,
Vec<DecisionState>: BorshDeserialize,
Option<Vec<Settle>>: BorshDeserialize,
Option<Vec<Transfer>>: BorshDeserialize,
Option<Vec<u8>>: BorshDeserialize,
impl BorshDeserialize for GameContextwhere
Addr: BorshDeserialize,
u64: BorshDeserialize,
GameStatus: BorshDeserialize,
Vec<Player>: BorshDeserialize,
Vec<Server>: BorshDeserialize,
Option<DispatchEvent>: BorshDeserialize,
Vec<u8>: BorshDeserialize,
bool: BorshDeserialize,
Vec<RandomState>: BorshDeserialize,
Vec<DecisionState>: BorshDeserialize,
Option<Vec<Settle>>: BorshDeserialize,
Option<Vec<Transfer>>: BorshDeserialize,
Option<Vec<u8>>: BorshDeserialize,
Source§impl BorshSerialize for GameContextwhere
Addr: BorshSerialize,
u64: BorshSerialize,
GameStatus: BorshSerialize,
Vec<Player>: BorshSerialize,
Vec<Server>: BorshSerialize,
Option<DispatchEvent>: BorshSerialize,
Vec<u8>: BorshSerialize,
bool: BorshSerialize,
Vec<RandomState>: BorshSerialize,
Vec<DecisionState>: BorshSerialize,
Option<Vec<Settle>>: BorshSerialize,
Option<Vec<Transfer>>: BorshSerialize,
Option<Vec<u8>>: BorshSerialize,
impl BorshSerialize for GameContextwhere
Addr: BorshSerialize,
u64: BorshSerialize,
GameStatus: BorshSerialize,
Vec<Player>: BorshSerialize,
Vec<Server>: BorshSerialize,
Option<DispatchEvent>: BorshSerialize,
Vec<u8>: BorshSerialize,
bool: BorshSerialize,
Vec<RandomState>: BorshSerialize,
Vec<DecisionState>: BorshSerialize,
Option<Vec<Settle>>: BorshSerialize,
Option<Vec<Transfer>>: BorshSerialize,
Option<Vec<u8>>: BorshSerialize,
Source§impl Clone for GameContext
impl Clone for GameContext
Source§fn clone(&self) -> GameContext
fn clone(&self) -> GameContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more