Skip to content

Commit 30f11be

Browse files
Merge pull request #29 from GalaxySciTech/cursor/tokencore-multichain-optimize-5cc6
Tokencore 2.0.1, monolith Docker/CI, external signing, DB token catalog
2 parents f47248c + 65385fa commit 30f11be

43 files changed

Lines changed: 497 additions & 359 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
# Database
1+
# Database (Spring Boot reads DB_URL / DB_USERNAME / DB_PASSWORD)
22
DB_URL=jdbc:mysql://127.0.0.1:3306/wallet_db?allowMultiQueries=true&useSSL=false&characterEncoding=UTF-8&autoReconnect=true
33
DB_USERNAME=root
44
DB_PASSWORD=your_secure_password
55

6-
# RabbitMQ
7-
RABBITMQ_HOST=127.0.0.1
8-
RABBITMQ_PORT=5672
9-
RABBITMQ_USERNAME=guest
10-
RABBITMQ_PASSWORD=guest
6+
# Server
7+
SERVER_PORT=8080
118

12-
# XXL-Job
13-
XXL_JOB_ADMIN_ADDRESSES=http://127.0.0.1:8099/xxl-job-admin
14-
XXL_JOB_PORT=9999
15-
XXL_JOB_ACCESS_TOKEN=your_access_token
16-
17-
# HSM Keystore
9+
# Keystore (tokencore / WalletManager)
1810
KEYSTORE_DIR=/data/keystores
19-
KEYSTORE_PASSWORD=your_keystore_password
11+
WALLET_KEYSTORE_PASSWORD=your_keystore_password
2012

21-
# Encryption
22-
WALLET_CRYPTO_PUSH_KEY=your_32_char_encryption_key_here
13+
# Optional: EOS deposit address for EOS flows
14+
EOS_DEPOSIT_ADDRESS=
15+
16+
# Tokencore signing chain ids (H2 testnet example: ETH_SIGN_CHAIN_ID=11155111, BTC_SIGN_CHAIN_ID=1)
17+
ETH_SIGN_CHAIN_ID=1
18+
BTC_SIGN_CHAIN_ID=0
19+
20+
# External signer (when wallet_chain_config.signing_backend = EXTERNAL)
21+
EXTERNAL_SIGNER_BASE_URL=
22+
23+
# Optional ETH gas price HTTP fallback (JSON shape must match ETH_GAS_LEVEL keys)
24+
ETH_GAS_FALLBACK_URL=
2325

2426
# Logging
2527
LOG_LEVEL=INFO
28+
29+
# Encryption (if used by your deployment)
30+
WALLET_CRYPTO_PUSH_KEY=your_32_char_encryption_key_here

