GameStorm API is a backend application designed to facilitate a gaming platform that integrates with the Lightning Network using the Zebedee API. The application allows users to authenticate, subscribe, and make payments via the Lightning Network, providing a seamless and secure gaming experience with cryptocurrency integration.
This project leverages the Zebedee API to interact with the Lightning Network. Zebedee provides a set of tools and services that enable developers to build Bitcoin Lightning applications, handling complex payment operations with ease.
To use the Zebedee API in this project, you need to obtain an API key. Follow these steps:
- Sign Up for a Zebedee Account:
- Visit the Zebedee Dashboard and create an account.
- Create a New Application:
- Once logged in, navigate to the Applications section.
- Click on Create Application.
- Fill in the required details for your application.
- Obtain the API Key:
- After creating the application, you will be provided with an API key.
- Important: Keep this API key secure and do not expose it publicly.
To keep sensitive information secure and out of the codebase, the project uses environment variables to manage configuration settings like the Zebedee API key.
- Create a
.envFile:
In the gamestorm-api directory, create a file named .env.
cd gamestorm-api
touch .env- Add Your API Key to the
.envFile:
Open the .env file in a text editor and add the following line:
ZEBEDEE_API_KEY=YOUR_ZEBEDEE_API_KEYReplace YOUR_ZEBEDEE_API_KEY with the actual API key you obtained from Zebedee.
- Ensure the
.envFile is Ignored by Git:
To prevent the .env file from being committed to version control (e.g., GitHub), add it to your .gitignore file.
Add the following line to .gitignore:
.env- Verify the Configuration in
config.py:
The gamestorm-api/gamestorm/config.py file is set up to read the API key from the environment variable:
# gamestorm-api/gamestorm/config.py
import os
from dotenv import load_dotenv
load_dotenv() # This loads the environment variables from the .env file
class Settings:
"""Configuration settings for the GameStorm application."""
API_KEY = os.getenv("ZEBEDEE_API_KEY") # Reads the API key from the environment
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./gamestorm.db")
settings = Settings()- The
load_dotenv()function loads environment variables from the.envfile. os.getenv("ZEBEDEE_API_KEY")retrieves the value of theZEBEDEE_API_KEYenvironment variable.
The GameStorm API is currently in development. The core functionalities have been implemented, but some parts are still incomplete or contain placeholders (indicated by TODO comments in the code).
- User Authentication:
- Users can authenticate using a username and Lightning Network address.
- An invoice is generated for authentication purposes.
- Subscription Management:
- Users can subscribe to the service by making a payment via the Lightning Network.
- Subscription status can be queried to determine if a user is subscribed or unsubscribed.
- Payment Processing:
- Integration with the Zebedee API to create charges and verify payments.
- Invoice Verification:
- The verification of signed invoices in the
/authenticate/confirmendpoint is not yet implemented. - Files with TODOs:
gamestorm/routers/auth_router.pygamestorm/utils/security.py
- The verification of signed invoices in the
- Security Enhancements:
- Proper verification of payments and security checks need to be added.
- Error Handling and Validation:
- Comprehensive error handling and input validation are required.
- Database Migrations:
- Ensure that database migrations are properly managed with Alembic.
The project includes a Dockerfile to build and run the GameStorm API using Docker.
- Docker installed on your machine.
- Zebedee API Key configured in a
.envfile.
- Clone the Repository:
git clone https://github.com/yourusername/gamestorm-api.git
cd gamestorm-api- Set Up the
.envFile:
Create a .env file and add your Zebedee API key:
echo "ZEBEDEE_API_KEY=YOUR_ZEBEDEE_API_KEY" > .envReplace YOUR_ZEBEDEE_API_KEY with your actual API key.
- Ensure the
.envFile is in.gitignore:
Confirm that the .env file is listed in .gitignore to prevent it from being committed to version control.
- Build the Docker Image:
docker build -t gamestorm-api .- Run the Docker Container:
docker run -d -p 8000:8000 --env-file .env --name gamestorm-api gamestorm-api- The API will be accessible at http://localhost:8000.
- Check the Logs (Optional):
docker logs -f gamestorm-api- Stop and Remove the Container (Optional):
docker stop gamestorm-api
docker rm gamestorm-apiBelow are examples of how to interact with the GameStorm API endpoints using curl.
Endpoint:
POST /authenticate
Request:
curl -X POST "http://localhost:8000/authenticate" \
-H "Content-Type: application/json" \
-d '{
"username": "user1",
"ln_address": "user1@lnaddress.com"
}'Expected Response:
{
"ln_invoice": "ln_invoice_for_user1@lnaddress.com",
"user_id": 1
}Endpoint:
POST /authenticate/confirm
Note: This endpoint is not fully implemented yet.
Request:
curl -X POST "http://localhost:8000/authenticate/confirm" \
-H "Content-Type: application/json" \
-d '{
"signed_invoice": "signed_ln_invoice"
}'Expected Response:
{
"status": "Authentication successful"
}Endpoint:
GET /subscriptionStatus
Request:
curl -X GET "http://localhost:8000/subscriptionStatus" \
--data-urlencode "user_id=1"Expected Response:
{
"status": "unsubscribed"
}Endpoint:
POST /subscribe
Request:
curl -X POST "http://localhost:8000/subscribe" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1,
"amount": 1000
}'Expected Response:
{
"ln_invoice": "lnbc1... (actual Lightning invoice)",
"charge_id": "charge_id_from_zebedee"
}Endpoint:
POST /verify-payment
Request:
curl -X POST "http://localhost:8000/verify-payment" \
-H "Content-Type: application/json" \
-d '{
"charge_id": "charge_id_from_zebedee",
"user_id": 1
}'Expected Response:
{
"status": "Subscription activated"
}- Incomplete Implementations:
- Invoice verification and security checks are pending.
- Error handling and input validation need to be improved.
- Testing:
- No unit tests or integration tests have been implemented yet.
- Database Migrations:
- Ensure that Alembic migrations are correctly applied when making changes to models.
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes or improvements.
This project is licensed under the MIT License.
For any inquiries or support, please contact:
Email: bitcynic@protonmail.com GitHub: bitcynic