Initialize the contract
fn __constructor(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
ohloss: soroban_sdk::Address,
)
Create a new open game waiting for an opponent
Returns the session_id of the created game
fn create_game(
env: soroban_sdk::Env,
player1: soroban_sdk::Address,
wager: i128,
) -> u32
Join an open game as player2
Both players' FP will be locked in Ohloss
fn join_game(
env: soroban_sdk::Env,
session_id: u32,
player2: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Cancel an open game (only creator can cancel, only if still open)
fn cancel_game(
env: soroban_sdk::Env,
session_id: u32,
) -> Result<(), soroban_sdk::Error>
Store Player 1's signed auth entry for join_game
This allows anyone to join the game by reading the auth entry from storage. Only the game creator can call this, and only while game is open.
fn store_join_auth(
env: soroban_sdk::Env,
session_id: u32,
auth_entry: soroban_sdk::Bytes,
) -> Result<(), soroban_sdk::Error>
Get Player 1's join auth entry for a game
fn get_join_auth(
env: soroban_sdk::Env,
session_id: u32,
) -> Result
Get all open games
fn get_open_games(env: soroban_sdk::Env) -> soroban_sdk::Vec
Commit an allocation hash
commitment = keccak256(allocation.b1 || allocation.b2 || allocation.b3 || salt)
fn commit(
env: soroban_sdk::Env,
session_id: u32,
player: soroban_sdk::Address,
commitment: soroban_sdk::BytesN<32>,
) -> Result<(), soroban_sdk::Error>
Commit an allocation hash AND store auth entry for joining
This is used by Player 1 to commit their allocation AND make the game joinable by storing their pre-signed auth entry for join_game. Combines two operations into one transaction.
commitment = keccak256(allocation.b1 || allocation.b2 || allocation.b3 || salt)
fn commit_with_auth(
env: soroban_sdk::Env,
session_id: u32,
player: soroban_sdk::Address,
commitment: soroban_sdk::BytesN<32>,
join_auth_entry: soroban_sdk::Bytes,
) -> Result<(), soroban_sdk::Error>
Reveal allocation and salt
Contract verifies: keccak256(allocation || salt) == commitment
fn reveal(
env: soroban_sdk::Env,
session_id: u32,
player: soroban_sdk::Address,
allocation: Allocation,
salt: soroban_sdk::BytesN<32>,
) -> Result<(), soroban_sdk::Error>
Commit and reveal in a single transaction
This is an optimization for the second player to commit - since the other player has already committed, there's no advantage to hiding your allocation. This also auto-resolves the game if the first player has already revealed.
Returns Option<Address> - Some(winner) if game was auto-resolved, None if waiting for opponent's reveal
fn commit_and_reveal(
env: soroban_sdk::Env,
session_id: u32,
player: soroban_sdk::Address,
allocation: Allocation,
salt: soroban_sdk::BytesN<32>,
) -> Result
Resolve the game after both players have revealed
Determines winner and calls Ohloss end_game
fn resolve(
env: soroban_sdk::Env,
session_id: u32,
) -> Result
Claim victory by timeout
If opponent failed to commit or reveal in time, claim the win
fn claim_timeout(
env: soroban_sdk::Env,
session_id: u32,
claimer: soroban_sdk::Address,
) -> Result
Get game state
fn get_game(env: soroban_sdk::Env, session_id: u32) -> Result
Helper to compute commitment hash (for testing/frontend)
Returns keccak256(allocation || salt)
fn compute_commitment(
env: soroban_sdk::Env,
allocation: Allocation,
salt: soroban_sdk::BytesN<32>,
) -> Result, soroban_sdk::Error>
Get completed game by session ID
fn get_completed_game(
env: soroban_sdk::Env,
session_id: u32,
) -> Result
Get list of recent completed games (most recent first)
fn get_completed_games(env: soroban_sdk::Env) -> soroban_sdk::Vec
Get completed games IDs list (for pagination)
fn get_completed_game_ids(env: soroban_sdk::Env) -> soroban_sdk::Vec
fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address
fn set_admin(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)
fn get_ohloss(env: soroban_sdk::Env) -> soroban_sdk::Address
fn set_ohloss(env: soroban_sdk::Env, new_ohloss: soroban_sdk::Address)
Clean up stale open games (admin only) Removes games from open list that are no longer actually open
fn cleanup_open_games(env: soroban_sdk::Env)
fn upgrade(env: soroban_sdk::Env, new_wasm_hash: soroban_sdk::BytesN<32>)