.github/workflows/ci.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,57 @@ jobs:
1313
build:
1414
name: Build & Test
1515
runs-on: ubuntu-latest
16-
16+
1717
steps:
1818
- uses: actions/checkout@v4
19-
19+
2020
- name: Set up JDK 17
2121
uses: actions/setup-java@v4
2222
with:
2323
java-version: '17'
2424
distribution: 'temurin'
25-
25+
2626
- name: Setup Gradle
2727
uses: gradle/actions/setup-gradle@v3
2828
with:
2929
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
30-
30+
3131
- name: Grant execute permission for gradlew
3232
run: chmod +x gradlew
33-
33+
3434
- name: Build
3535
run: ./gradlew build -x test --no-daemon
36-
36+
3737
- name: Run tests
3838
run: ./gradlew test --no-daemon
3939
continue-on-error: true
40-
40+
4141
- name: Upload build artifacts
4242
uses: actions/upload-artifact@v4
4343
with:
4444
name: build-artifacts
4545
path: |
46-
wallet-webapi/build/libs/*.jar
47-
wallet-task/build/libs/*.jar
48-
wallet-hsm/build/libs/*.jar
46+
build/libs/*.jar
4947
retention-days: 7
5048

5149
docker:
5250
name: Docker Build
5351
runs-on: ubuntu-latest
5452
needs: build
5553
if: github.ref == 'refs/heads/master'
56-
57-
strategy:
58-
matrix:
59-
service: [wallet-webapi, wallet-task, wallet-hsm]
60-
54+
6155
steps:
6256
- uses: actions/checkout@v4
63-
57+
6458
- name: Set up Docker Buildx
6559
uses: docker/setup-buildx-action@v3
66-
60+
6761
- name: Build Docker image
6862
uses: docker/build-push-action@v5
6963
with:
7064
context: .
71-
file: ./${{ matrix.service }}/Dockerfile
65+
file: ./Dockerfile
7266
push: false
73-
tags: ${{ matrix.service }}:${{ github.sha }}
67+
tags: wallet-app:${{ github.sha }}
7468
cache-from: type=gha
7569
cache-to: type=gha,mode=max

.gitlab-ci.yml

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,75 +19,25 @@ build:
1919
stage: build
2020
script:
2121
- chmod +x ./gradlew
22-
- ./gradlew wallet-webapi:bootJar --no-daemon -x test
23-
- ./gradlew wallet-task:bootJar --no-daemon -x test
24-
- ./gradlew wallet-hsm:bootJar --no-daemon -x test
22+
- ./gradlew bootJar --no-daemon -x test
2523
artifacts:
2624
paths:
27-
- wallet-webapi/build/libs/*.jar
28-
- wallet-hsm/build/libs/*.jar
29-
- wallet-task/build/libs/*.jar
25+
- build/libs/*.jar
3026
expire_in: 1 hour
3127

32-
deploy wallet-webapi:
28+
deploy wallet-app:
3329
image: docker:latest
3430
services:
3531
- docker:dind
3632
tags:
3733
- wallet-dev
3834
stage: deploy
3935
script:
40-
- docker stop wallet-webapi || true
41-
- docker rm wallet-webapi || true
42-
- docker rmi wallet-webapi || true
43-
- docker build -t wallet-webapi -f wallet-webapi/Dockerfile .
44-
- docker run -d --name wallet-webapi
45-
--restart unless-stopped
46-
-p 10001:10001
47-
-v /etc/localtime:/etc/localtime:ro
48-
--env-file /etc/wallet/webapi.env
49-
wallet-webapi
50-
when: manual
51-
52-
deploy wallet-task:
53-
image: docker:latest
54-
services:
55-
- docker:dind
56-
tags:
57-
- wallet-dev
58-
stage: deploy
59-
script:
60-
- docker stop wallet-task || true
61-
- docker rm wallet-task || true
62-
- docker rmi wallet-task || true
63-
- docker build -t wallet-task -f wallet-task/Dockerfile .
64-
- docker run -d --name wallet-task
65-
--restart unless-stopped
66-
-p 10033:10033
67-
-v /etc/localtime:/etc/localtime:ro
68-
--env-file /etc/wallet/task.env
69-
wallet-task
70-
when: manual
71-
72-
deploy wallet-hsm:
73-
image: docker:latest
74-
services:
75-
- docker:dind
76-
tags:
77-
- wallet-dev
78-
stage: deploy
79-
script:
80-
- docker stop wallet-hsm || true
81-
- docker rm wallet-hsm || true
82-
- docker rmi wallet-hsm || true
83-
- docker build -t wallet-hsm -f wallet-hsm/Dockerfile .
84-
- docker run -d --name wallet-hsm
85-
--restart unless-stopped
86-
-p 10888:10888
87-
-v /etc/localtime:/etc/localtime:ro
88-
-v /mnt/wallets:/data/keystores
89-
--env-file /etc/wallet/hsm.env
90-
wallet-hsm
36+
- docker stop wallet-app || true
37+
- docker rm wallet-app || true
38+
- docker rmi wallet-app || true
39+
- docker build -t wallet-app -f Dockerfile .
40+
- docker run -d --name wallet-app --restart unless-stopped -p 8080:8080 -v /etc/localtime:/etc/localtime:ro -v /mnt/wallets:/data/keystores --env-file /etc/wallet/wallet.env wallet-app
9141
when: manual
9242

9343
after_script:

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Single-module Spring Boot app (sources under ./src)
2+
FROM eclipse-temurin:17-jdk-alpine AS builder
3+
WORKDIR /app
4+
COPY gradlew gradlew.bat settings.gradle build.gradle gradle.properties ./
5+
COPY gradle ./gradle
6+
COPY src ./src
7+
RUN chmod +x gradlew && ./gradlew bootJar --no-daemon -x test
8+
9+
FROM eclipse-temurin:17-jre-alpine
10+
WORKDIR /app
11+
RUN addgroup -S wallet && adduser -S wallet -G wallet
12+
COPY --from=builder /app/build/libs/*.jar /app/app.jar
13+
USER wallet
14+
EXPOSE 8080
15+
ENV SERVER_PORT=8080
16+
ENTRYPOINT ["java","-XX:+UseContainerSupport","-XX:MaxRAMPercentage=75.0","-jar","/app/app.jar"]

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ It provides unified wallet management, blockchain synchronization, deposit detec
99

1010
This repository is converging to a **single-service architecture** to make deployment and operations simpler:
1111

12-
- One startup service (`wallet-webapi` runtime)
12+
- One Spring Boot service (sources under [`src/`](src/); root Gradle module)
1313
- No RabbitMQ dependency
1414
- No xxl-job dependency
15-
- HSM capabilities invoked in-process
16-
- Unified tokencore dependency: `com.github.galaxyscitech:tokencore:2.0.0`
15+
- HSM / signing invoked in-process via [tokencore](https://github.com/GalaxySciTech/tokencore) `com.github.galaxyscitech:tokencore:2.0.1`
16+
- Optional **external HTTP signer** when `wallet_chain_config.signing_backend` = `EXTERNAL` (see `wallet.external-signer` in [`application.yml`](src/main/resources/application.yml))
1717

1818
This means fewer moving parts, easier troubleshooting, and faster onboarding for developers and DevOps teams.
1919

@@ -67,9 +67,27 @@ Services:
6767
### Option B: Run locally with Gradle
6868

6969
```bash
70-
./gradlew :wallet-webapi:bootRun
70+
./gradlew bootRun
7171
```
7272

73+
Initialize the database from [`db/wallet_db.sql`](db/wallet_db.sql). If you already have `wallet_chain_config`, apply [`db/002_wallet_chain_signing_backend.sql`](db/002_wallet_chain_signing_backend.sql) for the `signing_backend` column.
74+
75+
### Configuration highlights
76+
77+
| Area | Notes |
78+
|------|--------|
79+
| JDBC | `DB_URL`, `DB_USERNAME`, `DB_PASSWORD` (see [`.env.example`](.env.example)) |
80+
| Keystore | `KEYSTORE_DIR`, `WALLET_KEYSTORE_PASSWORD` |
81+
| Testnet signing | `ETH_SIGN_CHAIN_ID` (e.g. `11155111` for Sepolia), `BTC_SIGN_CHAIN_ID` (`0` mainnet / `1` testnet) |
82+
| Metrics | Actuator: `/actuator/health`, `/actuator/prometheus` |
83+
| Gas fallback | Optional `ETH_GAS_FALLBACK_URL` in `sys_config` if the node does not expose `eth_gasPrice` |
84+
85+
### H2 (testnet on-chain smoke)
86+
87+
1. Point `ETH_RPC_URL` in `config` (or env) to a **Sepolia** (or other testnet) HTTP endpoint.
88+
2. Set `ETH_SIGN_CHAIN_ID=11155111` and fund a test hot wallet.
89+
3. Run `./gradlew bootRun` and exercise withdraw/collect paths from Swagger or your integration client.
90+
7391
---
7492

7593
## First-time user path (10-minute onboarding)

README_CN.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
项目正在收敛为**单体 Spring Boot 钱包服务**
44

55
## 当前变化
6-
- 统一单服务启动(以 `wallet-webapi` 作为应用运行时)
7-
- 不再依赖 RabbitMQ
8-
- 不再依赖 xxl-job
9-
- HSM 能力改为进程内调用
10-
- tokencore 统一为 `com.github.galaxyscitech:tokencore:2.0.0`
6+
- **单模块**:源码仅在仓库根目录 [`src/`](src/),Gradle 在根目录 [`build.gradle`](build.gradle)
7+
- 不再依赖 RabbitMQ / xxl-job
8+
- 签名与地址:**tokencore** `com.github.galaxyscitech:tokencore:2.0.1`(进程内)
9+
- 可选 **外部 HTTP 签名**:表 `wallet_chain_config.signing_backend = EXTERNAL`,配置 `wallet.external-signer.base-url`
1110

1211
## 快速开始
1312
### 1)Docker Compose 启动
@@ -21,9 +20,13 @@ docker compose up -d --build
2120

2221
### 2)手动启动
2322
```bash
24-
./gradlew :wallet-webapi:bootRun
23+
./gradlew bootRun
2524
```
2625

26+
数据库初始化见 [`db/wallet_db.sql`](db/wallet_db.sql)。若已有库,需增加 `signing_backend` 列时执行 [`db/002_wallet_chain_signing_backend.sql`](db/002_wallet_chain_signing_backend.sql)
27+
28+
环境变量示例:[`.env.example`](.env.example)。测试网链上冒烟:配置 Sepolia 等 `ETH_RPC_URL`,设置 `ETH_SIGN_CHAIN_ID=11155111`,准备测试资金后走 Swagger 提现/归集相关接口。
29+
2730
## 接口
2831
- 钱包接口:`/wallet/v1`
2932
- 链接口:`/block_chain/v1`

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ dependencies {
3030
implementation 'wf.bitcoin:bitcoin-rpc-client:1.2.4'
3131
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
3232
implementation 'com.github.sealedtx:bitcoin-cash-converter:1.0'
33-
implementation 'com.github.galaxyscitech:tokencore:2.0.0'
33+
implementation 'com.github.galaxyscitech:tokencore:2.0.1'
34+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
35+
implementation 'io.micrometer:micrometer-registry-prometheus'
3436
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
3537
implementation 'commons-codec:commons-codec:1.16.0'
3638
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'

build.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
./gradlew bootRepackage
3-
rm -rf build/*
4-
mv wallet-webapi/build/libs/*.jar build/
5-
mv wallet-task/build/libs/*.jar build/
6-
mv wallet-hsm/build/libs/*.jar build/
2+
set -e
3+
./gradlew bootJar --no-daemon -x test
4+
rm -rf build/dist
5+
mkdir -p build/dist
6+
cp build/libs/*.jar build/dist/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Optional migration: per-chain signing backend (TOKENCORE | EXTERNAL)
2+
ALTER TABLE `wallet_chain_config`
3+
ADD COLUMN `signing_backend` varchar(32) NOT NULL DEFAULT 'TOKENCORE'
4+
COMMENT 'TOKENCORE=in-process tokencore; EXTERNAL=wallet.external-signer HTTP'
5+
AFTER `withdraw_enabled`;

db/wallet_db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ CREATE TABLE `wallet_chain_config` (
331331
`enabled` tinyint(1) DEFAULT 1,
332332
`deposit_scan_enabled` tinyint(1) DEFAULT 1,
333333
`withdraw_enabled` tinyint(1) DEFAULT 0,
334+
`signing_backend` varchar(32) NOT NULL DEFAULT 'TOKENCORE' COMMENT 'TOKENCORE|EXTERNAL',
334335
`confirmations` int(11) DEFAULT 12,
335336
`start_block` bigint(20) DEFAULT 0,
336337
`current_block` bigint(20) DEFAULT 0,

0 commit comments

Comments
 (0)