Skip to content

High-performance Rust web service for managing game players, balances, cryptographic keys, and blockchain transactions

Notifications You must be signed in to change notification settings

wasif1024/rocky-road-player

Repository files navigation

<<<<<<< HEAD

Rocky Road Player

A high-performance Rust-based web service built with Actix-web for managing game players, their balances, cryptographic keys, transactions, and blockchain integration. This service provides a comprehensive API for player registration, currency transfers, balance management, and secure key management within a gaming ecosystem.

Features

  • Player Management: Register players, manage player details, and handle player-related operations
  • Balance Management: Track and manage player balances across multiple games and currencies
  • Cryptographic Key Management: Secure management of player keys (E, S, X, Y, Z keys) for encryption/decryption operations
  • Transaction Processing: Handle various transaction types including transfers, sends, buys, and spends
  • Blockchain Integration: Support for blockchain transactions and transaction history tracking
  • Email Services: Email template management and email sending capabilities
  • Poems Integration: Integration with Poems service for player registration and decryption operations
  • Kafka Integration: Event streaming using Apache Kafka for asynchronous message processing
  • Substrate Integration: Blockchain integration using Substrate/Polkadot framework

Tech Stack

  • Web Framework: Actix-web 4.3.1
  • Database: PostgreSQL with Diesel ORM 2.1.4
  • Connection Pooling: r2d2
  • Message Queue: Apache Kafka (rdkafka)
  • Blockchain: Substrate (subxt)
  • Serialization: Serde & serde_json
  • Cryptography: magic-crypt, sha2, base64ct
  • HTTP Client: reqwest
  • Database Types: rust_decimal for numeric precision

Prerequisites

  • Rust: Latest stable version (recommended: 1.70+)
  • PostgreSQL: 12+
  • Apache Kafka: For message queue functionality (optional for basic operations)
  • Diesel CLI: For database migrations
    cargo install diesel_cli --no-default-features --features postgres

Installation

1. Clone the Repository

git clone https://github.com/wasif1024/rocky-road-player.git
cd rocky-road-player

2. Install Dependencies

cargo build

3. Database Setup

Create a PostgreSQL database:

createdb rocky_road_player

Or using psql:

CREATE DATABASE rocky_road_player;

4. Configure Database Connection

Set up your database URL in a .env file or as an environment variable:

DATABASE_URL=postgres://username:password@localhost/rocky_road_player

5. Run Migrations

diesel migration run

To revert a migration:

diesel migration revert

Configuration

The application uses environment variables for configuration. Create a .env file in the root directory with the following variables:

Required Environment Variables

# Server Configuration
HOST_URL=0.0.0.0           # Server host address
PORT=8080                  # Server port number
POOL_SIZE=15               # Database connection pool size

# Database
DATABASE_URL=postgres://username:password@localhost/rocky_road_player

# Kafka (if using message queue)
KAFKA_BOOTSTRAP_SERVERS=localhost:9092

# External Services
POEMS_BASE_URL=http://localhost:8081/  # Poems service base URL
GAME_URL=http://localhost:8082/        # Game service base URL

# Health Check
HEALTH_MSG=Service is healthy

Optional Environment Variables

  • Additional service URLs and API endpoints as needed
  • Authentication keys and secrets for external integrations

Running the Application

Development Mode

cargo run

The server will start on http://0.0.0.0:8080 (or your configured host and port).

Release Mode

cargo build --release
./target/release/rocky_road_player

With Docker

Build the Docker image:

docker build -t rocky-road-player .

Run the container:

docker run -p 8080:8080 --env-file .env rocky-road-player

API Endpoints

Health Check

  • GET /health - Health check endpoint
    • Returns service status and configured health message

Player Management

  • POST /player/register - Register a new player

    • Form data: game_id, player_name, player_email (optional)
  • POST /player/detail - Get player details

    • Form data: player_id or other identifiers
  • POST /player/transfer - Transfer currency between players

    • Form data: Transaction details
  • POST /player/currentbalance - Get current player balance

    • Form data: player_id, game_id, currency_id
  • POST /player/updateplayerpin - Update player PIN

    • Form data: player_id, pin

Poems Integration

  • POST /poems/player/register - Register player via Poems service

    • Form data: Player registration data
  • POST /poems/player/decrypt - Decrypt player data via Poems service

    • Form data: Encrypted data and keys

