Skip to main content

GameContext

Struct GameContext 

Source
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

Source

pub fn try_new(game_account: &GameAccount) -> Result<Self>

Source

pub fn set_timestamp(&mut self, timestamp: u64)

Source

pub fn is_allow_exit(&self) -> bool

Source

pub fn get_handler_state_raw(&self) -> &Vec<u8>

Source

pub fn set_handler_state_raw(&mut self, state: Vec<u8>)

Source

pub fn get_handler_state<H>(&self) -> H
where H: GameHandler,

Source

pub fn get_checkpoint(&self) -> Option<Vec<u8>>

Source

pub fn set_handler_state<H>(&mut self, handler: &H)
where H: GameHandler,

Source

pub fn get_servers(&self) -> &Vec<Server>

Source

pub fn get_game_addr(&self) -> &str

Source

pub fn get_transactor_addr(&self) -> &str

Source

pub fn get_player_by_index(&self, index: usize) -> Option<&Player>

Source

pub fn get_player_mut_by_index(&mut self, index: usize) -> Option<&mut Player>

Source

pub fn get_player_by_address(&self, addr: &str) -> Option<&Player>

Source

pub fn get_player_mut_by_address(&mut self, addr: &str) -> Option<&mut Player>

Source

pub fn count_players(&self) -> u16

Source

pub fn count_servers(&self) -> u16

Source

pub fn gen_start_game_event(&self) -> Event

Source

pub fn get_server_by_address(&self, addr: &str) -> Option<&Server>

Source

pub fn get_transactor_server(&self) -> &Server

Source

pub fn dispatch_event(&mut self, event: Event, timeout: u64)

Source

pub fn dispatch_event_instantly(&mut self, event: Event)

Source

pub fn wait_timeout(&mut self, timeout: u64)

Source

pub fn action_timeout(&mut self, player_addr: String, timeout: u64)

Source

pub fn start_game(&mut self)

Source

pub fn shutdown_game(&mut self)

Source

pub fn dispatch_custom<E>(&mut self, e: &E, timeout: u64)
where E: CustomEvent,

Source

pub fn get_players(&self) -> &Vec<Player>

Source

pub fn get_timestamp(&self) -> u64

Source

pub fn is_checkpoint(&self) -> bool

Source

pub fn get_status(&self) -> GameStatus

Source

pub fn list_random_states(&self) -> &Vec<RandomState>

Source

pub fn list_random_states_mut(&mut self) -> &mut Vec<RandomState>

Source

pub fn list_decision_states(&self) -> &Vec<DecisionState>

Source

pub fn get_dispatch(&self) -> &Option<DispatchEvent>

Source

pub fn cancel_dispatch(&mut self)

Source

pub fn get_access_version(&self) -> u64

Source

pub fn get_settle_version(&self) -> u64

Source

pub fn get_random_state(&self, id: RandomId) -> Result<&RandomState>

Get the random state by its id.

Source

pub fn get_random_state_unchecked(&self, id: RandomId) -> &RandomState

Source

pub fn get_decision_state_mut( &mut self, id: DecisionId, ) -> Result<&mut DecisionState>

Source

pub fn get_random_state_mut(&mut self, id: RandomId) -> Result<&mut RandomState>

Get the mutable random state by its id.

Source

pub fn assign<S: Into<String>>( &mut self, random_id: RandomId, player_addr: S, indexes: Vec<usize>, ) -> Result<()>

Assign random item to a player

Source

pub fn reveal(&mut self, random_id: RandomId, indexes: Vec<usize>) -> Result<()>

Source

pub fn release(&mut self, decision_id: DecisionId) -> Result<()>

Source

pub fn is_random_ready(&self, random_id: RandomId) -> bool

Source

pub fn is_secrets_ready(&self) -> bool

Source

pub fn set_game_status(&mut self, status: GameStatus)

Set game status

Source

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.

Source

pub fn add_player(&mut self, player: &PlayerJoin) -> Result<()>

Add player to the game.

Source

pub fn add_server(&mut self, server: &ServerJoin) -> Result<()>

Add server to the game.

Source

pub fn set_access_version(&mut self, access_version: u64)

Source

pub fn set_allow_exit(&mut self, allow_exit: bool)

Source

pub fn remove_player(&mut self, addr: &str) -> Result<()>

Remove player from the game.

Source

pub fn dispatch_safe(&mut self, event: Event, timeout: u64)

Dispatch an event if there’s none

Source

pub fn dispatch(&mut self, event: Event, timeout: u64) -> Result<()>

Dispatch event after timeout.

Source

pub fn init_random_state(&mut self, spec: RandomSpec) -> Result<RandomId>

Source

pub fn add_shared_secrets( &mut self, _addr: &str, shares: Vec<SecretShare>, ) -> Result<()>

Source

pub fn randomize_and_mask( &mut self, addr: &str, random_id: RandomId, ciphertexts: Vec<Ciphertext>, ) -> Result<()>

Source

pub fn lock( &mut self, addr: &str, random_id: RandomId, ciphertexts_and_tests: Vec<(Ciphertext, Ciphertext)>, ) -> Result<()>

Source

pub fn dispatch_randomization_timeout( &mut self, random_id: RandomId, ) -> Result<()>

Source

pub fn settle(&mut self, settles: Vec<Settle>)

Source

pub fn transfer(&mut self, transfers: Vec<Transfer>)

Source

pub fn get_settles(&self) -> &Option<Vec<Settle>>

Source

pub fn bump_settle_version(&mut self)

Source

pub fn take_settles_and_transfers( &mut self, ) -> Result<Option<(Vec<Settle>, Vec<Transfer>, Vec<u8>)>>

Source

pub fn add_settle(&mut self, settle: Settle)

Source

pub fn add_revealed_random( &mut self, random_id: RandomId, revealed: HashMap<usize, String>, ) -> Result<()>

Source

pub fn add_revealed_answer( &mut self, decision_id: DecisionId, revealed: String, ) -> Result<()>

Source

pub fn ask(&mut self, owner: String) -> DecisionId

Source

pub fn answer_decision( &mut self, id: DecisionId, owner: &str, ciphertext: Ciphertext, digest: SecretDigest, ) -> Result<()>

Source

pub fn get_revealed( &self, random_id: RandomId, ) -> Result<&HashMap<usize, String>>

Source

pub fn derive_effect(&self) -> Effect

Source

pub fn apply_effect(&mut self, effect: Effect) -> Result<()>

Source

pub fn set_node_ready(&mut self, access_version: u64)

Source

pub fn apply_checkpoint( &mut self, access_version: u64, settle_version: u64, ) -> Result<()>

Source

pub fn prepare_for_next_event(&mut self, timestamp: u64)

Trait Implementations§

Source§

impl BorshDeserialize for GameContext

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

impl BorshSerialize for GameContext

Source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Source§

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
Source§

impl Clone for GameContext

Source§

fn clone(&self) -> GameContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GameContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GameContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.