CryptoDrain is a Flask-based Bitcoin wallet sweeping service. This project provides a secure and modular API to create and sweep wallets based on provided seed phrases and transfer funds to a specified receiver address. It is built with security, scalability, and maintainability in mind.
- Features
- Architecture & Modules
- Installation
- Configuration
- Usage
- API Endpoints
- Development & Testing
- Contributing
- License
- Acknowledgments
Modular Design
- Separates configuration management, wallet operations, and API endpoints
Security Enhancements
- Sensitive data is redacted from logs and notifications
- Environment variable overrides for credentials
Input Validation
- Validates API keys, seed phrases, receiver addresses, and balance formats
Performance & Scalability
- Utilizes Gevent monkey patching for non-blocking I/O
- Implements caching for IP lookup results per request
Robust Logging & Error Handling
- Uses rotating file logging with detailed exception handling
- Provides structured logging for easier debugging
Health-Check Endpoint
- A dedicated endpoint to check server health for monitoring and load balancing
The repository is organized as follows:
├── api
│ └── config.json # JSON configuration file
├── app.py # Main application file containing Flask app and API endpoints
├── requirements.txt # Python dependencies
└── README.md # Project documentation
Key modules include:
- Config: Manages configuration loading and environment variable overrides
- WalletManager: Encapsulates wallet creation and sweeping operations
- Helper Functions: Provide logging, IP lookup, input sanitization, and validation
- API Endpoints:
/api:
Main endpoint for processing wallet sweep requests/health:
Health-check endpoint for server monitoring
- Python 3.7+
- pip (Python package installer)
1. Clone the Repository:
git clone https://github.com/fled-dev/cryptodrain.git
cd cryptodrain
2. Create a Virtual Environment (Optional but Recommended):
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
3. Install Dependencies:
pip install -r requirements.txt
4. Set Up Environment Variables (Optional): You can override sensitive configuration values (e.g., Telegram API key, channel ID, host IP/port) by setting environment variables:
export TG_API_KEY='your_telegram_api_key'
export TG_CHANNEL_ID='your_telegram_channel_id'
export HOST_IP='127.0.0.1'
export HOST_PORT=8080
The application reads its configuration from the api/config.json
file. An example configuration is provided below:
{
"FLASK_API_KEYS": [
"0c19e4d5-a705-4cd7-b107-be8fd9a7b122"
],
"TG_NOTIFICATIONS": true,
"TG_API_KEY": "",
"TG_CHANNEL_ID": "",
"HOST_IP": "127.0.0.1",
"HOST_PORT": 8080
}
Note:
It is recommended to use environment variables for sensitive data such as TG_API_KEY and TG_CHANNEL_ID rather than storing them in plain text.
After installation and configuration, you can run the application as follows:
python app.py
The server will start using Gevent’s WSGIServer on the specified HOST_IP
and HOST_PORT
. You should see a boot screen in the terminal followed by logs indicating the server is ready to receive requests.
1. /api
- Method:
GET
- Description: Endpoint to validate inputs, create a wallet based on the provided seed phrase, and sweep funds to a specified receiver address
- Query Parameters:
api-key
(str): A valid API keyseedphrase
(str): Wallet seed phrase (12 to 24 words)receiver
(str): Bitcoin address to sweep funds tobalance
(str): (Optional) Expected balance (for logging purposes)
- Example:
curl "http://127.0.0.1:8080/api?api-key=0c19e4d5-a705-4cd7-b107-be8fd9a7b122&seedphrase=word1%20word2%20...%20word12&receiver=bc1qexampleaddress&balance=0.12345678"
2. /health
- Method:
GET
- Description: Simple health-check endpoint for load balancers and monitoring tools
- Response:
{ "status": "ok" }
Running Locally
- Activate your virtual environment.
- Set any required environment variables.
- Run the application:
python app.py
Testing
- Unit Tests: Add your unit tests in a separate directory (e.g.,
tests/
) and run them using a test framework likepytest
- Linting: Ensure your code follows PEP 8 standards by running:
flake8 .
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix:
git checkout -b feature/my-new-feature
- Commit your changes with clear messages
- Push your branch to your fork:
git push origin feature/my-new-feature
- Open a pull request detailing your changes
Please ensure that your code follows our coding standards and includes tests where applicable.
This project is licensed under the GPL-3.0 license.
Thanks to all contributors (just me lol) Special thanks to the maintainers of Flask, Gevent, and bitcoinlib for their great work.