Bezerk/Transition Operations

  • POST /bezerk/transfer - Execute transition transfer
  • POST /bezerk/send - Execute transition send operation
  • POST /bezerk/buy - Execute transition buy operation
  • POST /bezerk/spend - Execute transition spend operation

Blockchain

  • POST /blockchain/test - Test blockchain transaction execution

Database Schema

The application uses Diesel ORM with the following main entities:

  • players: Core player information
  • player_balance: Player balances per game and currency
  • player_*_keys: Cryptographic keys (E, S, X, Y, Z keys)
  • players_key_summons: Key summon/binding records
  • transition_records: Transaction and transition records
  • chain_execution: Blockchain execution records
  • transaction_history: Historical transaction data
  • games: Game configuration and metadata
  • default_currency: Currency definitions per game

See src/schema.rs for the complete schema definition.

Project Structure

rocky-road-player/
├── src/
│   ├── main.rs                    # Application entry point
│   ├── schema.rs                  # Diesel database schema
│   ├── chain_execution/           # Blockchain execution module
│   ├── email/                     # Email service module
│   ├── helper/                    # Utility functions
│   ├── invo_functions/            # Invo function management
│   ├── player/                    # Player management
│   ├── player_balance/            # Balance management
│   ├── player_key_summon/         # Key summon operations
│   ├── player_keys/               # Cryptographic key management
│   │   ├── player_e_keys/
│   │   ├── player_s_keys/
│   │   ├── player_x_keys/
│   │   ├── player_y_keys/
│   │   └── player_z_keys/
│   ├── poems/                     # Poems service integration
│   ├── transaction_history/       # Transaction history
│   └── transition_records/        # Transition/transaction records
├── migrations/                    # Database migrations
├── cicd/                          # CI/CD configuration
│   ├── helmfile.yaml
│   └── templates/
│       └── svc.yaml
├── Cargo.toml                     # Rust dependencies
├── diesel.toml                    # Diesel configuration
├── Dockerfile                     # Docker configuration
└── buildspec.yml                  # AWS CodeBuild specification

Development

Running Tests

cargo test

Code Formatting

cargo fmt

Linting

cargo clippy

Database Migrations

Create a new migration:

diesel migration generate <migration_name>

This creates two files in migrations/:

  • up.sql - Migration to apply
  • down.sql - Migration to revert

Docker Deployment

The project includes a Dockerfile for containerized deployment. The Docker image:

  1. Uses a base Rust image (set via ENV_ECR_IMAGE)
  2. Installs system dependencies (libsasl2-dev, libpq-dev)
  3. Installs Diesel CLI
  4. Builds the application in release mode
  5. Runs environment setup script and starts the application

Building and Running

# Build
docker build -t rocky-road-player .

# Run with environment variables
docker run -p 8080:8080 \
  -e DATABASE_URL=postgres://... \
  -e HOST_URL=0.0.0.0 \
  -e PORT=8080 \
  rocky-road-player

CI/CD

The project uses AWS CodeBuild with:

  • Static Analysis: SonarQube integration for code quality
  • Security Scanning: Cargo audit for vulnerability detection
  • Docker Build: Automated Docker image building
  • Kubernetes Deployment: Helmfile-based deployment to EKS
  • ECR Integration: Automated image push to AWS ECR

The CI/CD pipeline:

  1. Runs static analysis (SonarQube, Clippy, Cargo Audit)
  2. Builds Docker image
  3. Pushes to ECR
  4. Deploys to Kubernetes using Helmfile

Logging

The application uses env_logger for logging. Set the log level using the RUST_LOG environment variable:

RUST_LOG=debug cargo run      # Debug logging
RUST_LOG=info cargo run       # Info logging (default)
RUST_LOG=warn cargo run       # Warnings and errors only

Security Considerations

  • Cryptographic keys are managed securely through the key management system
  • Database credentials should be stored securely (use AWS Secrets Manager, environment variables, etc.)
  • Kafka connections should use SSL/TLS in production
  • All sensitive operations should be logged appropriately
  • Player PINs and keys are encrypted at rest

Contributing

  1. Create a feature branch
  2. Make your changes
  3. Run tests and ensure code quality checks pass
  4. Submit a pull request

License

[Add your license information here]

Support

For issues and questions, please contact the development team or open an issue in the repository.

rocky-road-notifications

rocky-road-notifications

rocky-road-player

rocky-road-games

7c7b2930e9828985abac73c223b7f4fbc5f0ce4c

About

High-performance Rust web service for managing game players, balances, cryptographic keys, and blockchain transactions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages