Contract 45b1cc1238cc3619511ce59e22bfd9fd16878370c44c6e80f34e66f90fd6e3c2

← Back to Index 📥 Download WASM

Meta

cliver 23.4.0#fc6745f3d4e90d1ef68d14d0ae947404768fa5c0
rssdkver 23.4.0#673d6c4f2368d282d25da29bda55c21b8be69ca6
rsver 1.90.0

Instances

  • CDIOBDSVWHIERNCR6UJDBW4SPCB4DWPV4WHMJW3HHYOGFD472OX3OUP4

Interface

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>

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>

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>

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>
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>)

Imports

WebAssembly Text (WAT) ▶