diff --git a/.env-template b/.env-template index 16a2c26..9268f58 100644 --- a/.env-template +++ b/.env-template @@ -1,7 +1,7 @@ PORT=9000 -DATABASE_URL=postgres://postgres:postgres@localhost/zeropay -REDIS=redis://127.0.0.1:6379 -MNEMONICS="12/24 words" +DATABASE_URL=postgres://postgres:postgres@postgres/zeropay +REDIS_URL=redis://redis +MNEMONICS=12/24 words WALLET=0xa0..00 APIKEY=thisisapikey WEBHOOK=https://xx.com diff --git a/.gitignore b/.gitignore index 5055eae..1004007 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Cargo.lock .env .idea .vscode +.data diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 2305435..cfe2ebf 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -82,54 +82,53 @@ This guide provides detailed instructions for deploying ZeroPay either using Doc zeropaydev/zeropay:latest ``` -### Using Docker Compose - -Create a `docker-compose.yml` file: - -```yaml -version: '3.8' - -services: - postgres: - image: postgres:16-alpine - environment: - POSTGRES_DB: zeropay - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - volumes: - - postgres_data:/var/lib/postgresql/data - ports: - - "5432:5432" - - redis: - image: redis:7-alpine - ports: - - "6379:6379" - volumes: - - redis_data:/data - - zeropay: - image: zeropaydev/zeropay:latest - depends_on: - - postgres - - redis - ports: - - "9000:9000" - env_file: - - .env - volumes: - - ./config.toml:/app/config.toml - restart: unless-stopped - -volumes: - postgres_data: - redis_data: -``` +### Using Docker Compose (Recommended) -Start all services: -```bash -docker-compose up -d -``` +The project includes a `docker-compose.yml` file that sets up PostgreSQL, Redis, and ZeroPay with all required configuration. + +1. **Configure your blockchain settings:** + + Edit `config.toml` to configure supported blockchain networks: + ```toml + [[chains]] + chain_type="evm" + chain_name="Sepolia" + latency=1 + estimation=12 + commission=5 + commission_min=50 + commission_max=200 + admin="0xYourAdminPrivateKey" + rpc="https://ethereum-sepolia.blockpi.network/v1/rpc/YOUR-API-KEY" + tokens=["USDT:0xTokenAddress"] + ``` + +2. **Edit docker-compose.yml environment variables:** + + Update the `zeropay` service environment section in `docker-compose.yml`: + ```yaml + environment: + - PORT=9000 + - DATABASE_URL=postgres://postgres:postgres@zeropay-postgres:5432/zeropay + - REDIS_URL=redis://zeropay-redis:6379 + - SCANNER_CONFIG=config.toml + - MNEMONICS=your twelve or twenty four word mnemonic phrase + - WALLET=0xYourWalletAddress + - APIKEY=your-secure-api-key + - WEBHOOK=https://your-webhook-url.com + ``` + +3. **Start all services:** + ```bash + docker-compose up -d + ``` + +4. **View logs:** + ```bash + docker-compose logs -f zeropay + ``` + +**Note:** All configuration is now in `docker-compose.yml`. The `.env` file is optional and only needed for local development without Docker. ### Building Docker Image Locally @@ -238,14 +237,17 @@ Redis requires no additional setup. Ensure it's running and accessible at the UR | Variable | Description | Example | |----------|-------------|---------| | `PORT` | API server port | `9000` | -| `DATABASE_URL` | PostgreSQL connection string | `postgres://user:pass@localhost/zeropay` | -| `REDIS` | Redis connection string | `redis://127.0.0.1:6379` | -| `MNEMONICS` | BIP39 seed phrase for wallet generation | `"word1 word2 ... word12"` | +| `DATABASE_URL` | PostgreSQL connection string | `postgres://user:pass@host:5432/zeropay` | +| `REDIS_URL` | Redis connection string | `redis://host:6379` | +| `MNEMONICS` | BIP39 seed phrase for wallet generation | `word1 word2 ... word12` | | `WALLET` | Main settlement wallet address | `0xa0..00` | | `APIKEY` | API key for authentication | `your-secure-key` | | `WEBHOOK` | Webhook URL for payment notifications | `https://your-app.com/webhook` | | `SCANNER_CONFIG` | Path to chain configuration file | `config.toml` | +**For Docker Compose:** Set these in the `environment` section of `docker-compose.yml` +**For local development:** Set these in `.env` file or as environment variables + ### Chain Configuration (`config.toml`) Each chain configuration includes: diff --git a/README.md b/README.md index e65dd8b..8913326 100644 --- a/README.md +++ b/README.md @@ -31,32 +31,54 @@ ZeroPay is a lightweight, self-hosted payment gateway that enables merchants to ## Quick Start -### Using Docker (Recommended) +### Using Docker Compose (Recommended) + +The easiest way to run ZeroPay with all dependencies: + +1. **Configure your settings:** + + Edit `docker-compose.yml` environment variables: + ```yaml + environment: + - MNEMONICS=your twelve or twenty four word mnemonic phrase + - WALLET=0xYourWalletAddress + - APIKEY=your-secure-api-key + - WEBHOOK=https://your-webhook-url.com + ``` + +2. **Configure blockchain:** + + Edit `config.toml` with your chain settings (RPC URL, tokens, etc.) + +3. **Start all services:** + ```bash + docker-compose up -d + ``` + +4. **Check logs:** + ```bash + docker-compose logs -f zeropay + ``` + +### Using Docker Standalone ```bash # Pull the latest image docker pull zeropaydev/zeropay:latest -# Create configuration -cp .env-template .env -# Edit .env with your settings - -# Run the container +# Run with environment variables docker run -d \ --name zeropay \ -p 9000:9000 \ - --env-file .env \ + -e DATABASE_URL=postgres://user:pass@host:5432/zeropay \ + -e REDIS_URL=redis://host:6379 \ + -e MNEMONICS="your mnemonic phrase" \ + -e WALLET=0xYourWallet \ + -e APIKEY=your-api-key \ -v $(pwd)/config.toml:/app/config.toml \ zeropaydev/zeropay:latest ``` -### Using Docker Compose - -```bash -# Start all services (PostgreSQL, Redis, ZeroPay) -docker-compose up -d -``` - See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed setup instructions. ## Documentation @@ -142,23 +164,21 @@ For a hassle-free experience, use our managed platform at [zeropay.dev](https:// ### Environment Variables -Create a `.env` file from the template: +**For Docker Compose:** Edit the `environment` section in `docker-compose.yml` -```bash -cp .env-template .env -``` +**For local development:** Create a `.env` file or set as environment variables Key configuration options: ```bash -PORT=9000 # API server port -DATABASE_URL=postgres://user:pass@localhost/zeropay # PostgreSQL connection -REDIS=redis://127.0.0.1:6379 # Redis connection -MNEMONICS="your twelve or twenty-four word phrase" # BIP39 seed phrase -WALLET=0xa0..00 # Settlement wallet address -APIKEY=your-secure-api-key # API authentication key -WEBHOOK=https://your-app.com/webhook # Webhook endpoint URL -SCANNER_CONFIG=config.toml # Chain config file path +PORT=9000 # API server port +DATABASE_URL=postgres://user:pass@host:5432/zeropay # PostgreSQL connection +REDIS_URL=redis://host:6379 # Redis connection +MNEMONICS=your twelve or twenty-four word phrase # BIP39 seed phrase +WALLET=0xa0..00 # Settlement wallet address +APIKEY=your-secure-api-key # API authentication key +WEBHOOK=https://your-app.com/webhook # Webhook endpoint URL +SCANNER_CONFIG=config.toml # Chain config file path ``` ### Chain Configuration diff --git a/api/src/main.rs b/api/src/main.rs index def45de..d6659bd 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -106,6 +106,8 @@ async fn main() { // setup redis connection let redis = match RedisClient::open(args.redis.clone()) { Ok(client) => { + // try connect to check + let _ = client.get_multiplexed_async_connection().await.unwrap(); info!("✅ Redis connection established!"); client } diff --git a/config.toml b/config.toml index 06c8ccc..f2ba2a1 100644 --- a/config.toml +++ b/config.toml @@ -1,11 +1,11 @@ [[chains]] chain_type="evm" -chain_name="ethereum" -latency=6 -estimation=72 # received money estimation time: 12(block time) * 6 (latency) -commission=5 # 5% commission rate, if 0, no commission -commission_min=50 # min is $0.5 -commission_max=200 # max is $2.00 -admin="xxxxxxxx" # use your admin account private key 0xaa..00 (pay gas) -rpc="https://eth-mainnet.g.alchemy.com/" # use your own rpc -tokens=["USDT:0xdAC17F958D2ee523a2206206994597C13D831ec7", "USDC:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"] \ No newline at end of file +chain_name="Sepolia" +latency=1 +estimation=12 +commission=5 +commission_min=50 +commission_max=200 +rpc="https://ethereum-sepolia.blockpi.network/v1/rpc/6753677de8aba6408d0f9ae8fb74496c727c1ebc" +admin="0x839d8f0a6cf6e4241b349399d21385826413c181d4597e36c66b8085153d0872" +tokens=["USDS:0x0dE254a722BD16C2E647B444C448D2a911deb8d5"] diff --git a/docker-compose.yml b/docker-compose.yml index daa16a8..8d6e4aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,52 +1,61 @@ -version: '3.8' +version: '3' services: postgres: image: postgres:16-alpine + container_name: zeropay-postgres + restart: unless-stopped + expose: + - 5432 environment: POSTGRES_DB: zeropay POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres volumes: - - postgres_data:/var/lib/postgresql/data - ports: - - "5432:5432" + - .data/postgres:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 10s - timeout: 5s - retries: 5 + interval: 5s + timeout: 3s + retries: 10 redis: image: redis:7-alpine - ports: - - "6379:6379" + container_name: zeropay-redis + restart: unless-stopped + expose: + - 6379 volumes: - - redis_data:/data + - .data/redis:/data healthcheck: test: ["CMD", "redis-cli", "ping"] - interval: 10s - timeout: 5s - retries: 5 + interval: 5s + timeout: 3s + retries: 10 zeropay: image: zeropaydev/zeropay:latest + container_name: zeropay-api + restart: unless-stopped + ports: + - 9000:9000 depends_on: postgres: condition: service_healthy redis: condition: service_healthy - ports: - - "9000:9000" - env_file: - - .env volumes: - ./config.toml:/app/config.toml - restart: unless-stopped environment: - - DATABASE_URL=postgres://postgres:postgres@postgres/zeropay - - REDIS=redis://redis:6379 + - PORT=9000 + - DATABASE_URL=postgres://postgres:postgres@zeropay-postgres:5432/zeropay + - REDIS_URL=redis://zeropay-redis:6379 + - SCANNER_CONFIG=config.toml + - MNEMONICS="12/24 words" # your mnemonics code for generate accounts + - WALLET=0x00xxx00 # your received money account + - APIKEY=thisisapikey # your service apikey when create/query sessions + - WEBHOOK=https://xx.com # your webhook url -volumes: - postgres_data: - redis_data: +networks: + default: + name: zeropay