Sol.College

Full lesson

poker_solana

Gathering the tight knit community of poker players through a quiz about a player poker hand strength. Competing on RADAR hackathon. Check it out at DOMAIN.

What it does

From the project README:

This project is a blockchain-based Texas Holdem Poker Quiz that challenges users to choose between two poker hands and determine which one has a higher chance of winning. The game quiz covers different stages of a poker round: preflop, flop, turn, and river, allowing users to analyze the odds and make decisions based on each stage. User score and address are saved on the Solana blockchain.
Original
Parlov12/poker_solana
SuperStack fork
Blockchains/poker_solana @ 5ad0a81
Stars
0
Last push (original)
2024-10-06
Languages
TypeScript, JavaScript, CSS, Rust
Detected stack
AnchorNext.jsweb3.js
Categories
GamingConsumer & Social
Licence
MIT
Homepage
https://poker-solana.vercel.app

Architecture

48 source files. By extension: .tsx ×21, .js ×16, .ts ×10, .rs ×1.

Top-level directorySource files
web41
anchor5
(root)2

On-chain programs: anchor/programs/poksol-leaderboard

Dapp: deploying

This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/poker-solana/, once it is deployed and checked on devnet. Until then, run it locally with the commands below.

Key code, explained

Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.

Parlov12/poker_solana · anchor/programs/poksol-leaderboard/src/lib.rs L13–36 @ 5ad0a81 · MIT · original
     pub fn update_score(ctx: Context<UpdateScore>, score: u64) -> Result<()> {        let user_score = &mut ctx.accounts.user_score;        user_score.user = ctx.accounts.user.key();        user_score.score = score;        msg!("Score updated for user: {:?}", user_score.user);        Ok(())    }} #[derive(Accounts)]pub struct Initialize {} #[derive(Accounts)]#[instruction(score: u64)]pub struct UpdateScore<'info> {    #[account(        init_if_needed,        payer = user,        space = 8 + 32 + 8,        seeds = [b"user-score", user.key().as_ref()],        bump    )]    pub user_score: Account<'info, UserScore>,
  1. Line 18 msg!("Score updated for user: {:?}", user_score.user);: Logs to the program log, which is visible in explorers and the test output.
  2. Line 30 init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs.
  3. Line 33 seeds = [b"user-score", user.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  4. Line 34 bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.

How to run, build and test

These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.

DirectoryCommandRuns
.npm run devnx serve web
.npm run buildnx build web
anchornpm run lintprettier */*.js "*/**/*{.js,.ts}" --check
anchoranchor buildcompile programs and generate IDLs
anchoranchor testlocal validator + test suite
anchoranchor run testyarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts

What you could build from it