Skip to content

Chia-Network/chia-gaming

Repository files navigation

chia-gaming Traits and Structs

Here's a breakdown of the key traits and structs used in the chia-gaming project, along with their purposes.

Common Types:

  • CoinID: Represents a unique identifier for a coin on the Chia blockchain.
  • CoinString: A structured representation of a coin, containing its parent CoinID, puzzle hash, and amount.
  • PrivateKey: Encapsulates a private key for signing Chia transactions.
  • PublicKey: Encapsulates a public key derived from a PrivateKey.
  • Aggsig: Represents an aggregated BLS signature, used in the standard signing scheme for chialisp, but also pressed into a 2-of-2 multi-signature scheme here.
  • Hash: Represents a 32-byte SHA-256 hash.
  • PuzzleHash: Represents the SHA-256 tree hash of a puzzle program.
  • Puzzle: Represents a CLVM program that defines the rules for spending a coin.
  • Amount: Represents a Chia amount in mojos.
  • Timeout: Represents a block height at which a coin will expire if not spent.
  • GameID: A unique identifier for a specific game.
  • Program: A wrapper for CLVM programs in byte format.
  • Spend: Represents a transaction spend, consisting of the puzzle, solution, and signature.
  • CoinSpend: Encapsulates a CoinString and a Spend to represent a transaction that spends the coin.
  • SpendBundle: A collection of CoinSpend objects that can be submitted as a transaction to the Chia blockchain.
  • CoinCondition: Represents a condition that must be fulfilled to spend a coin.
  • ValidationProgram: A CLVM program used for validating game moves.
  • ValidationInfo: Contains the game state and a ValidationProgram, used for calculating a validation info hash.
  • Evidence: CLVM data representing proof of cheating.

Channel Handler:

  • ChannelHandlerPrivateKeys: Holds the private keys for a player's channel coin, unroll coin, and referee.
  • ChannelHandlerInitiationData: Data used to initiate a state channel, including launcher coin ID, contributions, and public keys of the other player.
  • ChannelHandlerInitiationResult: Returned by the ChannelHandler constructor, containing the puzzle hash of the channel coin and the initial channel half signature.
  • PotatoSignatures: Contains half-signed information for sending the potato.
  • GameStartInfo: Contains information for starting a game, including the game ID, initial state, amount, timeout, and game handlers.
  • ReadableMove: A CLVM representation of a game move that can be interpreted by the UI.
  • ReadableUX: A CLVM representation of a game state that can be displayed to the user.
  • MoveResult: Contains the potato signatures and game move details for a successful move.
  • OnChainGameCoin: Represents a game coin that has been moved on-chain.
  • CoinSpentMoveUp: Represents a successful game move that was spent on-chain, containing the game coin spend, the game ID, and the new coin string.
  • CoinSpentAccept: Represents a successful game acceptance that was spent on-chain, containing the game coin spend, the game ID, and the reward coin string.
  • CoinSpentDisposition: Represents the outcome of spending a game coin on-chain.
  • DispositionResult: The result of a ChannelHandler's channel_coin_spent method, containing the disposition, skipped game IDs, the contribution adjustment, and any skipped coin IDs.
  • CoinSpentResult: Result of a channel coin spend, providing the reward coin string and the list of new game coins.
  • ChannelCoinSpentResult: Describes the result of spending a channel coin on-chain, providing the unroll transaction, timeout status, and any canceled game IDs.
  • ChannelCoin: Encapsulates the state channel coin.
  • ChannelCoinInfo: Holds a ChannelCoin and the amount it represents.
  • ChannelCoinSpendInfo: Holds the solution, conditions, and signature of a channel coin spend.
  • ChannelHandlerUnrollSpendInfo: Contains information required to spend the unroll coin, including the coin's data and the corresponding signatures.
  • LiveGame: Represents a game currently in progress, holding the game ID, the referee maker, and contributions from both players.
  • PotatoAcceptCachedData: Cached data for a potato accept message, used for unrolling.
  • PotatoMoveCachedData: Cached data for a potato move message, used for unrolling.
  • CachedPotatoRegenerateLastHop: Enum representing different types of cached data for potato messages.
  • HandshakeResult: Holds the channel puzzle, amount, and spend information generated during the handshake process.

Referee:

  • RefereeMaker: Handles the referee coin and its logic.
  • GameMoveStateInfo: Stores basic information about a move, including the move made, mover share, and maximum move size.
  • GameMoveDetails: Extends GameMoveStateInfo with a validation info hash.
  • GameMoveWireData: Contains the puzzle hash for unroll and the GameMoveDetails for a move.
  • OnChainRefereeMove: Dynamic arguments for a referee coin spend related to a game move.
  • OnChainRefereeSlash: Dynamic arguments for a referee coin spend related to a slash.
  • OnChainRefereeSolution: Enum representing different types of solutions for the referee coin.
  • RefereeOnChainTransaction: Holds a spend bundle for a referee coin and the resulting reward coin.

Game Handler:

  • GameHandler: Represents a game handler, either for a player's turn or the opponent's turn.
  • MyTurnInputs: Contains inputs for a player's turn, including the move, amount, entropy, and information about the last move.
  • MyTurnResult: The result of a player's turn, containing the next game handler, validation program, and other details.
  • TheirTurnInputs: Contains inputs for an opponent's turn, including the amount, state, and move details.
  • TheirTurnResult: The result of an opponent's turn, representing either a move, a slash, or a final move.
  • MessageInputs: Contains inputs for a message handler, including the message, amount, state, move, and mover share.
  • MessageHandler: Handles messages during the game, providing a run method to interpret messages.

Additional:

  • DebugGamePrograms: A struct containing the debug game's validation programs and game handlers.
  • RefereeTest: A struct used for testing the referee module.
  • SimulatorEnvironment: A structure used in simulations to manage the game, identities, and the simulator instance.
  • GameAction: Represents a possible action within a game simulation.
  • GameActionResult: Represents the outcome of a game action.
  • OnChainState: Enum representing the state of the game, either off-chain or on-chain.
  • ValidatorMoveArgs: Arguments for the validator move query, containing the game move details, mover puzzle, and solution.
  • CoinDataForReward: Data for a coin being used as a reward, containing the coin string.

Overall, the project is organized around the concept of state channels, where two players interact through a set of coins on the Chia blockchain. The code uses a combination of CLVM programs and Rust code to manage the state channel, referee the games, and handle game logic. The use of traits helps to abstract away dependencies and make the code more modular and reusable.