A Flask-based API for handling Splinterlands asset trades on the Hive blockchain with automatic fee collection.
- Secure trade creation and confirmation
- Automatic DEC fee collection
- Transaction ID logging
- Comprehensive error handling
- Authentication system
- Trade status tracking
- Database persistence
pip install -r requirements.txtCreate a .env file with the following variables:
SECRET_KEY=your-super-secret-key-change-this-in-production
ADMIN_WALLET=splintermarket_admin FEE_AMOUNT=100 HIVE_NODE=https://api.hive.blog
SPLINTERLANDS_API=https://api.splinterlands.io MARKET_API=https://api.splinterlands.io/market AUTH_API=https://api.splinterlands.io/auth/login
### 3. Run the Application
```bash
python app.py
The application will start on http://localhost:5000
- GET
/health - Returns application status
- POST
/create_trade - Body:
{
"proposer": "user1",
"receiver": "user2",
"proposer_assets": ["card1", "card2"],
"receiver_assets": ["card3", "card4"],
"proposer_value": 100.0,
"receiver_value": 100.0
}- GET
/get_trade/<trade_id> - Returns complete trade information
- POST
/confirm_trade/<trade_id> - Body:
{
"user": "username",
"is_proposer": true,
"private_key": "user_private_key"
}- GET
/list_trades - Query Parameters:
user: Filter by userstatus: Filter by status (pending, completed, cancelled)
- POST
/cancel_trade/<trade_id> - Body:
{
"user": "username"
}The application uses SQLite with the following schema:
CREATE TABLE trades (
trade_id INTEGER PRIMARY KEY AUTOINCREMENT,
proposer TEXT NOT NULL,
receiver TEXT NOT NULL,
proposer_assets TEXT NOT NULL,
receiver_assets TEXT NOT NULL,
proposer_value REAL DEFAULT 0,
receiver_value REAL DEFAULT 0,
status TEXT DEFAULT 'pending',
last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP,
transaction_id TEXT,
proposer_confirmed BOOLEAN DEFAULT FALSE,
receiver_confirmed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- Authentication decorator for protected endpoints
- Input validation for all trade data
- Error handling and logging
- SQL injection prevention with parameterized queries
- Environment variable configuration
- Create Trade: User creates a trade with assets and values
- Confirm Trade: Both parties must confirm the trade
- Execute Trade: Once both parties confirm, the trade is executed on Hive
- Fee Collection: DEC fees are automatically transferred to admin wallet
- Status Update: Trade status is updated to 'completed'
The application includes comprehensive error handling for:
- Invalid trade data
- Insufficient authority (RC)
- Missing private keys
- Database errors
- Network issues
All operations are logged with appropriate levels:
- INFO: Successful operations
- ERROR: Failed operations with details
- DEBUG: Detailed debugging information
To run in development mode:
export FLASK_ENV=development
python app.py```envFor production deployment:
- Set proper environment variables
- Use a production WSGI server (gunicorn, uwsgi)
- Set up proper logging
- Configure database backups
- Set up monitoring and alerting
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.