<<<<<<< HEAD
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.
- 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
- 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
- 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
git clone https://github.com/wasif1024/rocky-road-player.git
cd rocky-road-playercargo buildCreate a PostgreSQL database:
createdb rocky_road_playerOr using psql:
CREATE DATABASE rocky_road_player;Set up your database URL in a .env file or as an environment variable:
DATABASE_URL=postgres://username:password@localhost/rocky_road_playerdiesel migration runTo revert a migration:
diesel migration revertThe application uses environment variables for configuration. Create a .env file in the root directory with the following 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- Additional service URLs and API endpoints as needed
- Authentication keys and secrets for external integrations
cargo runThe server will start on http://0.0.0.0:8080 (or your configured host and port).
cargo build --release
./target/release/rocky_road_playerBuild the Docker image:
docker build -t rocky-road-player .Run the container:
docker run -p 8080:8080 --env-file .env rocky-road-player- GET
/health- Health check endpoint- Returns service status and configured health message
-
POST
/player/register- Register a new player- Form data:
game_id,player_name,player_email(optional)
- Form data:
-
POST
/player/detail- Get player details- Form data:
player_idor other identifiers
- Form data:
-
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
- Form data:
-
POST
/player/updateplayerpin- Update player PIN- Form data:
player_id,pin
- Form data:
-
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
- 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
- POST
/blockchain/test- Test blockchain transaction execution
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.
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
cargo testcargo fmtcargo clippyCreate a new migration:
diesel migration generate <migration_name>This creates two files in migrations/:
up.sql- Migration to applydown.sql- Migration to revert
The project includes a Dockerfile for containerized deployment. The Docker image:
- Uses a base Rust image (set via
ENV_ECR_IMAGE) - Installs system dependencies (libsasl2-dev, libpq-dev)
- Installs Diesel CLI
- Builds the application in release mode
- Runs environment setup script and starts the application
# 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-playerThe 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:
- Runs static analysis (SonarQube, Clippy, Cargo Audit)
- Builds Docker image
- Pushes to ECR
- Deploys to Kubernetes using Helmfile
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- 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
- Create a feature branch
- Make your changes
- Run tests and ensure code quality checks pass
- Submit a pull request
[Add your license information here]
7c7b2930e9828985abac73c223b7f4fbc5f0ce4c