mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-07-12 07:41:06 +08:00
RedPacket Backend Service
A Web3 Red Packet service supporting Ethereum and TRON, following the design documents:
backend-api.md- API specificationsredpacket-web3-integration-design.md- Architecture and flowsred-packet-go-backend-eth-tron.md- Blockchain integration details
Features
- ✅ Create red packet orders (
/api/redpacket/create-order) - ✅ Created callback for on-chain transaction results
- ✅ Red packet detail query with claim history
- ✅ Claim signature issuance (
/api/redpacket/claim-sign) - ✅ Claim result reporting
- ✅ SQLite/MySQL support
- ✅ Blockchain signature logic ready for ETH/TRON
- ✅ Admin configuration endpoints
Quick Start
cd cmd/openim-rpc/openim-rpc-redpacket
# 1. Configure (optional)
cp config/config.yaml config/config.yaml.bak
# Edit config/config.yaml with your blockchain settings
# 2. Build and run
go run .
# Or build binary
go build -o redpacket .
./redpacket
Service will start on http://localhost:8080
Test the API
# Health check
curl http://localhost:8080/health
# Create red packet
curl -X POST http://localhost:8080/api/redpacket/create-order \
-H "Content-Type: application/json" \
-d '{
"creator_user_id": "u1001",
"creator_wallet": "0x1111111111111111111111111111111111111111",
"packet_type": 1,
"total_amount": "1000000000000000000",
"total_shares": 10
}'
Project Structure
.
├── config/ # Configuration
├── internal/
│ ├── handler/ # HTTP handlers (Gin)
│ ├── model/ # Database models (GORM)
│ ├── repository/ # Data access layer
│ ├── service/ # Business logic
│ └── chain/ # Blockchain integration (to be expanded)
├── pkg/resp/ # Response helpers
├── router/ # Route definitions
├── main.go
├── go.mod
└── README.md
Next Steps (from design docs)
-
Full Blockchain Integration
- Implement
ChainClientfor ETH and TRON - Add event indexer for
PacketCreated,PacketClaimed,PacketRefunded - Implement proper signature generation using
getSignMessage
- Implement
-
Advanced Features
- Admin configuration APIs (
setSigner,setToken, etc.) - Refund logic
- Rate limiting and authentication
- Monitoring and metrics
- Admin configuration APIs (
-
Production
- Add proper authentication middleware
- Configure production database
- Set up monitoring and logging
- Deploy with Docker/K8s
See the three design documents for detailed specifications.
API Documentation
See backend-api.md for complete API reference with examples.