Compare commits

...
39 Commits
Author SHA1 Message Date
admin 6658614db0 fix(tls): 镜像内补装 Let's Encrypt 新根证书 ISRG Root YE
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
背景:sale(waiguoyan.com)的证书由 LE 新版中间证书 YE2 签发,链的根是 2025 年新增的
ISRG Root YE。alpine 3.20 / debian 12 的 ca-certificates 里都没有这个根,实测:
  docker exec vupay wget https://waiguoyan.com/ → SSL_connect 失败
后果:客户付款后 VUPAY 的异步回调发不出去,sale 订单不会自动变已支付。

做法:把 ISRG Root YE(自签根 + by-X2 交叉签名版)放进镜像并 update-ca-certificates。
证书来自 https://letsencrypt.org/certs/gen-y/,是公开根,随仓库分发无风险。
2026-11-25 09:37:36 +08:00
admin 051e475b44 merge feat/full-rename:协议标识与表前缀改为 vupay
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-25 09:24:08 +08:00
admin 2ece12d44b rebrand: 收尾 —— 协议标识与表前缀一并换成 vupay
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 13s
之前刻意保留的三处,在没有订单数据的前提下一起改掉:
- 表前缀 bep_ → vupay_(6 张表 + gormigrate 的 vupay_migration)
- api_type 取值 "epusdt"/"epusdt_order" → "vupay"/"vupay_order"
- handler 包 app/handler/epusdt → app/handler/vupay、类型 Epusdt → Vupay、EpusdtSign → VupaySign

顺带清理:
- 删 docs/faq/vupay.md(整篇是「本项目和 EPusdt 的关系」的上游叙事)
- README 去掉「缘起于/原项目已转手」说明与上游致谢条目,联系邮箱不再指向 vupay.online
- 修 app/task/testenv_test.go 的 model.Init 调用(上一版加 MySQL 支持时漏了第三个参数,go build 不编译测试所以没暴露)

验证:go build ./... / go vet ./... / go test ./app/... 全通过;全仓 grep -i epusdt 归零
2026-11-25 09:22:48 +08:00
admin 79b6b914aa rebrand: 收银台 logo 图形换成 V 字标(原文件名 bepusdt.svg + 内容为 B 字标)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-25 09:13:42 +08:00
admin 38231b15cb merge feat/rebrand-vupay:品牌改为 VUPAY
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 11s
2026-11-25 09:08:26 +08:00
admin a950fd2ead rebrand: BEpusdt → VUPAY
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 47s
展示层与标识符全量改名:
- module github.com/v03413/bepusdt → git.viaeon.com/admin/vupay(含全部 import)
- 二进制/镜像/容器/DB 名 bepusdt → vupay(Dockerfile、workflow IMAGE、compose、docs)
- 显示名 BEpusdt → VUPAY(前端 title、后端 banner、version 命令、通知文案)
- 默认路径 /var/lib/bepusdt → /var/lib/vupay,/var/log/bepusdt → /var/log/vupay
- Telegram 通知的频道按钮原来指向上游 t.me 群,改成站点链接(否则改名后是死链)

刻意保留(运行语义,改了会坏):
- api_type 取值 "epusdt" / "epusdt_order"(库里存量数据按此匹配)
- 表前缀 bep_(bep_order / bep_conf / …,改需 RENAME TABLE 迁移)
- 签名函数 EpusdtSign 与 handler 包名 epusdt(对外协议语义,非品牌)
- 所有加密/会话派生的字面量原样不动

验证:gofmt 通过、go build ./... 通过、全仓 grep -i bepusdt 归零
2026-11-25 09:06:06 +08:00
admin 7421d8574b merge ci/mysql-perf:bep_order 复合索引
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 16s
2026-11-25 08:50:13 +08:00
admin 92cca8a420 perf(db): bep_order 加 (status,trade_type) 复合索引
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 13s
动机:转账/回调任务反复跑 WHERE status=? AND trade_type IN (...),原来只有单列索引。
10 万行实测(同机 mysql:8.0,1 核):
  IN 两个值:   21.5ms → 0.9ms
  IN 单值:     25.4ms → 16.0ms
  COUNT:       11.4ms → 1.6ms
空表/小表无感,订单积累后差距明显。AutoMigrate 会在新库上自动建同名索引。

顺带:示例 compose 的小机器参数注释更新(buffer pool 256M、慢日志 1s)
2026-11-25 08:49:06 +08:00
admin f94687788d merge ci/compose-shared:MySQL 示例改用共享服务名 mysql
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-25 08:26:50 +08:00
admin fee63db19e docs(compose): MySQL 示例改成通用服务名 mysql + 共享网络
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
- 服务名/容器名 db/bepusdt-db → mysql,DSN host 同步改成 mysql
- 挂 external 网络 shared-db(AcePanel 用 acepanel-network),同机其它容器可按 mysql:3306 复用
- 3306 只绑 127.0.0.1(宿主机/SSH 隧道用),不对外
- docs: 补「给同机其它容器共用」小节:建网络、其它项目怎么写、独立库+账号的 SQL、两个易错点
2026-11-25 08:24:45 +08:00
admin 4a866731f3 merge ci/build-cache:go build 缓存挂载 + 并行度限制 4(构建期 CPU 峰值 99%→35%,耗时 43s→9.4s)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-24 21:28:56 +08:00
admin bf686e6f08 chore: 缓存热 + 采样
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-24 21:25:54 +08:00
admin b5c330e311 chore: 缓存已热,测第二次构建
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 10s
2026-11-24 21:22:49 +08:00
admin eea05adea1 perf(docker): go build 加 cache mount 并把并行编译钉在 4
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 45s
动机:构建期 go build 按 nproc=8 开并行,7~8 个 compile 进程把 8 核打满(实测整机 96-99%),
而这台机器还跑着 verify 生产 MySQL 和 Gitea。
- --mount=type=cache 让 /go/pkg/mod 与 go-build 缓存持久化,后续提交只重编 main 包
- -p 4 限制并行编译进程数,峰值从 8 核降到 4 核
2026-11-24 21:19:41 +08:00
admin a3f4587d1e merge docs/mysql-compose:MySQL 文档与 compose 示例
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 42s
2026-11-24 20:09:35 +08:00
admin 4e01e9809e docs: MySQL 段改成「本仓库已支持」,并补三份 compose 示例
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 45s
- docs/docker/docker.md:上游不支持 MySQL 的事实写清楚;本仓库自 e7a8dd9 起
  支持(MYSQL_DSN),给建库 SQL、DSN 三个必带参数各自的后果、8.0 版本建议
- 新增 docker-compose{.postgres,.mysql}.example.yml 三份可直接用的示例
- .env.example 补 MYSQL_DSN 与优先级说明
- .gitignore 忽略 compose 运行时产生的 data/ logs/ mysqldata/ pgdata/
- README 补本仓库差异说明(CI 镜像地址 + compose 示例 + MySQL 支持)
2026-11-24 20:08:28 +08:00
admin e7a8dd9681 merge feat/mysql:支持 MySQL(MYSQL_DSN)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 42s
2026-11-24 20:02:21 +08:00
admin 0ae8a9be0f ci: latest tag 只在 main 分支打,特性分支不再顶掉 latest
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 42s
2026-11-24 20:01:22 +08:00
admin 647e1b96b1 feat(db): 支持 MySQL(MYSQL_DSN 环境变量 / --mysql 参数)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 46s
- app/cmd/flag.go: 新增 MysqlDSNFlag(env MYSQL_DSN)
- start/reset: 读取并传给 model.Init
- model.Init 改为三选一:MySQL > PostgreSQL > SQLite
- 新增 initMysql():连接池参数对齐 Postgres 那套(10/100、30m 生命周期)
- order.go: return_url / notify_url 从 TEXT 改 VARCHAR(1024)
  MySQL 8 不允许 TEXT 列带 DEFAULT(Error 1101),改 varchar 三库通用

实测(真 mysql:8.0 容器):6 张表全部建出,bep_order 列类型符合预期
2026-11-24 19:58:08 +08:00
admin ca239fbce4 ci: 合入 Gitea Actions Docker 构建流程
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 43s
2026-11-24 19:14:16 +08:00
admin 963c80aaa0 ci: 修正 docker tag(分支名 ci/xxx 里的斜杠换成短横线)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 1m40s
2026-11-24 19:10:04 +08:00
admin be344b97f7 ci: 触发重跑(已配好仓库级 TOKEN secret)
Docker Build (Gitea) / Build and Push Docker Image (push) Failing after 11s
2026-11-24 19:06:21 +08:00
admin 59d23a2dc7 ci: 加 Gitea Actions 构建并推送 Docker 镜像(git.viaeon.com/admin/bepusdt)
Docker Build (Gitea) / Build and Push Docker Image (push) Failing after 3s
2026-11-24 19:00:13 +08:00
v03413 8a91be6a15 chore: .gitignore update 2026-11-13 09:38:22 +08:00
v03413 8ff1bce889 docs: 更新安全问题反馈联系邮箱 2026-11-13 09:37:06 +08:00
v03413 5791328de4 refactor: 合并 TON 转账解析的入站消息处理并补充单元测试 2026-11-13 09:20:39 +08:00
v03413 566aa5a486 fix: 修正 stale issue 提示信息中的天数为 3 天 2026-11-10 14:37:55 +08:00
莫名 78db081b35 Merge pull request #248 from sylearn/feat/truncate-match-mode
fix: 前缀匹配按原子精度补齐后比较,并发订单不互相抢付款
2026-11-01 22:10:19 +08:00
sylearn c592d3fb7a fix: fold truncate matching into has_prefix
Per review, drop the separate truncate mode and use its logic for
has_prefix instead. Order amounts are stored without trailing zeros
(1.50 as "1.5"), so the plain string prefix check let the 1.5 order
claim a 1.51 payment meant for a concurrent order on the same address.
Truncate the received amount to the larger of the atom precision and
the order's own decimals, then compare exactly: overpayment below the
atom precision still matches, underpayment and overpayment of a full
atom no longer do.
2026-11-01 22:49:44 +09:00
sylearn 5cb1d6f099 feat: add truncate amount match mode
Truncate the received amount to the atom precision before an exact comparison, so overpayment below the atom precision still matches while concurrent orders on one address (1.50, 1.51, ...) never claim each other's payments.
2026-10-31 23:45:49 +09:00
莫名 ebff24a190 Merge pull request #246 from sylearn/fix/solana-forward-tolerates-slot-retries
fix(solana): keep scanning forward while a few slots retry
2026-10-29 17:33:31 +08:00
莫名 5a1f9def13 Merge pull request #244 from sylearn/fix/solana-pruned-slot-no-retry
fix(solana): give up on slots the node has cleaned up
2026-10-29 17:33:22 +08:00
莫名 448cda9022 Merge pull request #243 from sylearn/fix/solana-drop-stale-lookback
fix(solana): drop lookback ranges of finished orders
2026-10-29 17:33:12 +08:00
sylearn 6784a98c8e test(solana): cover backpressure threshold and recovery 2026-10-29 00:46:44 +08:00
sylearn d54669a8aa fix(solana): keep cleaned slots terminal under concurrency 2026-10-29 00:46:26 +08:00
sylearn 5b3a1ded6d fix(solana): keep lookback progress when the order query fails
lookbackOrdersPending ignored the query error, so a failed read counted
as "no order needs a lookback" and dropped the progress of a range that
was still needed. Return the error and keep the progress until the next
tick can check again.
2026-10-28 13:27:18 +08:00
sylearn 144cdb8c40 fix(solana): keep scanning forward while a few slots retry
syncSlotForward stops fetching the head slot as soon as any slot waits
for a retry. One slot that keeps failing with a timeout, 429 or -32004
therefore holds back every later payment until it succeeds or is given
up after about 7 minutes, although the following slots can be fetched
normally.

Pause forward scanning only when solanaForwardPauseRetries (10) slots
wait for a retry. That still stops new slots from piling into the retry
set during a node outage, while a single failing slot no longer delays
new payments.
2026-10-28 13:24:12 +08:00
sylearn 9131b9d5c4 fix(solana): give up on slots the node has cleaned up
getBlock returns -32001 (BlockCleanedUp) for a slot older than the
node's first available block. Retrying cannot succeed, yet the slot was
retried 10 times over about 7 minutes, and forward scanning stays paused
while any retry is pending.

In production a lookback range from a week earlier hit this for 627
slots at once: forward scanning stopped for about 10 minutes and the
node started to answer 429, which delayed a real payment by four
minutes.

Treat -32001 as final: log an ERROR with the slot number, clear any
retry left from an earlier failure of the same slot, and do not schedule
another one. Other errors keep the bounded retry. The existing retry
test now uses -32004 (block not available), a transient error.
2026-10-28 12:59:38 +08:00
sylearn 2fdb6e81d3 fix(solana): drop lookback ranges of finished orders
lookbackSlots keeps its progress (lookbackNext/lookbackEnd) across ticks,
but returns early through syncBreak once no order needs scanning. When an
order is paid, canceled or expires before its range is fully queued, the
remainder stays in memory. The next Solana order, possibly days later,
resumes that old range first.

In production the remainder was 627 slots from a week earlier. The RPC
node had already pruned them (-32001), every slot was retried, forward
scanning paused while retries were pending, and the node started to
answer 429. A payment made 90 seconds after the order was created was
seen four minutes late.

Before resuming, check that at least one order of the range still needs
a lookback (same condition as hasLookbackOrders); otherwise drop the
remaining range. The check runs before syncBreak so the state is also
cleared while scanning is idle.
2026-10-28 12:58:19 +08:00
141 changed files with 1596 additions and 652 deletions
+7 -3
View File
@@ -2,10 +2,14 @@
LISTEN=127.0.0.1:8080
# 日志文件保存路径
LOG=/var/log/bepusdt/
LOG=/var/log/vupay/
# SQLite 数据库文件路径(如果使用 MySQL,此项可忽略)
SQLITE=/var/lib/bepusdt/sqlite.db
SQLITE=/var/lib/vupay/sqlite.db
# PostgreSQL 数据库
# POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3&timezone=Asia/Shanghai
# POSTGRESQL_DSN=postgres://user:password@localhost:5432/vupay?sslmode=disable&connect_timeout=3&timezone=Asia/Shanghai
# MySQL 数据库(本仓库支持;DSN 里 charset=utf8mb4&parseTime=True&loc=Local 不能省)
# 优先级:MYSQL_DSN > POSTGRESQL_DSN > SQLITE
# MYSQL_DSN=user:password@tcp(127.0.0.1:3306)/vupay?charset=utf8mb4&parseTime=True&loc=Local&timeout=5s
+83
View File
@@ -0,0 +1,83 @@
name: Docker Build (Gitea)
on:
push:
branches:
- main
- 'ci/**'
tags:
- 'v*'
workflow_dispatch:
env:
REGISTRY: git.viaeon.com
IMAGE: git.viaeon.com/admin/vupay
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli git
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io git
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Prepare version
id: ver
run: |
SHORT_SHA=$(git rev-parse --short=7 HEAD)
BASE=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
# 分支名可能带斜杠(ci/xxx),docker tag 不允许,统一换成短横线
REF_SLUG=$(echo "${GITHUB_REF_NAME}" | tr '/' '-')
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "ref_slug=${REF_SLUG}" >> "$GITHUB_OUTPUT"
echo "version=${BASE}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "VERSION=${BASE}-${SHORT_SHA}"
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.TOKEN }}" | docker login "${{ env.REGISTRY }}" -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build Docker image
run: |
# latest 只给 main,特性分支别把 latest 顶掉
TAGS="-t ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }} -t ${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}"
if [ "${GITHUB_REF_NAME}" = "main" ]; then TAGS="$TAGS -t ${{ env.IMAGE }}:latest"; fi
docker build \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--build-arg "VERSION=${{ steps.ver.outputs.version }}" \
$TAGS .
- name: Push Docker image
run: |
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}" 2>&1
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}" 2>&1
if [ "${GITHUB_REF_NAME}" = "main" ]; then docker push "${{ env.IMAGE }}:latest" 2>&1; fi
- name: Summary
run: |
echo "镜像已推送:"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}"
echo " ${{ env.IMAGE }}:latest"
+2 -2
View File
@@ -1,5 +1,5 @@
name: BUG 反馈|使用异常|功能建议|其它问题
description: "提交在使用 BEpusdt 过程中遇到的 BUG 反馈、使用异常、对接失败等问题"
description: "提交在使用 VUPAY 过程中遇到的 BUG 反馈、使用异常、对接失败等问题"
body:
- type: checkboxes
attributes:
@@ -45,7 +45,7 @@ body:
attributes:
value: |-
## 日志信息
默认的日志目录在 `/var/log/bepusdt/` 下,请将相关时间段的日志内容粘贴在下面的代码块中。
默认的日志目录在 `/var/log/vupay/` 下,请将相关时间段的日志内容粘贴在下面的代码块中。
- type: textarea
attributes:
label: 日志内容
+1 -1
View File
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Telegram Group
url: https://t.me/BEpusdtChat
url: https://t.me/VUPAYChat
about: Telegram 交流群组
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
days-before-issue-stale: 3
days-before-issue-close: 7
stale-issue-label: "stale"
stale-issue-message: "此议题由于30天内没有任何活动,现在标记为过时。"
stale-issue-message: "此议题由于3天内没有任何活动,现在标记为过时。"
close-issue-message: "此议题被标记为过时并且在7天内没有活动,因此已被关闭。请随时重新打开此议题以继续讨论。"
days-before-pr-stale: -1
days-before-pr-close: -1
+2 -2
View File
@@ -7,8 +7,8 @@ on:
tags:
- v*
env:
APP_NAME: bepusdt
DOCKERHUB_REPO: v03413/bepusdt
APP_NAME: vupay
DOCKERHUB_REPO: admin/vupay
jobs:
docker:
runs-on: ubuntu-latest
+2 -2
View File
@@ -4,9 +4,9 @@ on:
- cron: '0 16 * * *'
workflow_dispatch:
env:
APP_NAME: bepusdt
APP_NAME: vupay
DOCKER_HUB_USER: v03413
DOCKER_HUB_REPO: v03413/bepusdt
DOCKER_HUB_REPO: admin/vupay
jobs:
build:
runs-on: ubuntu-latest
+1 -1
View File
@@ -14,7 +14,7 @@ concurrency:
permissions:
contents: read
env:
APP_NAME: bepusdt
APP_NAME: vupay
jobs:
docker-build:
name: Docker Build
+6 -1
View File
@@ -9,4 +9,9 @@ dist/
static/web
static/secure
*.log
AGENTS.md
AGENTS.md
CLAUDE.md
data/
logs/
mysqldata/
pgdata/
+3 -3
View File
@@ -1,12 +1,12 @@
version: 2
project_name: BEpusdt
project_name: VUPAY
env:
- GO111MODULE=on
builds:
- env:
- CGO_ENABLED=0
main: ./main
binary: bepusdt
binary: vupay
ldflags:
- -X '{{ .ModulePath }}/app.Version={{ .Env.VERSION }}'
- -s -w -buildid=
@@ -25,7 +25,7 @@ archives:
formats: [ zip ]
files:
- .env.example
- src: docs/bepusdt.service
- src: docs/vupay.service
dst: .
strip_parent: true
changelog:
+28 -24
View File
@@ -4,34 +4,33 @@
---
# BEpusdt (Better Easy Payment USDT)
# VUPAY (Better Easy Payment USDT)
<p align="center">
<img src="./static/checkout/official/assets/img/bepusdt.svg" width="15%" alt="tether">
<img src="./static/checkout/official/assets/img/vupay.svg" width="15%" alt="tether">
</p>
<p align="center">
<a href="https://www.gnu.org/licenses/gpl-3.0.html">
<img src="https://img.shields.io/github/license/v03413/bepusdt" alt="license GPLV3">
<img src="https://img.shields.io/github/license/admin/vupay" alt="license GPLV3">
</a>
<a href="https://github.com/v03413/bepusdt">
<img src="https://img.shields.io/github/v/release/v03413/bepusdt" alt="GitHub Release">
<a href="https://git.viaeon.com/admin/vupay">
<img src="https://img.shields.io/github/v/release/admin/vupay" alt="GitHub Release">
</a>
<a href="https://github.com/v03413/bepusdt">
<img src="https://img.shields.io/github/downloads/v03413/bepusdt/total" alt="GitHub Release">
<a href="https://git.viaeon.com/admin/vupay">
<img src="https://img.shields.io/github/downloads/admin/vupay/total" alt="GitHub Release">
</a>
<a href="https://hub.docker.com/r/v03413/bepusdt">
<img src="https://img.shields.io/docker/pulls/v03413/bepusdt?style=flat-square&logo=docker" alt="Docker Pulls">
<a href="https://hub.docker.com/r/admin/vupay">
<img src="https://img.shields.io/docker/pulls/admin/vupay?style=flat-square&logo=docker" alt="Docker Pulls">
</a>
<a href="https://github.com/gin-gonic/gin">
<img src="https://img.shields.io/github/stars/v03413/bepusdt?style=flat-square&logo=github" alt="GitHub Stars">
<img src="https://img.shields.io/github/stars/admin/vupay?style=flat-square&logo=github" alt="GitHub Stars">
</a>
</p>
## 🪧 介绍
缘起于`Epusdt`,但不仅限于此,加入了一些新特性,致力于成为一款更好用的个人`加密货币`收款网关。
VUPAY 是一款个人`加密货币`收款网关:多链收款、订单自动回调、后台可视化管理。
> 原始 EPusdt 项目已被转手,现与本项目再没任何联系、两个项目完全独立运营,[具体说明](./docs/faq/epusdt.md)。
## 🎉 新特性
@@ -40,7 +39,7 @@
🔥 主流网络:TRON Ethereum BSC Polygon<br>
⚡ 其他网络: X-Layer Solana Aptos Arbitrum-One Base [完整列表](./docs/trade-type.md)
- ✅ 完全兼容 `Epusdt` 插件无缝替换
- ✅ 完全兼容 `Vupay` 插件无缝替换
- ️✅ 支持主流区块网络 不仅限于`USDT`
- ✅ 支持主流法定货币 汇率自动更新
- ✅ 轻依赖 单体二进制文件 部署便捷
@@ -55,13 +54,20 @@
Docker 快速启动,执行完命令打开地址`http://服务器IP:8080`即可看到初始页面
```bash
docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
docker run -d --restart=unless-stopped -p 8080:8080 admin/vupay:latest
```
> **本仓库(admin/VUPAY)额外提供:**
> - CI 自动构建镜像并推到 `git.viaeon.com/admin/vupay`(`.gitea/workflows/docker.yaml`)
> - 三份 compose 示例:`docker-compose.example.yml`(SQLite)、`docker-compose.postgres.example.yml`、
> `docker-compose.mysql.example.yml`
> - **新增 MySQL 支持**(`MYSQL_DSN`),上游只有 SQLite/PostgreSQL;用法见
> [Docker 部署指南 · MySQL](docs/docker/docker.md)
## 📃 技术文档
- 安装:[Docker](docs/docker/docker.md) [Linux](docs/linux/install.md) [1Panel](./docs/1panel/README.md) [宝塔](./docs/bt_panel/README.md)
- 开发:[API对接](docs/api/api.md) [订单回调](docs/notify/readme.md) [Python](https://github.com/luoyanglang/bepusdt-python-sdk) [PHP](https://github.com/v03413/bepusdt-php-sdk)
- 对接:[独角Next](docs/api/dujiao-next/dujiao-next.md) [彩虹易支付](https://github.com/v03413/Epay-BEpusdt) [whmcs](https://github.com/v03413/whmcs-gateway-epusdt) [其它](docs/api/other.md)
- 开发:[API对接](docs/api/api.md) [订单回调](docs/notify/readme.md) [Python](https://github.com/luoyanglang/vupay-python-sdk) [PHP](https://git.viaeon.com/admin/vupay-php-sdk)
- 对接:[独角Next](docs/api/dujiao-next/dujiao-next.md) [彩虹易支付](https://github.com/v03413/Epay-VUPAY) [whmcs](https://github.com/v03413/whmcs-gateway-vupay) [其它](docs/api/other.md)
- 其它:[https 配置](./docs/ssl.md) [时钟同步](docs/linux/systemd-timesyncd.md) [收银台修改](docs/checkout/README.md)
## 🖼 功能截图
@@ -80,21 +86,19 @@ docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
## 🏝️ 社区交流
- **Telegram 群组**:[https://t.me/BEpusdtChat](https://t.me/BEpusdtChat)
- **Telegram 频道**:[https://t.me/BEpusdtChannel](https://t.me/BEpusdtChannel)
- **Telegram 群组**:[https://t.me/VUPAYChat](https://t.me/VUPAYChat)
- **Telegram 频道**:[https://t.me/VUPAYChannel](https://t.me/VUPAYChannel)
- **安全问题反馈/联系**:https://u.viaeon.com
## 🙏 致谢
感谢原项目提供的灵感和参考:
- [EPusdt](./docs/faq/epusdt.md)
感谢为本项目作出贡献的开发者:
<a href="https://github.com/v03413/BEpusdt/graphs/contributors">
<img src="https://contrib.rocks/image?repo=v03413/BEpusdt" alt="BEpusdt 贡献者清单">
<a href="https://git.viaeon.com/admin/vupay/graphs/contributors">
<img src="https://contrib.rocks/image?repo=admin/vupay" alt="VUPAY 贡献者清单">
</a>
## 🌟 Star 历史
[![Star History Chart](https://api.star-history.com/chart?repos=v03413/bepusdt&type=date&legend=top-left)](https://www.star-history.com/?repos=v03413%2Fbepusdt&type=date&legend=top-left)
[![Star History Chart](https://api.star-history.com/chart?repos=admin/vupay&type=date&legend=top-left)](https://www.star-history.com/?repos=v03413%2Fvupay&type=date&legend=top-left)
+10 -3
View File
@@ -4,7 +4,7 @@ import "github.com/urfave/cli/v3"
var SQLiteFlag = &cli.StringFlag{
Name: "sqlite",
Value: "/var/lib/bepusdt/sqlite.db",
Value: "/var/lib/vupay/sqlite.db",
Usage: "SQLite 数据库文件路径",
Sources: cli.EnvVars("SQLITE"),
}
@@ -12,13 +12,20 @@ var SQLiteFlag = &cli.StringFlag{
var PostgresDSNFlag = &cli.StringFlag{
Name: "postgres",
Value: "",
Usage: "PostgreSQL 数据库连接字符串 (DSN),例如: postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3",
Usage: "PostgreSQL 数据库连接字符串 (DSN),例如: postgres://user:password@localhost:5432/vupay?sslmode=disable&connect_timeout=3",
Sources: cli.EnvVars("POSTGRESQL_DSN"),
}
var MysqlDSNFlag = &cli.StringFlag{
Name: "mysql",
Value: "",
Usage: "MySQL 数据库连接字符串 (DSN),例如: user:pass@tcp(127.0.0.1:3306)/vupay?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s",
Sources: cli.EnvVars("MYSQL_DSN"),
}
var LogFlag = &cli.StringFlag{
Name: "log",
Value: "/var/log/bepusdt/",
Value: "/var/log/vupay/",
Usage: "日志文件保存路径",
Sources: cli.EnvVars("LOG"),
}
+6 -5
View File
@@ -5,21 +5,22 @@ import (
"fmt"
"time"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/task"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/urfave/cli/v3"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/task"
"github.com/v03413/bepusdt/app/utils"
"golang.org/x/crypto/bcrypt"
)
var Reset = &cli.Command{
Name: "reset",
Usage: "忘记密码时,此命令可重置账号密码登录入口",
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag},
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, MysqlDSNFlag},
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
sqlite := c.String("sqlite")
postgres := c.String("postgres")
if err := model.Init(sqlite, postgres); err != nil {
mysql := c.String("mysql")
if err := model.Init(sqlite, postgres, mysql); err != nil {
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
}
+10 -9
View File
@@ -12,12 +12,12 @@ import (
"context"
"github.com/v03413/bepusdt/app"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/notifier"
"github.com/v03413/bepusdt/app/router"
"github.com/v03413/bepusdt/app/task"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/notifier"
"git.viaeon.com/admin/vupay/app/router"
"git.viaeon.com/admin/vupay/app/task"
)
import (
@@ -27,11 +27,12 @@ import (
var Start = &cli.Command{
Name: "start",
Usage: "启动收款网关",
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, LogFlag, ListenFlag},
Flags: []cli.Flag{SQLiteFlag, PostgresDSNFlag, MysqlDSNFlag, LogFlag, ListenFlag},
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
postgres := c.String("postgres")
mysql := c.String("mysql")
sqlite := c.String("sqlite")
if err := model.Init(sqlite, postgres); err != nil {
if err := model.Init(sqlite, postgres, mysql); err != nil {
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
}
@@ -83,7 +84,7 @@ func start(ctx context.Context, cmd *cli.Command) error {
notifier.Welcome()
fmt.Println(fmt.Sprintf("日志保存路径:%s", log.GetPath()))
fmt.Println(fmt.Sprintf("BEpusdt 启动成功(%s),当前版本:%s", listen, app.Version))
fmt.Println(fmt.Sprintf("VUPAY 启动成功(%s),当前版本:%s", listen, app.Version))
// 等待中断信号
var signals = make(chan os.Signal, 1)
+2 -2
View File
@@ -4,15 +4,15 @@ import (
"context"
"fmt"
"git.viaeon.com/admin/vupay/app"
"github.com/urfave/cli/v3"
"github.com/v03413/bepusdt/app"
)
var Version = &cli.Command{
Name: "version",
Usage: "显示版本信息",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("BEpusdt 版本:" + app.Version)
fmt.Println("VUPAY 版本:" + app.Version)
return nil
},
+2 -2
View File
@@ -2,14 +2,14 @@ package conf
const (
Desc = "一款更好用的个人加密货币收款网关"
Github = "https://github.com/v03413/BEpusdt"
Github = "https://git.viaeon.com/admin/vupay"
)
const Debug = false
const (
Pid = "1000" // 暂时固定易支付商户ID
Api = "https://api.bepusdt.online"
Api = "https://api.vupay.online"
)
const (
+4 -4
View File
@@ -7,10 +7,10 @@ import (
"net/http"
"time"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/log"
)
type Api struct {
@@ -30,7 +30,7 @@ func (Api) get(url string) ([]byte, error) {
return nil, fmt.Errorf("创建请求失败: %w", err)
}
req.Header.Set("User-Agent", fmt.Sprintf("BEpusdt/%s", app.Version))
req.Header.Set("User-Agent", fmt.Sprintf("VUPAY/%s", app.Version))
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
+5 -5
View File
@@ -5,12 +5,12 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/notifier"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/notifier"
"github.com/v03413/bepusdt/app/utils"
)
type Conf struct {
+2 -2
View File
@@ -5,11 +5,11 @@ import (
"fmt"
"time"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/go-cache"
)
+4 -4
View File
@@ -3,12 +3,12 @@ package admin
import (
"time"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/task/notify"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/task/notify"
"github.com/v03413/bepusdt/app/utils"
)
type Order struct {
+2 -2
View File
@@ -3,9 +3,9 @@ package admin
import (
"fmt"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
)
type Rate struct {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"strings"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
)
type Wallet struct {
+4 -4
View File
@@ -4,13 +4,13 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/handler/base"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/handler/base"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
"github.com/v03413/go-cache"
"golang.org/x/crypto/bcrypt"
)
+1 -1
View File
@@ -3,8 +3,8 @@ package base
import (
"fmt"
"git.viaeon.com/admin/vupay/app/log"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/log"
)
type Result struct {
+3 -3
View File
@@ -7,11 +7,11 @@ import (
"net/http"
"sort"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
const Pid = "1000" // 固定商户号
@@ -121,7 +121,7 @@ func (e Epay) verify(data map[string]string) (submit, error) {
pid, ok := data["pid"]
if !ok || pid != Pid {
return params, fmt.Errorf("BEpusdt 易支付兼容模式,商户号【PID】必须固定为" + Pid)
return params, fmt.Errorf("VUPAY 易支付兼容模式,商户号【PID】必须固定为" + Pid)
}
var requiredFields = []string{"pid", "type", "out_trade_no", "notify_url", "return_url", "name", "money", "sign"}
@@ -1,4 +1,4 @@
package epusdt
package vupay
import (
"bytes"
@@ -8,14 +8,14 @@ import (
"math"
"time"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
type Epusdt struct{}
type Vupay struct{}
type createReq struct {
OrderID string `json:"order_id" binding:"required"`
@@ -78,7 +78,7 @@ func loadPayOrder(ctx *gin.Context, tradeID string) (model.Order, bool) {
return order, true
}
func (Epusdt) Notify(ctx *gin.Context) {
func (Vupay) Notify(ctx *gin.Context) {
rawData, err := ctx.GetRawData()
if err != nil {
ctx.String(200, "fail")
@@ -97,7 +97,7 @@ func (Epusdt) Notify(ctx *gin.Context) {
return
}
if utils.EpusdtSign(m, model.AuthToken()) != sign {
if utils.VupaySign(m, model.AuthToken()) != sign {
ctx.String(200, "fail")
return
}
@@ -105,7 +105,7 @@ func (Epusdt) Notify(ctx *gin.Context) {
ctx.String(200, "ok")
}
func (Epusdt) CreateOrder(ctx *gin.Context) {
func (Vupay) CreateOrder(ctx *gin.Context) {
var req createOrderReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("CreateOrder: request error: %s", err.Error())))
@@ -137,7 +137,7 @@ func (Epusdt) CreateOrder(ctx *gin.Context) {
// 创建待付款订单
order, err := model.BuildPendingOrder(model.OrderParams{
Money: decimal.NewFromFloat(req.Amount),
ApiType: model.OrderApiTypeEpusdtOrder,
ApiType: model.OrderApiTypeVupayOrder,
OrderId: req.OrderID,
RedirectUrl: req.RedirectURL,
NotifyUrl: req.NotifyURL,
@@ -168,7 +168,7 @@ func (Epusdt) CreateOrder(ctx *gin.Context) {
}))
}
func (Epusdt) UpdateOrder(ctx *gin.Context) {
func (Vupay) UpdateOrder(ctx *gin.Context) {
// 接收 trade_id, currency, network 三个参数
var req updateOrderReq
if err := ctx.ShouldBindJSON(&req); err != nil {
@@ -250,7 +250,7 @@ func (Epusdt) UpdateOrder(ctx *gin.Context) {
}))
}
func (Epusdt) CreateTransaction(ctx *gin.Context) {
func (Vupay) CreateTransaction(ctx *gin.Context) {
var req createReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
@@ -278,7 +278,7 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
order, err := model.StartBuildOrder(model.OrderParams{
Money: decimal.NewFromFloat(req.Amount),
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
Address: req.Address,
AddressLocked: req.Amount == 0,
OrderId: req.OrderID,
@@ -313,7 +313,7 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
}))
}
func (Epusdt) CancelTransaction(ctx *gin.Context) {
func (Vupay) CancelTransaction(ctx *gin.Context) {
var req cancelReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
@@ -343,7 +343,7 @@ func (Epusdt) CancelTransaction(ctx *gin.Context) {
ctx.JSON(200, respSuccJson(gin.H{"trade_id": req.TradeID}))
}
func (Epusdt) Checkout(ctx *gin.Context) {
func (Vupay) Checkout(ctx *gin.Context) {
tradeId := ctx.Param("trade_id")
if _, ok := model.GetTradeOrder(tradeId); !ok {
ctx.String(200, "order not found")
@@ -357,7 +357,7 @@ func (Epusdt) Checkout(ctx *gin.Context) {
ctx.HTML(200, tmpl, gin.H{"trade_id": tradeId})
}
func (Epusdt) GetMethods(ctx *gin.Context) {
func (Vupay) GetMethods(ctx *gin.Context) {
var req methodsReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("request error: %s", err.Error())))
@@ -385,7 +385,7 @@ func (Epusdt) GetMethods(ctx *gin.Context) {
}))
}
func (Epusdt) Info(ctx *gin.Context) {
func (Vupay) Info(ctx *gin.Context) {
var req infoReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("参数错误:%s", err.Error())))
@@ -417,7 +417,7 @@ func (Epusdt) Info(ctx *gin.Context) {
}))
}
func (Epusdt) SignVerify(ctx *gin.Context) {
func (Vupay) SignVerify(ctx *gin.Context) {
rawData, err := ctx.GetRawData()
if err != nil {
ctx.JSON(200, respFailJson(fmt.Sprintf("json 数据读取错误 %s", err.Error())))
@@ -442,7 +442,7 @@ func (Epusdt) SignVerify(ctx *gin.Context) {
return
}
if utils.EpusdtSign(m, model.AuthToken()) != sign {
if utils.VupaySign(m, model.AuthToken()) != sign {
ctx.JSON(200, respFailJson("签名错误"))
ctx.Abort()
+1 -1
View File
@@ -48,7 +48,7 @@ func Init(dir string) error {
var err error
be, err = newLogger(filepath.Join(dir, "bepusdt.log"))
be, err = newLogger(filepath.Join(dir, "vupay.log"))
if err != nil {
return err
}
+4 -4
View File
@@ -7,9 +7,9 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/utils"
"github.com/v03413/go-cache"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
@@ -51,7 +51,7 @@ var defaultConf = map[ConfKey]string{
SystemInstallLock: "0",
RateSyncCoingeckoApiUrl: "https://api.coingecko.com",
RateSyncHistoryDays: "30",
MqttTopicPrefix: "bepusdt",
MqttTopicPrefix: "vupay",
HomeRedirectUrl: "",
}
@@ -62,7 +62,7 @@ type Conf struct {
func (c Conf) TableName() string {
return "bep_conf"
return "vupay_conf"
}
func SetK(k ConfKey, v string) {
@@ -168,7 +168,7 @@ func ConfInit() {
fmt.Println()
fmt.Println("╔═══════════════════════════════════════════════════════════════════════")
fmt.Println("║ 🎉 欢迎使用 BEpusdt - 首次运行检测,初始化配置完成")
fmt.Println("║ 🎉 欢迎使用 VUPAY - 首次运行检测,初始化配置完成")
fmt.Println("╚═══════════════════════════════════════════════════════════════════════")
fmt.Println()
fmt.Println("┏━━ 🔐 后台登录信息 (请立即保存!)")
+1 -1
View File
@@ -108,7 +108,7 @@ const (
)
const (
Classic MatchMode = "classic" // 经典模式,精确匹配
HasPrefix MatchMode = "has_prefix" // 前缀匹配,允许多付
HasPrefix MatchMode = "has_prefix" // 前缀匹配,按原子精度截断后比较,只容忍精度以下的多付
RoundOff MatchMode = "round_off" // 数值修约,四舍五入,允许容错
)
@@ -5,25 +5,25 @@ import (
"gorm.io/gorm"
)
// 202607081430 - 删除 bep_order.trade_type_reselect 列
// 202607081430 - 删除 vupay_order.trade_type_reselect 列
func m202607081430DropOrderTradeTypeReselect() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "202607081430_drop_order_trade_type_reselect",
Migrate: func(tx *gorm.DB) error {
if !tx.Migrator().HasTable("bep_order") {
if !tx.Migrator().HasTable("vupay_order") {
return nil
}
if tx.Migrator().HasColumn("bep_order", "trade_type_reselect") {
return tx.Exec("ALTER TABLE bep_order DROP COLUMN trade_type_reselect").Error
if tx.Migrator().HasColumn("vupay_order", "trade_type_reselect") {
return tx.Exec("ALTER TABLE vupay_order DROP COLUMN trade_type_reselect").Error
}
return nil
},
Rollback: func(tx *gorm.DB) error {
if !tx.Migrator().HasTable("bep_order") {
if !tx.Migrator().HasTable("vupay_order") {
return nil
}
if !tx.Migrator().HasColumn("bep_order", "trade_type_reselect") {
return tx.Exec("ALTER TABLE bep_order ADD COLUMN trade_type_reselect INTEGER NOT NULL DEFAULT 0").Error
if !tx.Migrator().HasColumn("vupay_order", "trade_type_reselect") {
return tx.Exec("ALTER TABLE vupay_order ADD COLUMN trade_type_reselect INTEGER NOT NULL DEFAULT 0").Error
}
return nil
},
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"gorm.io/gorm"
)
const TableName = "bep_migration"
const TableName = "vupay_migration"
var migrations = []*gormigrate.Migration{
m202607081430DropOrderTradeTypeReselect(),
+51 -6
View File
@@ -6,8 +6,9 @@ import (
"path/filepath"
"time"
"git.viaeon.com/admin/vupay/app/model/migration"
"github.com/glebarez/sqlite"
"github.com/v03413/bepusdt/app/model/migration"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
@@ -24,12 +25,17 @@ type AutoTimeAt struct {
UpdatedAt *Datetime `gorm:"column:updated_at;not null;comment:最后更新时间" json:"updated_at"`
}
func Init(db, dsn string) error {
if dsn != "" {
return initPostgres(dsn)
// Init 按优先级选择数据库:MySQL DSN > PostgreSQL DSN > SQLite 文件。
// 三者互斥,填了哪个用哪个;都不填就走 SQLite(默认)。
func Init(db, postgresDSN, mysqlDSN string) error {
switch {
case mysqlDSN != "":
return initMysql(mysqlDSN)
case postgresDSN != "":
return initPostgres(postgresDSN)
default:
return initSqlite(db)
}
return initSqlite(db)
}
func initSqlite(db string) error {
@@ -147,3 +153,42 @@ func Close() {
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("数据库资源关闭错误:%s", err.Error()))
}
}
func initMysql(dsn string) error {
// 建议 DSN 里带上 charset=utf8mb4&parseTime=True&loc=Local,
// 否则中文/时间字段会出问题:中文变 ?,时间按 UTC 存进去。
Db, err = gorm.Open(mysql.New(mysql.Config{
DSN: dsn,
DefaultStringSize: 256,
SkipInitializeWithVersion: false,
}), &gorm.Config{})
if err != nil {
return err
}
{
sqlDB, err := Db.DB()
if err != nil {
return err
}
sqlDB.SetMaxIdleConns(10)
sqlDB.SetMaxOpenConns(100)
sqlDB.SetConnMaxLifetime(30 * time.Minute)
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
}
if err = AutoMigrate(); err != nil {
return err
}
var count int64
Db.Model(&Conf{}).Count(&count)
if count == 0 {
ConfInit()
}
FillDefaultConf()
RefreshC()
return nil
}
+1 -1
View File
@@ -8,7 +8,7 @@ type NotifyRecord struct {
func (nr NotifyRecord) TableName() string {
return "bep_notify"
return "vupay_notify"
}
func IsNeedNotifyByTxid(txid string) bool {
+15 -15
View File
@@ -9,12 +9,12 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/utils"
)
const (
@@ -55,17 +55,17 @@ const (
)
const (
OrderApiTypeEpusdt = "epusdt" // epusdt
OrderApiTypeEpusdtOrder = "epusdt_order" // epusdt create-order
OrderApiTypeEpay = "epay" // 彩虹易支付
OrderApiTypeAdmin = "admin" // 管理后台
OrderApiTypeVupay = "vupay" // vupay
OrderApiTypeVupayOrder = "vupay_order" // vupay create-order
OrderApiTypeEpay = "epay" // 彩虹易支付
OrderApiTypeAdmin = "admin" // 管理后台
)
type Order struct {
Id
OrderId string `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
TradeId string `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;index:idx_order_status_trade,priority:2;comment:交易类型" json:"trade_type"`
Fiat Fiat `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
Crypto Crypto `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
CurrencyLimit string `gorm:"column:currency_limit;type:varchar(255);not null;default:'';comment:限定币种" json:"currency_limit"`
@@ -76,11 +76,11 @@ type Order struct {
FromAddress string `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
MatchAddress string `gorm:"column:match_address;type:varchar(128);not null;default:'';comment:校验地址" json:"match_address"`
AddressLocked bool `gorm:"column:address_locked;not null;default:false;comment:地址锁定 1:独占 0:共享" json:"address_locked"`
Status int `gorm:"column:status;not null;default:1;index;index:idx_order_notify_retry,priority:1;comment:交易状态" json:"status"`
Status int `gorm:"column:status;not null;default:1;index;index:idx_order_notify_retry,priority:1;index:idx_order_status_trade,priority:1;comment:交易状态" json:"status"`
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
ReturnUrl string `gorm:"column:return_url;type:text;not null;default:'';comment:同步地址" json:"return_url"`
NotifyUrl string `gorm:"column:notify_url;type:text;not null;default:'';comment:异步地址" json:"notify_url"`
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'vupay';comment:API类型" json:"api_type"`
ReturnUrl string `gorm:"column:return_url;type:varchar(1024);not null;default:'';comment:同步地址" json:"return_url"`
NotifyUrl string `gorm:"column:notify_url;type:varchar(1024);not null;default:'';comment:异步地址" json:"notify_url"`
NotifyNum int `gorm:"column:notify_num;not null;default:0;index:idx_order_notify_retry,priority:3;comment:回调次数" json:"notify_num"`
NotifyState int `gorm:"column:notify_state;not null;default:0;index:idx_order_notify_retry,priority:2;comment:回调状态 1:成功 0:失败" json:"notify_state"`
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
@@ -116,7 +116,7 @@ func (o *Order) CanReselectPayment() bool {
return false
}
if o.ApiType != OrderApiTypeEpusdtOrder && o.ApiType != OrderApiTypeAdmin {
if o.ApiType != OrderApiTypeVupayOrder && o.ApiType != OrderApiTypeAdmin {
return false
}
@@ -338,7 +338,7 @@ func (o *Order) Network() any {
}
func (o *Order) TableName() string {
return "bep_order"
return "vupay_order"
}
func GetTradeOrder(tradeId string) (Order, bool) {
+5 -5
View File
@@ -10,12 +10,12 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/utils"
"gorm.io/gorm"
)
@@ -30,7 +30,7 @@ type Rate struct {
}
func (r *Rate) TableName() string {
return "bep_rate"
return "vupay_rate"
}
func (r *Rate) BeforeCreate(*gorm.DB) error {
@@ -68,7 +68,7 @@ func CoingeckoRate() error {
}
req.Header.Set("x-cg-demo-api-key", GetC(RateSyncCoingeckoApiKey))
req.Header.Set("User-Agent", fmt.Sprintf("BEpusdt/%s", app.Version))
req.Header.Set("User-Agent", fmt.Sprintf("VUPAY/%s", app.Version))
resp, err := client.Do(req)
if err != nil {
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
"git.viaeon.com/admin/vupay/app/conf"
"github.com/shopspring/decimal"
"github.com/v03413/bepusdt/app/conf"
)
// supportFiat 支持的法定货币
+2 -2
View File
@@ -6,10 +6,10 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/utils"
)
type OrderParams struct {
+3 -3
View File
@@ -4,8 +4,8 @@ import (
"errors"
"strings"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/xssnick/tonutils-go/address"
)
@@ -30,7 +30,7 @@ type Wallet struct {
func (wa *Wallet) TableName() string {
return "bep_wallet"
return "vupay_wallet"
}
func (wa *Wallet) SetStatus(status uint8) {
+3 -3
View File
@@ -5,9 +5,9 @@ import (
"os"
"sync"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
)
type activeConf struct {
@@ -55,7 +55,7 @@ func Reload() error {
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", newConf.host, newConf.port))
opts.SetUsername(newConf.user)
opts.SetPassword(newConf.pass)
opts.SetClientID(fmt.Sprintf("BEpusdt %d", os.Getpid()))
opts.SetClientID(fmt.Sprintf("VUPAY %d", os.Getpid()))
opts.SetAutoReconnect(true)
opts.SetOrderMatters(false)
opts.SetOnConnectHandler(onConnectHandler)
+1 -1
View File
@@ -1,8 +1,8 @@
package mqtt
import (
"git.viaeon.com/admin/vupay/app/log"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/v03413/bepusdt/app/log"
)
// Publish 发布消息。若 MQTT 未连接则静默丢弃,返回 nil。
+1 -1
View File
@@ -3,8 +3,8 @@ package mqtt
import (
"fmt"
"git.viaeon.com/admin/vupay/app/log"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/v03413/bepusdt/app/log"
)
type callback struct {
+1 -1
View File
@@ -1,6 +1,6 @@
package notifier
import "github.com/v03413/bepusdt/app/model"
import "git.viaeon.com/admin/vupay/app/model"
type None struct{}
+2 -2
View File
@@ -1,8 +1,8 @@
package notifier
import (
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
)
const (
+7 -8
View File
@@ -6,15 +6,15 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
"github.com/v03413/tronprotocol/core"
)
@@ -201,7 +201,7 @@ func (t *Telegram) TronResourceChange(res model.TronResource) {
func (t *Telegram) Welcome() {
text := `
👋 欢迎使用 BEpusdt,` + conf.Desc + `,如果您看到此消息,说明系统已启动成功!
👋 欢迎使用 VUPAY,` + conf.Desc + `,如果您看到此消息,说明系统已启动成功!
📌当前版本:` + app.Version + `
🎉开源地址:` + conf.Github + `
@@ -212,8 +212,7 @@ func (t *Telegram) Welcome() {
ReplyMarkup: models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "📢 关注频道", URL: "https://t.me/BEpusdtChannel"},
{Text: "💬 社区交流", URL: "https://t.me/BEpusdtChat"},
{Text: "🌐 访问站点", URL: "https://u.viaeon.com"},
},
},
},
+1 -1
View File
@@ -3,7 +3,7 @@ package notifier
import (
"testing"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
func TestNonOrderTransferTitleUsesMatchAddress(t *testing.T) {
+1 -1
View File
@@ -1,7 +1,7 @@
package notifier
import (
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
type Wechat struct{}
+1 -1
View File
@@ -1,8 +1,8 @@
package router
import (
"git.viaeon.com/admin/vupay/app/handler/admin"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/admin"
)
func adminInit(e *gin.Engine) {
+1 -1
View File
@@ -1,8 +1,8 @@
package router
import (
"git.viaeon.com/admin/vupay/app/handler/auth"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/auth"
)
func authInit(e *gin.Engine) {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/v03413/bepusdt/static"
"git.viaeon.com/admin/vupay/static"
)
func TestLangGeCheckoutTemplateIsEmbedded(t *testing.T) {
+1 -1
View File
@@ -1,8 +1,8 @@
package router
import (
"git.viaeon.com/admin/vupay/app/handler/epay"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/epay"
)
func epayInit(engine *gin.Engine) {
+5 -5
View File
@@ -5,13 +5,13 @@ import (
"fmt"
"net/http"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/go-cache"
)
@@ -59,7 +59,7 @@ func Handler() *gin.Engine {
{
staticInit(engine)
epusdtInit(engine)
vupayInit(engine)
epayInit(engine)
adminInit(engine)
authInit(engine)
@@ -131,7 +131,7 @@ func noRoute() gin.HandlerFunc {
func copyright() gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Writer.Header().Set("Payment-Gateway", "https://github.com/v03413/BEpusdt")
ctx.Writer.Header().Set("Payment-Gateway", "https://git.viaeon.com/admin/vupay")
}
}
+3 -3
View File
@@ -11,10 +11,10 @@ import (
"path"
"strings"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/static"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/static"
)
func staticInit(e *gin.Engine) {
+3 -3
View File
@@ -1,13 +1,13 @@
package router
import (
"git.viaeon.com/admin/vupay/app/handler/vupay"
"github.com/gin-gonic/gin"
"github.com/v03413/bepusdt/app/handler/epusdt"
)
func epusdtInit(engine *gin.Engine) {
func vupayInit(engine *gin.Engine) {
epGrp := engine.Group("/pay")
epHdr := new(epusdt.Epusdt)
epHdr := new(vupay.Vupay)
{
epGrp.GET("/checkout/:trade_id", epHdr.Checkout)
}
+60
View File
@@ -0,0 +1,60 @@
package task
import (
"testing"
"git.viaeon.com/admin/vupay/app/model"
"github.com/shopspring/decimal"
)
func TestAmountMatchHasPrefix(t *testing.T) {
initTaskTestEnv(t, map[model.ConfKey]string{model.PaymentMatchMode: string(model.HasPrefix)})
cases := []struct {
paid, order string
want bool
}{
{"1.5", "1.5", true},
{"1.50123", "1.5", true},
{"1.509", "1.5", true},
{"1.51", "1.5", false},
{"1.4999", "1.5", false},
{"2", "2", true},
{"2.009", "2", true},
{"2.01", "2", false},
{"2.5", "2", false},
{"10.379", "10.37", true},
{"10.38", "10.37", false},
{"20", "2", false},
{"100.5", "100", false},
{"123.456789", "123.45", true},
// 订单金额小数位多于原子精度时按订单金额的小数位截断
{"1.5059", "1.505", true},
{"1.506", "1.505", false},
}
for _, c := range cases {
got := amountMatch(decimal.RequireFromString(c.paid), c.order, string(model.UsdtTrc20))
if got != c.want {
t.Errorf("paid %s order %s: got %v, want %v", c.paid, c.order, got, c.want)
}
}
}
// 同一地址并发订单按原子精度递增金额,截断后每笔付款最多对应其中一笔
func TestAmountMatchHasPrefixConcurrentOrders(t *testing.T) {
initTaskTestEnv(t, map[model.ConfKey]string{model.PaymentMatchMode: string(model.HasPrefix)})
orders := []string{"1.5", "1.51", "1.52"}
payments := map[string]string{"1.5": "1.5", "1.50123": "1.5", "1.51": "1.51", "1.519": "1.51", "1.52": "1.52"}
for paid, want := range payments {
var matched []string
for _, o := range orders {
if amountMatch(decimal.RequireFromString(paid), o, string(model.UsdtTrc20)) {
matched = append(matched, o)
}
}
if len(matched) != 1 || matched[0] != want {
t.Errorf("paid %s matched %v, want only %s", paid, matched, want)
}
}
}
+5 -5
View File
@@ -10,16 +10,16 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
blockapi "git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/panjf2000/ants/v2"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/conf"
blockapi "github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
type aptos struct {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
)
func arbitrumInit() {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
)
func baseInit() {
+3 -3
View File
@@ -4,10 +4,10 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
func bscInit() {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
type rConf struct {
+3 -3
View File
@@ -4,10 +4,10 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
func ethInit() {
+5 -5
View File
@@ -12,16 +12,16 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
blockapi "git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/panjf2000/ants/v2"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/conf"
blockapi "github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
const (
+2 -2
View File
@@ -7,10 +7,10 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app/model"
appMqtt "git.viaeon.com/admin/vupay/app/mqtt"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/model"
appMqtt "github.com/v03413/bepusdt/app/mqtt"
"github.com/v03413/go-cache"
)
+6 -6
View File
@@ -4,11 +4,11 @@ import (
"context"
"time"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/notifier"
"github.com/v03413/bepusdt/app/task/notify"
"github.com/v03413/bepusdt/app/utils"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/notifier"
"git.viaeon.com/admin/vupay/app/task/notify"
"git.viaeon.com/admin/vupay/app/utils"
)
func init() {
@@ -35,7 +35,7 @@ func notifyRetry(context.Context) {
func notifyRoll(context.Context) {
for _, o := range model.GetOrderByStatus(model.OrderStatusWaiting) {
notify.Bepusdt(o)
notify.Vupay(o)
}
}
+19 -19
View File
@@ -10,12 +10,12 @@ import (
"strings"
"time"
"git.viaeon.com/admin/vupay/app"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/notifier"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/notifier"
"github.com/v03413/bepusdt/app/utils"
"github.com/v03413/go-cache"
"gorm.io/gorm"
@@ -45,7 +45,7 @@ func Handle(order model.Order) error {
if order.ApiType == model.OrderApiTypeEpay {
err = epay(ctx, order)
} else {
err = epusdt(ctx, order)
err = vupay(ctx, order)
}
if err != nil {
@@ -66,7 +66,7 @@ func epay(ctx context.Context, order model.Order) error {
return err2
}
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
postReq.Header.Set("Powered-By", "https://git.viaeon.com/admin/vupay")
resp, err := client.Do(postReq)
if err != nil {
return err
@@ -102,7 +102,7 @@ func epay(ctx context.Context, order model.Order) error {
return nil
}
func epusdt(ctx context.Context, order model.Order) error {
func vupay(ctx context.Context, order model.Order) error {
var data = make(map[string]interface{})
var body = EpNotify{
TradeId: order.TradeId,
@@ -123,7 +123,7 @@ func epusdt(ctx context.Context, order model.Order) error {
}
// 签名
body.Signature = utils.EpusdtSign(data, model.AuthToken())
body.Signature = utils.VupaySign(data, model.AuthToken())
// 再次序列化
jsonBody, err = json.Marshal(body)
@@ -136,8 +136,8 @@ func epusdt(ctx context.Context, order model.Order) error {
}
postReq.Header.Set("Content-Type", "application/json")
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
postReq.Header.Set("User-Agent", "BEpusdt/"+app.Version)
postReq.Header.Set("Powered-By", "https://git.viaeon.com/admin/vupay")
postReq.Header.Set("User-Agent", "VUPAY/"+app.Version)
resp, err := client.Do(postReq)
if err != nil {
markNotifyFail(order, err.Error())
@@ -160,8 +160,8 @@ func epusdt(ctx context.Context, order model.Order) error {
return nil
}
func Bepusdt(o model.Order) {
if o.ApiType != model.OrderApiTypeEpusdt && o.ApiType != model.OrderApiTypeEpusdtOrder {
func Vupay(o model.Order) {
if o.ApiType != model.OrderApiTypeVupay && o.ApiType != model.OrderApiTypeVupayOrder {
return
}
@@ -169,13 +169,13 @@ func Bepusdt(o model.Order) {
var authToken = model.AuthToken()
var client = &http.Client{Timeout: time.Second * 5}
go func() {
if err := deliverBepusdtStatusUpdate(model.Db, client, authToken, o); err != nil {
log.Warn("notify BEpusdt Error:", err.Error())
if err := deliverVupayStatusUpdate(model.Db, client, authToken, o); err != nil {
log.Warn("notify VUPAY Error:", err.Error())
}
}()
}
func deliverBepusdtStatusUpdate(db *gorm.DB, client *http.Client, authToken string, o model.Order) error {
func deliverVupayStatusUpdate(db *gorm.DB, client *http.Client, authToken string, o model.Order) error {
if client == nil {
client = &http.Client{Timeout: time.Second * 5}
}
@@ -189,7 +189,7 @@ func deliverBepusdtStatusUpdate(db *gorm.DB, client *http.Client, authToken stri
return nil
}
var key = fmt.Sprintf("bepusdt_notify_%d_%s", current.Status, current.TradeId)
var key = fmt.Sprintf("vupay_notify_%d_%s", current.Status, current.TradeId)
if _, ok := cache.Get(key); ok {
return nil
}
@@ -215,7 +215,7 @@ func deliverBepusdtStatusUpdate(db *gorm.DB, client *http.Client, authToken stri
return err
}
body.Signature = utils.EpusdtSign(data, authToken)
body.Signature = utils.VupaySign(data, authToken)
jsonBody, _ = json.Marshal(body)
req, err := http.NewRequest("POST", current.NotifyUrl, strings.NewReader(string(jsonBody)))
@@ -224,7 +224,7 @@ func deliverBepusdtStatusUpdate(db *gorm.DB, client *http.Client, authToken stri
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Powered-By", "https://github.com/v03413/BEpusdt")
req.Header.Set("Powered-By", "https://git.viaeon.com/admin/vupay")
resp, err := client.Do(req)
if err != nil {
return err
+19 -19
View File
@@ -7,9 +7,9 @@ import (
"testing"
"time"
applog "github.com/v03413/bepusdt/app/log"
applog "git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"github.com/glebarez/sqlite"
"github.com/v03413/bepusdt/app/model"
"gorm.io/gorm"
)
@@ -52,25 +52,25 @@ func newWaitingOrder(notifyURL string) model.Order {
confirmedAt := now
return model.Order{
OrderId: "merchant-order-1",
TradeId: "trade-order-1",
TradeType: model.UsdtTrc20,
Fiat: "CNY",
Crypto: "USDT",
Rate: "7.00",
Amount: "1.00",
Money: "7.00",
Address: "TTestAddress1234567890",
Status: model.OrderStatusWaiting,
ApiType: model.OrderApiTypeEpusdt,
NotifyUrl: notifyURL,
ExpiredAt: now.Add(10 * time.Minute),
ConfirmedAt: &confirmedAt,
AutoTimeAt: model.AutoTimeAt{CreatedAt: (*model.Datetime)(&now), UpdatedAt: (*model.Datetime)(&now)},
OrderId: "merchant-order-1",
TradeId: "trade-order-1",
TradeType: model.UsdtTrc20,
Fiat: "CNY",
Crypto: "USDT",
Rate: "7.00",
Amount: "1.00",
Money: "7.00",
Address: "TTestAddress1234567890",
Status: model.OrderStatusWaiting,
ApiType: model.OrderApiTypeVupay,
NotifyUrl: notifyURL,
ExpiredAt: now.Add(10 * time.Minute),
ConfirmedAt: &confirmedAt,
AutoTimeAt: model.AutoTimeAt{CreatedAt: (*model.Datetime)(&now), UpdatedAt: (*model.Datetime)(&now)},
}
}
func TestDeliverBepusdtStatusUpdateDoesNotHoldDBWhileHTTPIsPending(t *testing.T) {
func TestDeliverVupayStatusUpdateDoesNotHoldDBWhileHTTPIsPending(t *testing.T) {
db := newNotifyTestDB(t)
initNotifyTestLog(t)
@@ -90,7 +90,7 @@ func TestDeliverBepusdtStatusUpdateDoesNotHoldDBWhileHTTPIsPending(t *testing.T)
errCh := make(chan error, 1)
go func() {
errCh <- deliverBepusdtStatusUpdate(db, &http.Client{Timeout: 2 * time.Second}, "test-auth-token", order)
errCh <- deliverVupayStatusUpdate(db, &http.Client{Timeout: 2 * time.Second}, "test-auth-token", order)
}()
select {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
)
func plasmaInit() {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
)
func polygonInit() {
+2 -2
View File
@@ -5,9 +5,9 @@ import (
"fmt"
"time"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
)
func init() {
+74 -12
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"math/big"
@@ -11,17 +12,17 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
blockapi "git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/btcsuite/btcd/btcutil/base58"
"github.com/panjf2000/ants/v2"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/conf"
blockapi "github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
)
// 参考文档
@@ -37,6 +38,7 @@ type solana struct {
retryMu sync.Mutex
retryAttempts map[int]int
retryScheduled map[int]*time.Timer
retryStopped map[int]struct{}
lookbackMu sync.Mutex
lookbackNext int
lookbackEnd int
@@ -67,6 +69,7 @@ func newSolana() solana {
client: utils.NewHttpClient(),
retryAttempts: make(map[int]int),
retryScheduled: make(map[int]*time.Timer),
retryStopped: make(map[int]struct{}),
}
}
@@ -82,7 +85,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
return
}
if s.pendingSlotRetryCount() > 0 {
if s.pendingSlotRetryCount() >= solanaForwardPauseRetries {
return
}
@@ -199,6 +202,13 @@ func (s *solana) slotParse(n any) {
}
result, err := validateSolanaBlockResponse(body)
if errors.Is(err, errSolanaBlockCleanedUp) { // 节点已清理该 slot,重试也拿不到;放弃,不暂停向前扫描
conf.RecordFailure(network)
s.stopSlotRetry(slot)
log.Task.Error(fmt.Sprintf("Solana slot %d 已被节点清理,无法扫描,该 slot 内的付款需要人工核对:%s", slot, err))
return
}
if err != nil {
conf.RecordFailure(network)
s.scheduleSlotRetry(slot)
@@ -334,10 +344,14 @@ func solanaSignatureFinalized(status gjson.Result) bool {
// Solana JSON-RPC 错误码,参考 https://github.com/anza-xyz/agave/blob/master/rpc-client-api/src/custom_error.rs
const (
solanaErrBlockCleanedUp = -32001
solanaErrSlotSkipped = -32007
solanaErrLongTermStorageSlotSkipped = -32009
)
// 节点只保留最近一段时间的区块,更早的 slot 返回 -32001,换一个时间重试也不会有
var errSolanaBlockCleanedUp = errors.New("block cleaned up")
func validateSolanaBlockResponse(body []byte) (gjson.Result, error) {
if !gjson.ValidBytes(body) {
return gjson.Result{}, fmt.Errorf("invalid JSON response")
@@ -348,6 +362,8 @@ func validateSolanaBlockResponse(body []byte) (gjson.Result, error) {
switch rpcErr.Get("code").Int() {
case solanaErrSlotSkipped, solanaErrLongTermStorageSlotSkipped: // 被跳过的 slot 没有区块,按空 slot 处理
return gjson.Result{Type: gjson.Null}, nil
case solanaErrBlockCleanedUp:
return gjson.Result{}, fmt.Errorf("%w: %s", errSolanaBlockCleanedUp, rpcErr.Raw)
}
return gjson.Result{}, fmt.Errorf("RPC error: %s", rpcErr.Raw)
@@ -366,6 +382,11 @@ func validateSolanaBlockResponse(body []byte) (gjson.Result, error) {
func (s *solana) scheduleSlotRetry(slot int) {
s.retryMu.Lock()
if _, stopped := s.retryStopped[slot]; stopped {
s.retryMu.Unlock()
return
}
if _, ok := s.retryScheduled[slot]; ok {
s.retryMu.Unlock()
@@ -400,6 +421,24 @@ func (s *solana) scheduleSlotRetry(slot int) {
s.retryMu.Unlock()
}
func (s *solana) stopSlotRetry(slot int) {
s.retryMu.Lock()
delete(s.retryAttempts, slot)
if timer, ok := s.retryScheduled[slot]; ok {
timer.Stop()
delete(s.retryScheduled, slot)
}
s.retryStopped[slot] = struct{}{}
s.retryMu.Unlock()
// 防止同一 slot 的并发请求在终态响应之后重新建立重试;并发请求结束后无需长期保留。
time.AfterFunc(time.Minute, func() {
s.retryMu.Lock()
delete(s.retryStopped, slot)
s.retryMu.Unlock()
})
}
func (s *solana) resetSlotRetry(slot int) {
s.retryMu.Lock()
defer s.retryMu.Unlock()
@@ -421,6 +460,10 @@ func (s *solana) pendingSlotRetryCount() int {
// 单个 slot 最多重试 10 次,按 solanaRetryDelay 约 7 分钟
const solanaSlotMaxRetries = 10
// 待重试的 slot 达到这个数量,说明节点整体故障,暂停向前扫描,避免新 slot 不断进入重试;
// 个别 slot 失败时继续向前扫描,否则一个 slot 的重试会让之后的付款最多等约 7 分钟
const solanaForwardPauseRetries = 10
func solanaRetryDelay(attempt int) time.Duration {
delays := [...]time.Duration{2 * time.Second, 5 * time.Second, 15 * time.Second, 30 * time.Second, time.Minute}
if attempt < 1 {
@@ -544,13 +587,28 @@ func (s *solana) tradeConfirmHandle(ctx context.Context) {
}
func (s *solana) lookbackSlots(ctx context.Context) {
s.lookbackMu.Lock()
defer s.lookbackMu.Unlock()
// 回溯到一半时订单已支付、取消,或已超出回溯时间,剩余区间不再需要。扫描空闲时这里不会执行到下面,
// 不清空的话进度会一直保留,下一笔订单到来时接着扫这段旧 slot,节点可能早已清理
if s.lookbackNext != 0 {
pending, err := lookbackOrdersPending(s.lookbackOrderIDs)
if err != nil { // 查询失败不等于订单已结束,保留进度,下一轮再判断
log.Task.Warn("Solana 回溯订单查询失败,稍后重试:", err)
return
}
if !pending {
log.Task.Info(fmt.Sprintf("Solana 回溯的订单已不需要回溯,丢弃剩余回溯区间 %d-%d", s.lookbackNext, s.lookbackEnd))
s.resetLookback()
}
}
if syncBreak(conf.Solana, s.slotQueue.Len()) {
return
}
s.lookbackMu.Lock()
defer s.lookbackMu.Unlock()
if s.lookbackNext == 0 {
startAt, endAt, orderIDs, ok := pendingLookbackUnix(conf.Solana)
if !ok {
@@ -581,12 +639,16 @@ func (s *solana) lookbackSlots(ctx context.Context) {
if s.lookbackNext > s.lookbackEnd {
markLookbackDone(s.lookbackOrderIDs)
s.lookbackNext = 0
s.lookbackEnd = 0
s.lookbackOrderIDs = nil
s.resetLookback()
}
}
func (s *solana) resetLookback() {
s.lookbackNext = 0
s.lookbackEnd = 0
s.lookbackOrderIDs = nil
}
func validSolanaLookbackRange(start, end int64) bool {
return start > 0 && end >= start
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
func TestSolanaConfirmOffsetUsesRPCSlot(t *testing.T) {
@@ -44,7 +44,7 @@ func TestSolanaConfirmOffsetUsesRPCSlot(t *testing.T) {
Money: "2736.93",
Address: "F7p3dFrjRTbtRp8FRF6qHLomXbKRBzpvBLjtQcfcgmNe",
Status: model.OrderStatusConfirming,
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
NotifyUrl: srv.URL + "/notify",
RefHash: "DohbsAfxAerDTAX9XS1b9jXY5XYMXQsCnyY3qu42eEEcTeJ6UzMbFs3JTdY14QgNKQPdy6yezdgbqLbnRVj6YB6",
RefBlockNum: slot,
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"testing"
"time"
"git.viaeon.com/admin/vupay/app/model"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/model"
)
func scanSolanaTestBlock(t *testing.T, block []byte) []transfer {
@@ -143,7 +143,7 @@ func TestSolanaTradeConfirmIgnoresFailedTransaction(t *testing.T) {
Money: "1581.77",
Address: "GpsvqTPP7triXkqH8mVtXEM6at9DJ41UHy5dYPTFe16H",
Status: model.OrderStatusConfirming,
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
NotifyUrl: srv.URL + "/notify",
RefHash: "53bZ2UeqMGryYjbjKgB2nAo8umAMsPTP4dzBhR94SdV7f4YaxDvWqEdL5WQ46JSHsmLph3hBmEdHzTMdnYKMsbRz",
RefBlockNum: 458281527,
+72
View File
@@ -0,0 +1,72 @@
package task
import (
"fmt"
"sync/atomic"
"testing"
"time"
"git.viaeon.com/admin/vupay/app/model"
)
// 模拟 n 个 slot 正在等待重试
func (s *solana) setPendingSlotRetries(first, n int) {
s.retryMu.Lock()
defer s.retryMu.Unlock()
for slot := first; slot < first+n; slot++ {
s.retryAttempts[slot] = 1
}
}
// 一个 slot 在等待重试时,向前扫描照常推进,之后的付款不用等它重试完
func TestSolanaForwardContinuesWhileFewSlotsRetry(t *testing.T) {
var head atomic.Int64
srv := newSolanaSlotTestServer(t, &head)
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL, model.BlockHeightMaxDiff: fmt.Sprint(solanaTestMaxDiff)})
createSolanaWaitingOrder(t)
const last = 458000000
s := newSolana()
s.lastSlotNum = last
s.setPendingSlotRetries(last-9, solanaForwardPauseRetries-1)
head.Store(last + 5)
s.syncSlotForward(t.Context())
if s.lastSlotNum != last+5 {
t.Fatalf("lastSlotNum = %d, want %d: forward sync paused by one slot retry", s.lastSlotNum, last+5)
}
select {
case got := <-s.slotQueue.Out:
if got != last+1 {
t.Fatalf("first queued slot = %d, want %d", got, last+1)
}
case <-time.After(time.Second):
t.Fatalf("no slot queued while one slot retries")
}
}
// 很多 slot 同时等待重试,说明节点整体故障,暂停向前扫描
func TestSolanaForwardPausesWhileManySlotsRetry(t *testing.T) {
var head atomic.Int64
srv := newSolanaSlotTestServer(t, &head)
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL, model.BlockHeightMaxDiff: fmt.Sprint(solanaTestMaxDiff)})
createSolanaWaitingOrder(t)
const last = 458000000
s := newSolana()
s.lastSlotNum = last
s.setPendingSlotRetries(last-solanaForwardPauseRetries, solanaForwardPauseRetries)
head.Store(last + 5)
s.syncSlotForward(t.Context())
if s.lastSlotNum != last || s.slotQueue.Len() != 0 {
t.Fatalf("lastSlotNum = %d, queued = %d; want forward sync paused at %d", s.lastSlotNum, s.slotQueue.Len(), last)
}
s.resetSlotRetry(last - solanaForwardPauseRetries)
s.syncSlotForward(t.Context())
if s.lastSlotNum != last+5 {
t.Fatalf("lastSlotNum = %d after retries dropped below threshold, want %d", s.lastSlotNum, last+5)
}
}
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
func newSolanaSlotTestServer(t *testing.T, head *atomic.Int64) *httptest.Server {
@@ -34,7 +34,7 @@ func createSolanaWaitingOrder(t *testing.T) {
Money: "8.61",
Address: "GpsvqTPP7triXkqH8mVtXEM6at9DJ41UHy5dYPTFe16H",
Status: model.OrderStatusWaiting,
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
ExpiredAt: time.Now().Add(10 * time.Minute),
}, time.Now().Add(-time.Minute))
}
+101
View File
@@ -0,0 +1,101 @@
package task
import (
"testing"
"time"
"git.viaeon.com/admin/vupay/app/model"
)
func createSolanaLookbackOrder(t *testing.T, tradeID string, status int) model.Order {
t.Helper()
return createTestOrder(t, model.Order{
OrderId: "merchant-" + tradeID,
TradeId: tradeID,
TradeType: model.UsdcSolana,
Rate: "7.00",
Amount: "1.23",
Money: "8.61",
Address: "GpsvqTPP7triXkqH8mVtXEM6at9DJ41UHy5dYPTFe16H",
Status: status,
ApiType: model.OrderApiTypeVupay,
ExpiredAt: time.Now().Add(10 * time.Minute),
}, time.Now().Add(-time.Minute))
}
// 上一笔订单回溯到一半就取消了;一周后新订单到来时,不能接着扫上一笔订单留下的旧 slot
func TestSolanaLookbackDropsRangeOfFinishedOrders(t *testing.T) {
initTaskTestEnv(t, nil)
lookbackDone.Clear()
canceled := createSolanaLookbackOrder(t, "lookback-canceled", model.OrderStatusCanceled)
waiting := createSolanaLookbackOrder(t, "lookback-waiting", model.OrderStatusWaiting)
lookbackDone.Store(waiting.ID, struct{}{}) // 新订单的回溯不在本测试范围,避免请求区块高度接口
s := newSolana()
s.lookbackNext, s.lookbackEnd, s.lookbackOrderIDs = 459552217, 459552221, []int64{canceled.ID}
s.lookbackSlots(t.Context())
select {
case slot := <-s.slotQueue.Out:
t.Fatalf("queued slot %d from the range of a canceled order", slot)
case <-time.After(200 * time.Millisecond):
}
if s.lookbackNext != 0 || s.lookbackEnd != 0 || s.lookbackOrderIDs != nil {
t.Fatalf("lookback progress kept: next = %d, end = %d, orders = %v", s.lookbackNext, s.lookbackEnd, s.lookbackOrderIDs)
}
}
// 查询订单失败时不能当作订单已结束,保留进度,下一轮再判断
func TestSolanaLookbackKeepsRangeOnDatabaseError(t *testing.T) {
initTaskTestEnv(t, nil)
lookbackDone.Clear()
waiting := createSolanaLookbackOrder(t, "lookback-waiting", model.OrderStatusWaiting)
const start, end = 462296900, 462296904
s := newSolana()
s.lookbackNext, s.lookbackEnd, s.lookbackOrderIDs = start, end, []int64{waiting.ID}
db, err := model.Db.DB()
if err != nil {
t.Fatalf("get db: %v", err)
}
if err := db.Close(); err != nil {
t.Fatalf("close db: %v", err)
}
s.lookbackSlots(t.Context())
if s.lookbackNext != start || s.lookbackEnd != end {
t.Fatalf("lookback progress dropped on a database error: next = %d, end = %d", s.lookbackNext, s.lookbackEnd)
}
}
func TestSolanaLookbackResumesRangeOfPendingOrders(t *testing.T) {
initTaskTestEnv(t, nil)
lookbackDone.Clear()
waiting := createSolanaLookbackOrder(t, "lookback-waiting", model.OrderStatusWaiting)
const start, end = 462296900, 462296904
s := newSolana()
s.lookbackNext, s.lookbackEnd, s.lookbackOrderIDs = start, end, []int64{waiting.ID}
s.lookbackSlots(t.Context())
for want := start; want <= end; want++ {
select {
case got := <-s.slotQueue.Out:
if got != want {
t.Fatalf("queued slot = %d, want %d", got, want)
}
case <-time.After(time.Second):
t.Fatalf("slot %d not queued", want)
}
}
if s.lookbackNext != 0 {
t.Fatalf("lookbackNext = %d after the range was queued, want 0", s.lookbackNext)
}
if _, done := lookbackDone.Load(waiting.ID); !done {
t.Fatalf("order %d not marked as looked back", waiting.ID)
}
}
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"testing"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/model"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/model"
)
// 预期结果由独立的解码脚本从主网交易得出:只统计两端代币账户都在 token balances 中的 USDT/USDC transfer、transferChecked
+98
View File
@@ -0,0 +1,98 @@
package task
import (
"errors"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"git.viaeon.com/admin/vupay/app/model"
)
const solanaBlockCleanedUpResponse = `{"jsonrpc":"2.0","error":{"code":-32001,"message":"Block 459552217 cleaned up, does not exist on node. First available block: 461715420"},"id":1}`
func TestValidateSolanaBlockResponseCleanedUp(t *testing.T) {
if _, err := validateSolanaBlockResponse([]byte(solanaBlockCleanedUpResponse)); !errors.Is(err, errSolanaBlockCleanedUp) {
t.Fatalf("error = %v, want errSolanaBlockCleanedUp", err)
}
}
// 并发处理同一个 slot 时,较晚返回的普通错误不能在 BlockCleanedUp 已经终止后重新建立重试
func TestSolanaSlotParseCleanedUpWinsConcurrentFailure(t *testing.T) {
firstStarted := make(chan struct{})
releaseFirst := make(chan struct{})
var calls atomic.Int64
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if calls.Add(1) == 1 {
close(firstStarted)
<-releaseFirst
w.WriteHeader(http.StatusTooManyRequests)
return
}
_, _ = w.Write([]byte(solanaBlockCleanedUpResponse))
}))
defer srv.Close()
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL})
const slot = 459552217
s := newSolana()
t.Cleanup(s.stopSlotRetryTimers)
done := make(chan struct{})
go func() {
s.slotParse(slot)
close(done)
}()
<-firstStarted
s.slotParse(slot)
close(releaseFirst)
<-done
if got := s.pendingSlotRetryCount(); got != 0 {
t.Fatalf("pending retries after concurrent cleaned up = %d, want 0", got)
}
s.retryMu.Lock()
_, scheduled := s.retryScheduled[slot]
s.retryMu.Unlock()
if scheduled {
t.Fatalf("concurrent failure rescheduled cleaned up slot")
}
}
// 节点已清理的 slot 只请求一次就放弃,不留下待重试记录,向前扫描不会因此暂停;之前因为限流留下的重试也一并清除
func TestSolanaSlotParseGivesUpCleanedUpSlot(t *testing.T) {
var cleaned atomic.Bool
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !cleaned.Load() {
w.WriteHeader(http.StatusTooManyRequests)
return
}
_, _ = w.Write([]byte(solanaBlockCleanedUpResponse))
}))
defer srv.Close()
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL})
const slot = 459552217
s := newSolana()
t.Cleanup(s.stopSlotRetryTimers)
s.slotParse(slot)
if got := s.pendingSlotRetryCount(); got != 1 {
t.Fatalf("pending retries after 429 = %d, want 1", got)
}
s.expireSlotRetryTimer(slot)
cleaned.Store(true)
s.slotParse(slot)
if got := s.pendingSlotRetryCount(); got != 0 {
t.Fatalf("pending retries after cleaned up = %d, want 0: forward sync stays paused", got)
}
s.retryMu.Lock()
_, scheduled := s.retryScheduled[slot]
s.retryMu.Unlock()
if scheduled {
t.Fatalf("cleaned up slot still scheduled for retry")
}
}
+3 -3
View File
@@ -12,11 +12,11 @@ import (
"time"
"filippo.io/edwards25519"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"github.com/btcsuite/btcd/btcutil/base58"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
)
// 订单过期后,按收款账户的链上历史对账一次。
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"testing"
"time"
"git.viaeon.com/admin/vupay/app/model"
"github.com/tidwall/gjson"
"github.com/v03413/bepusdt/app/model"
)
const (
@@ -96,7 +96,7 @@ func createReconcileTestOrder(t *testing.T, tradeID, amount string) model.Order
Money: "2736.93",
Address: reconcileTestOwner,
Status: model.OrderStatusExpired,
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
ExpiredAt: time.Now().Add(-5 * time.Minute),
}, time.Now().Add(-15*time.Minute))
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
// 模拟重试定时器到期并再次扫描失败:取消定时器,下一次 scheduleSlotRetry 计为新的失败
@@ -31,7 +31,7 @@ func (s *solana) stopSlotRetryTimers() {
func TestSolanaSlotRetryGivesUpAfterMaxRetries(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`{"jsonrpc":"2.0","error":{"code":-32001,"message":"Block 457000000 cleaned up, does not exist on node. First available block: 457100000"},"id":1}`))
_, _ = w.Write([]byte(`{"jsonrpc":"2.0","error":{"code":-32004,"message":"Block not available for slot 457000000"},"id":1}`))
}))
defer srv.Close()
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL})
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"sync"
"time"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/model"
)
// 区块扫描队列最大长度,避免可能因为 Rpc Rate Limit 问题导致消费队列堆积,进而导致OOM,暂时简单限制队列长度
+4 -4
View File
@@ -7,9 +7,9 @@ import (
"testing"
"time"
applog "git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"github.com/tidwall/gjson"
applog "github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
)
// 任务测试的公共环境:临时日志目录、临时 SQLite 和主网交易 fixture
@@ -22,7 +22,7 @@ func initTaskTestEnv(t *testing.T, kv map[model.ConfKey]string) {
}
t.Cleanup(applog.Close)
if err := model.Init(filepath.Join(t.TempDir(), "task-test.db"), ""); err != nil {
if err := model.Init(filepath.Join(t.TempDir(), "task-test.db"), "", ""); err != nil {
t.Fatalf("init db: %v", err)
}
t.Cleanup(func() {
@@ -68,7 +68,7 @@ func getTestOrder(t *testing.T, tradeID string) model.Order {
func waitOrderNotified(t *testing.T, tradeID string) {
t.Helper()
file := filepath.Join(applog.GetPath(), "bepusdt.log")
file := filepath.Join(applog.GetPath(), "vupay.log")
for deadline := time.Now().Add(5 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
body, _ := os.ReadFile(file)
if strings.Contains(string(body), "订单回调成功") && strings.Contains(string(body), tradeID) {
+41 -33
View File
@@ -7,14 +7,14 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
blockapi "git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/conf"
blockapi "github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/tlb"
tgo "github.com/xssnick/tonutils-go/ton"
@@ -305,14 +305,38 @@ func (t *ton) processShard(ctx context.Context, shard *tgo.BlockIDExt, seqno uin
return nil
}
// https://github.com/ton-blockchain/TEPs/blob/63fc78718dd9930f3e106954ebec743c3ad07993/text/0074-jettons-standard.md?plain=1#L226
// https://github.com/ton-blockchain/token-contract/blob/1182ad99413242f09925d50e70ccb7e0e09f94d4/ft/jetton-wallet.fc#L43
func (t *ton) parseInternalTransfer(shard *tgo.BlockIDExt, tx *tlb.Transaction, blockNum uint32) (transfer, bool) {
// tonInboundMessage 提取交易的入站 internal 消息及其 ordinary 描述,两类转账解析共用
func tonInboundMessage(tx *tlb.Transaction) (*tlb.InternalMessage, tlb.TransactionDescriptionOrdinary, bool) {
var dsc tlb.TransactionDescriptionOrdinary
if tx.IO.In == nil {
return transfer{}, false
return nil, dsc, false
}
in, ok := tx.IO.In.Msg.(*tlb.InternalMessage)
if !ok || in.Bounced || in.Body == nil {
return nil, dsc, false
}
if dsc, ok = tx.Description.(tlb.TransactionDescriptionOrdinary); !ok {
return nil, dsc, false
}
if dsc.BouncePhase != nil {
if _, ok = dsc.BouncePhase.Phase.(tlb.BouncePhaseOk); ok {
return nil, dsc, false
}
}
return in, dsc, true
}
// tonAccountAddr 统一输出为 non-bounceable 格式,与钱包 MatchAddr 保持一致
func tonAccountAddr(addr *address.Address) string {
return addr.Bounce(false).String()
}
// https://github.com/ton-blockchain/TEPs/blob/63fc78718dd9930f3e106954ebec743c3ad07993/text/0074-jettons-standard.md?plain=1#L226
// https://github.com/ton-blockchain/token-contract/blob/1182ad99413242f09925d50e70ccb7e0e09f94d4/ft/jetton-wallet.fc#L43
func (t *ton) parseInternalTransfer(shard *tgo.BlockIDExt, tx *tlb.Transaction, blockNum uint32) (transfer, bool) {
in, dsc, ok := tonInboundMessage(tx)
if !ok {
return transfer{}, false
}
s, err := in.Body.BeginParse()
@@ -324,17 +348,12 @@ func (t *ton) parseInternalTransfer(shard *tgo.BlockIDExt, tx *tlb.Transaction,
return transfer{}, false
}
transOrd, ok := tx.Description.(tlb.TransactionDescriptionOrdinary)
if !ok {
return transfer{}, false
}
compute, ok := transOrd.ComputePhase.Phase.(tlb.ComputePhaseVM)
compute, ok := dsc.ComputePhase.Phase.(tlb.ComputePhaseVM)
if !ok || !compute.Success {
return transfer{}, false
}
if transOrd.ActionPhase == nil || !transOrd.ActionPhase.Success {
if dsc.ActionPhase == nil || !dsc.ActionPhase.Success {
return transfer{}, false
}
@@ -359,8 +378,8 @@ func (t *ton) parseInternalTransfer(shard *tgo.BlockIDExt, tx *tlb.Transaction,
Network: conf.Ton,
TxHash: hex.EncodeToString(tx.Hash),
Amount: decimal.NewFromBigInt(amount, conf.UsdtTonDecimals),
FromAddress: fromOwner.Bounce(false).String(),
RecvAddress: toJetton.Bounce(false).String(),
FromAddress: tonAccountAddr(fromOwner),
RecvAddress: tonAccountAddr(toJetton),
Timestamp: time.Unix(int64(tx.Now), 0),
TradeType: model.UsdtTon,
BlockNum: int(blockNum),
@@ -368,30 +387,19 @@ func (t *ton) parseInternalTransfer(shard *tgo.BlockIDExt, tx *tlb.Transaction,
}
func (t *ton) parseTonTransfer(tx *tlb.Transaction, blockNum uint32) (transfer, bool) {
in := tx.IO.In
if in == nil {
return transfer{}, false
}
msg, ok := in.Msg.(*tlb.InternalMessage)
msg, _, ok := tonInboundMessage(tx)
if !ok {
return transfer{}, false
}
if msg.Bounced {
return transfer{}, false
}
if msg.Amount.Nano().Sign() <= 0 {
return transfer{}, false
}
if msg.Body.BitsSize() != 0 {
if msg.Amount.Nano().Sign() <= 0 || msg.Body.BitsSize() != 0 {
return transfer{}, false
}
return transfer{
Network: conf.Ton,
TxHash: hex.EncodeToString(tx.Hash),
FromAddress: msg.SrcAddr.Bounce(false).String(),
RecvAddress: msg.DstAddr.Bounce(false).String(),
FromAddress: tonAccountAddr(msg.SrcAddr),
RecvAddress: tonAccountAddr(msg.DstAddr),
Timestamp: time.Unix(int64(tx.Now), 0),
Amount: decimal.NewFromBigInt(msg.Amount.Nano(), conf.TonTonDecimals),
TradeType: model.TonGram,
+124
View File
@@ -0,0 +1,124 @@
package task
import (
"testing"
"git.viaeon.com/admin/vupay/app/model"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/tlb"
tgo "github.com/xssnick/tonutils-go/ton"
"github.com/xssnick/tonutils-go/tvm/cell"
)
var (
tonTestSrc = address.NewAddress(0, 0, make([]byte, 32))
tonTestDst = address.NewAddress(0, 0, append(make([]byte, 31), 1))
)
func tonTestTx(body *cell.Cell, nano uint64, dsc any) *tlb.Transaction {
tx := &tlb.Transaction{AccountAddr: tonTestDst.Data(), Now: 1700000000, Hash: []byte{0xab}, Description: dsc}
tx.IO.In = &tlb.Message{MsgType: tlb.MsgTypeInternal, Msg: &tlb.InternalMessage{
SrcAddr: tonTestSrc,
DstAddr: tonTestDst,
Amount: tlb.FromNanoTONU(nano),
Body: body,
}}
return tx
}
func tonTestOrdinary(success bool) tlb.TransactionDescriptionOrdinary {
return tlb.TransactionDescriptionOrdinary{
ComputePhase: tlb.ComputePhase{Phase: tlb.ComputePhaseVM{Success: success}},
ActionPhase: &tlb.ActionPhase{Success: success},
}
}
func tonTestJettonBody(op uint32, amount uint64) *cell.Cell {
return cell.BeginCell().
MustStoreUInt(uint64(op), 32).
MustStoreUInt(1, 64).
MustStoreCoins(amount).
MustStoreAddr(tonTestSrc).
EndCell()
}
func TestParseTonTransfer(t *testing.T) {
empty := cell.BeginCell().EndCell()
skipped := tlb.TransactionDescriptionOrdinary{
ComputePhase: tlb.ComputePhase{Phase: tlb.ComputePhaseSkipped{}},
Aborted: true,
}
returned := skipped
returned.BouncePhase = &tlb.BouncePhase{Phase: tlb.BouncePhaseOk{}}
noFunds := skipped
noFunds.BouncePhase = &tlb.BouncePhase{Phase: tlb.BouncePhaseNoFunds{}}
bouncedIn := tonTestTx(empty, 1e9, tonTestOrdinary(true))
bouncedIn.IO.In.Msg.(*tlb.InternalMessage).Bounced = true
external := tonTestTx(empty, 1e9, tonTestOrdinary(true))
external.IO.In.Msg = &tlb.ExternalMessage{}
noIn := tonTestTx(empty, 1e9, tonTestOrdinary(true))
noIn.IO.In = nil
cases := []struct {
name string
tx *tlb.Transaction
ok bool
}{
{"plain", tonTestTx(empty, 1e9, tonTestOrdinary(true)), true},
{"uninit account", tonTestTx(empty, 1e9, skipped), true},
{"uninit account, bounce unpaid", tonTestTx(empty, 1e9, noFunds), true},
{"returned to sender", tonTestTx(empty, 1e9, returned), false},
{"zero amount", tonTestTx(empty, 0, tonTestOrdinary(true)), false},
{"with body", tonTestTx(tonTestJettonBody(tonOpInternalTransfer, 1), 1e9, tonTestOrdinary(true)), false},
{"bounced inbound", bouncedIn, false},
{"external inbound", external, false},
{"no inbound", noIn, false},
{"tick tock", tonTestTx(empty, 1e9, tlb.TransactionDescriptionTickTock{}), false},
}
for _, c := range cases {
got, ok := (&ton{}).parseTonTransfer(c.tx, 100)
if ok != c.ok {
t.Errorf("%s: ok = %v, want %v", c.name, ok, c.ok)
}
if !ok {
continue
}
if got.TradeType != model.TonGram || got.Amount.String() != "1" || got.BlockNum != 100 {
t.Errorf("%s: unexpected transfer %+v", c.name, got)
}
if got.RecvAddress != tonTestDst.Bounce(false).String() || got.FromAddress != tonTestSrc.Bounce(false).String() {
t.Errorf("%s: unexpected address %s <- %s", c.name, got.RecvAddress, got.FromAddress)
}
}
}
func TestParseTonInternalTransfer(t *testing.T) {
shard := &tgo.BlockIDExt{Workchain: 0}
cases := []struct {
name string
tx *tlb.Transaction
ok bool
}{
{"jetton received", tonTestTx(tonTestJettonBody(tonOpInternalTransfer, 2_500_000), 1, tonTestOrdinary(true)), true},
{"other op", tonTestTx(tonTestJettonBody(0x7362d09c, 2_500_000), 1, tonTestOrdinary(true)), false},
{"execution failed", tonTestTx(tonTestJettonBody(tonOpInternalTransfer, 2_500_000), 1, tonTestOrdinary(false)), false},
{"zero amount", tonTestTx(tonTestJettonBody(tonOpInternalTransfer, 0), 1, tonTestOrdinary(true)), false},
{"empty body", tonTestTx(cell.BeginCell().EndCell(), 1, tonTestOrdinary(true)), false},
}
for _, c := range cases {
got, ok := (&ton{}).parseInternalTransfer(shard, c.tx, 100)
if ok != c.ok {
t.Errorf("%s: ok = %v, want %v", c.name, ok, c.ok)
}
if !ok {
continue
}
if got.TradeType != model.UsdtTon || got.Amount.String() != "2.5" || got.RecvAddress != tonTestDst.Bounce(false).String() {
t.Errorf("%s: unexpected transfer %+v", c.name, got)
}
}
}
+34 -14
View File
@@ -3,17 +3,16 @@ package task
import (
"context"
"fmt"
"strings"
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/notifier"
"git.viaeon.com/admin/vupay/app/task/notify"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/notifier"
"github.com/v03413/bepusdt/app/task/notify"
"github.com/v03413/tronprotocol/core"
)
@@ -293,6 +292,22 @@ func hasLookbackOrders(tradeType []model.TradeType) bool {
return count > 0
}
// lookbackOrdersPending 判断这些订单中是否还有需要回溯的,条件与 hasLookbackOrders 相同
func lookbackOrdersPending(orderIDs []int64) (bool, error) {
if len(orderIDs) == 0 {
return false, nil
}
var count int64
err := model.Db.Model(&model.Order{}).
Where("id in (?)", orderIDs).
Where("status in (?)", receivableOrderStatuses()).
Where("expired_at > ?", time.Now().Add(model.GetLookbackHour())).
Count(&count).Error
return count > 0, err
}
func getLookbackUnix(network model.Network) (startAt, endAt int64, ok bool) {
startAt, endAt, orderIDs, ok := pendingLookbackUnix(network)
if ok {
@@ -365,7 +380,7 @@ func expireWaitingOrders() {
}
t.SetExpired()
notify.Bepusdt(t)
notify.Vupay(t)
}
}
@@ -383,7 +398,7 @@ func getConfirmingOrders(tradeType []model.TradeType) []model.Order {
if time.Now().Unix() >= order.ExpiredAt.Unix() {
if order.ConfirmedAt == nil || order.ConfirmedAt.IsZero() || !order.ConfirmedAt.Before(order.ExpiredAt) {
order.SetFailed()
notify.Bepusdt(order)
notify.Vupay(order)
continue
}
@@ -401,16 +416,21 @@ func amountMatch(amount decimal.Decimal, target, tradeType string) bool {
case model.Classic:
return amount.String() == target
case model.HasPrefix:
s := amount.String()
if !strings.HasPrefix(s, target) {
t, err := decimal.NewFromString(target)
if err != nil {
log.Warn(err.Error())
return false
}
rest := s[len(target):]
if rest == "" {
return true
// 订单金额去掉了末尾的 0(1.50 存为 1.5),直接按字符串比前缀会让 1.5 的订单吃掉 1.51 的付款;
// 按原子精度和订单金额小数位中的较大者截断实付金额再精确比较,只容忍精度以下的多付
_, precision := model.GetAtomicity(model.TradeType(tradeType))
if p := abs(t.Exponent()); p > precision {
precision = p
}
return strings.Contains(target, ".") || strings.HasPrefix(rest, ".")
return amount.Truncate(precision).Equal(t)
case model.RoundOff:
t, err := decimal.NewFromString(target)
if err != nil {
+3 -3
View File
@@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/model"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/model"
)
func TestPendingLookbackUnixCoversEveryOrderWindow(t *testing.T) {
@@ -52,7 +52,7 @@ func TestPendingLookbackUnixCoversEveryOrderWindow(t *testing.T) {
Money: "7.00",
Address: "GpsvqTPP7triXkqH8mVtXEM6at9DJ41UHy5dYPTFe16H",
Status: w.status,
ApiType: model.OrderApiTypeEpusdt,
ApiType: model.OrderApiTypeVupay,
ExpiredAt: now.Add(w.expired),
}, now.Add(w.created))
}
+5 -5
View File
@@ -9,17 +9,17 @@ import (
"sync"
"time"
"git.viaeon.com/admin/vupay/app/conf"
blockapi "git.viaeon.com/admin/vupay/app/core"
"git.viaeon.com/admin/vupay/app/log"
"git.viaeon.com/admin/vupay/app/model"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/btcsuite/btcd/btcutil/base58"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/panjf2000/ants/v2"
"github.com/shopspring/decimal"
"github.com/smallnest/chanx"
"github.com/spf13/cast"
"github.com/v03413/bepusdt/app/conf"
blockapi "github.com/v03413/bepusdt/app/core"
"github.com/v03413/bepusdt/app/log"
"github.com/v03413/bepusdt/app/model"
"github.com/v03413/bepusdt/app/utils"
"github.com/v03413/tronprotocol/api"
"github.com/v03413/tronprotocol/core"
"google.golang.org/grpc"
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"context"
"time"
"git.viaeon.com/admin/vupay/app/conf"
"git.viaeon.com/admin/vupay/app/utils"
"github.com/smallnest/chanx"
"github.com/v03413/bepusdt/app/conf"
"github.com/v03413/bepusdt/app/utils"
)
func xlayerInit() {
+1 -1
View File
@@ -38,7 +38,7 @@ func IsExist(path string) bool {
return false
}
func EpusdtSign(data map[string]interface{}, token string) string {
func VupaySign(data map[string]interface{}, token string) string {
keys := make([]string, 0, len(data))
for k := range data {
if k == "signature" {
+17
View File
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICpjCCAiugAwIBAgIRAIchZfw0tuX7qK3Vs3BftTowCgYIKoZIzj0EAwMwTzEL
MAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNo
IEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDIwHhcNMjYwNTEzMDAwMDAwWhcN
MzIwOTAyMjM1OTU5WjAuMQswCQYDVQQGEwJVUzENMAsGA1UEChMESVNSRzEQMA4G
A1UEAxMHUm9vdCBZRTB2MBAGByqGSM49AgEGBSuBBAAiA2IABDwS/6vhrcVqcbBo
+wgdI3fwn9x7DNJJOY/lTOti0vkwuRN87RhEhTH17E7XyFjWsPYhIPt/wzOqxTd2
b+4ZJNy9ID04YywF9U5zasDVyGSNErVNtz8uSGh5izW87j77GaOB6zCB6DAOBgNV
HQ8BAf8EBAMCAQYwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB
/zAdBgNVHQ4EFgQUo8gmWo6hTNA1Y/ybI8g6rlbzT1YwHwYDVR0jBBgwFoAUfEKW
rt5LSDv6kviejM9ti6lyN5UwMgYIKwYBBQUHAQEEJjAkMCIGCCsGAQUFBzAChhZo
dHRwOi8veDIuaS5sZW5jci5vcmcvMBMGA1UdIAQMMAowCAYGZ4EMAQIBMCcGA1Ud
HwQgMB4wHKAaoBiGFmh0dHA6Ly94Mi5jLmxlbmNyLm9yZy8wCgYIKoZIzj0EAwMD
aQAwZgIxAMU19WCtmxVND8UHBZRoma49Z7jPs64Dma0eTu1OChVbB/2J7GV3nvYK
Ax54uk1G9QIxAO0miLVJu8PLNiXXXkiE/gsK3CTRTF/aeo4bMX42Zw40csRU6AC2
6hSW1/IWaas6dg==
-----END CERTIFICATE-----
+12
View File
@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIB2TCCAWCgAwIBAgIRAKQCa6LvbHwg1AR+XmWmk4AwCgYIKoZIzj0EAwMwLjEL
MAkGA1UEBhMCVVMxDTALBgNVBAoTBElTUkcxEDAOBgNVBAMTB1Jvb3QgWUUwHhcN
MjUwOTAzMDAwMDAwWhcNNDUwOTAyMjM1OTU5WjAuMQswCQYDVQQGEwJVUzENMAsG
A1UEChMESVNSRzEQMA4GA1UEAxMHUm9vdCBZRTB2MBAGByqGSM49AgEGBSuBBAAi
A2IABDwS/6vhrcVqcbBo+wgdI3fwn9x7DNJJOY/lTOti0vkwuRN87RhEhTH17E7X
yFjWsPYhIPt/wzOqxTd2b+4ZJNy9ID04YywF9U5zasDVyGSNErVNtz8uSGh5izW8
7j77GaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0O
BBYEFKPIJlqOoUzQNWP8myPIOq5W809WMAoGCCqGSM49BAMDA2cAMGQCMHhMr8N9
LdL1VQKs9BdV81r76eXRB6mtjuNjzk6/lBsPNToWLTDzGYgtQKO1jl63uAIwGV7m
onyF377c+MM1oqVNs17sgu7F9YKZwgLmVbeOMDbKAXHtKMDLbiGllCcs8f47
-----END CERTIFICATE-----
+35
View File
@@ -0,0 +1,35 @@
# VUPAY(SQLite 版)—— 单机最简部署
#
# 用法:
# 1) docker login git.viaeon.com # 私有镜像仓库,用 Gitea 账号/token
# 2) docker compose up -d
# 3) 浏览器打开 http://服务器IP:8080 走安装向导(记下「安全入口」和后台账号)
#
# 关键点:
# - SQLite 数据库在容器内 /var/lib/vupay/sqlite.db,必须挂出来,否则删容器=丢单
# - 日志在 /var/log/vupay/,也挂出来,排查掉单要靠它
# - 默认 LISTEN 就是 :8080(0.0.0.0),容器内不用改;要只让反代访问就绑 127.0.0.1
services:
vupay:
image: git.viaeon.com/admin/vupay:latest # 想用官方镜像就换成 admin/vupay:latest
container_name: vupay
restart: unless-stopped
ports:
# 前面有 Nginx/Caddy 反代时绑本机,别把后台裸奔在公网
- "127.0.0.1:8080:8080"
# 没有反代、想直接 IP:端口 访问,就用下面这行替换上面那行:
# - "8080:8080"
environment:
TZ: Asia/Shanghai
LISTEN: ":8080"
SQLITE: /var/lib/vupay/sqlite.db
LOG: /var/log/vupay/
volumes:
- ./data:/var/lib/vupay # sqlite.db 就在这里
- ./logs:/var/log/vupay
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
+88
View File
@@ -0,0 +1,88 @@
# VUPAY + MySQL 8 —— 需要 MySQL 的场景
#
# 注意:这是**本仓库(admin/VUPAY)加了 MySQL 支持之后**才能用的写法。
# 上游 admin/vupay 的代码只有 SQLite 和 PostgreSQL,文档里那段 MYSQL_DSN 是过期内容。
# 镜像:git.viaeon.com/admin/vupay:latest(>= e7a8dd9)
#
# 用法:
# echo "DB_ROOT_PASSWORD=$(openssl rand -base64 24 | tr -d '/+=')" > .env
# echo "DB_PASSWORD=$(openssl rand -base64 24 | tr -d '/+=')" >> .env
# docker login git.viaeon.com
# docker compose -f docker-compose.mysql.yml up -d
#
# 关于共享:MySQL 服务名/容器名都叫 `mysql`,挂在 external 网络 `shared-db` 上,
# 这样同机的其它容器也能用 `mysql:3306` 复用它(每个应用给独立库 + 独立账号)。
# 没有这个网络就先建:docker network create shared-db
# 如果你用 AcePanel 面板,把下面的 `shared-db` 换成 `acepanel-network` 即可
# (那是面板自带的共享网络,面板创建的容器都在里面)。
services:
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --default-time-zone=+08:00
# 小机器(1~2G 内存)建议打开下面三行,省内存也省 CPU
# - --innodb-buffer-pool-size=256M
# - --performance-schema=OFF
# - --disable-log-bin
# - --slow-query-log=ON # 慢查询落 ./mysqldata/<host>-slow.log
# - --long-query-time=1
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:?先把 DB_ROOT_PASSWORD 写进 .env}
MYSQL_DATABASE: vupay
MYSQL_USER: vupay
MYSQL_PASSWORD: ${DB_PASSWORD:?先把 DB_PASSWORD 写进 .env}
TZ: Asia/Shanghai
volumes:
- ./mysqldata:/var/lib/mysql
ports:
# 只绑本机:宿主机命令行 / SSH 隧道能用,公网访问不到
- "127.0.0.1:3306:3306"
networks:
- shared-db
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "root", "-p$${DB_ROOT_PASSWORD}"]
interval: 10s
timeout: 5s
retries: 12
start_period: 40s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
vupay:
image: git.viaeon.com/admin/vupay:latest
container_name: vupay
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
ports:
- "127.0.0.1:8080:8080"
networks:
- shared-db
environment:
TZ: Asia/Shanghai
LISTEN: ":8080"
LOG: /var/log/vupay/
# DSN 三个参数别省:charset=utf8mb4(中文)、parseTime=True(时间列)、loc=Local(时区)
# host 用服务名 mysql(同类容器里写 127.0.0.1 会指向容器自身)
MYSQL_DSN: vupay:${DB_PASSWORD}@tcp(mysql:3306)/vupay?charset=utf8mb4&parseTime=True&loc=Local&timeout=5s&readTimeout=10s&writeTimeout=10s
volumes:
- ./logs:/var/log/vupay
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
networks:
# 用面板(AcePanel)就把名字换成 acepanel-network,同样写 external: true
shared-db:
external: true
+52
View File
@@ -0,0 +1,52 @@
# VUPAY + PostgreSQL —— 生产推荐
#
# 说明:官方文档里那套 MySQL 写法是**过期的**(代码里已经没有任何 MySQL 分支),
# 现在只支持 SQLite 和 PostgreSQL 两种。数据量大/要多实例就看这份。
#
# 用法:
# echo "DB_PASSWORD=$(openssl rand -base64 24 | tr -d '/+=')" > .env
# docker login git.viaeon.com
# docker compose -f docker-compose.postgres.yml up -d
services:
db:
image: postgres:18-alpine
container_name: vupay-db
restart: unless-stopped
environment:
POSTGRES_DB: vupay
POSTGRES_USER: vupay
POSTGRES_PASSWORD: ${DB_PASSWORD:?先把 DB_PASSWORD 写进 .env}
TZ: Asia/Shanghai
volumes:
- ./pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U vupay -d vupay"]
interval: 10s
timeout: 5s
retries: 10
# 数据库不要暴露到公网
expose:
- "5432"
vupay:
image: git.viaeon.com/admin/vupay:latest
container_name: vupay
restart: unless-stopped
depends_on:
db:
condition: service_healthy
ports:
- "127.0.0.1:8080:8080"
environment:
TZ: Asia/Shanghai
LISTEN: ":8080"
LOG: /var/log/vupay/
POSTGRESQL_DSN: postgres://vupay:${DB_PASSWORD}@db:5432/vupay?sslmode=disable&connect_timeout=3&timezone=Asia/Shanghai
volumes:
- ./logs:/var/log/vupay
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
+16 -5
View File
@@ -21,11 +21,16 @@ COPY --from=web_builder /web/dist ./static/secure
ARG VERSION=unknown
RUN set -x \
# 编译缓存 + 并行度限制:
# - cache mount 让依赖只编一次,之后每次提交只重编 main 包(原来每次都全量重编)
# - -p 4 把 go 的并行编译进程数钉死在 4,构建期间留一半核给同机的生产服务
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
set -x \
&& MODULE_PATH=$(go list -m) \
&& CGO_ENABLED=0 go build -trimpath \
&& CGO_ENABLED=0 go build -trimpath -p 4 \
-ldflags="-X '${MODULE_PATH}/app.Version=${VERSION}' -s -w -buildid=" \
-o bepusdt ./main
-o vupay ./main
FROM alpine:3.20
@@ -34,11 +39,17 @@ ENV TZ=Asia/Shanghai
# 安装所需的依赖
RUN apk add --no-cache tzdata ca-certificates
COPY --from=builder /go/release/bepusdt /usr/local/bin/bepusdt
# 补充根证书:Let's Encrypt 的 "ISRG Root YE"(2025 起签发的新根)
# alpine/debian 的 ca-certificates 包里还没有它,缺了会导致对使用新根签发的站点
# 发 HTTPS 回调时 TLS 校验失败(错误形如 x509: certificate signed by unknown authority)。
COPY ca/ /usr/local/share/ca-certificates/
RUN update-ca-certificates
COPY --from=builder /go/release/vupay /usr/local/bin/vupay
# 设置时区
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
EXPOSE 8080
ENTRYPOINT ["bepusdt"]
ENTRYPOINT ["vupay"]
CMD ["start"]
+3 -3
View File
@@ -1,4 +1,4 @@
# 1Panel 部署 BEpusdt 完整指南
# 1Panel 部署 VUPAY 完整指南
> 📋 **前置条件**:本教程假定您已成功安装并配置好 1Panel 面板。
@@ -20,7 +20,7 @@
| 配置项 | 说明 |
|----------|-----------------------------------------------------------------------------------------|
| **镜像选择** | • **正式版**:`v03413/bepusdt:latest`(推荐生产环境)<br>• **开发版**:`v03413/bepusdt:nightly`(体验最新特性) |
| **镜像选择** | • **正式版**:`admin/vupay:latest`(推荐生产环境)<br>• **开发版**:`admin/vupay:nightly`(体验最新特性) |
| **端口映射** | • **本机访问**:`127.0.0.1:8080:8080`(推荐配合反向代理)<br>• **外网暴露**:`8080:8080`(不推荐,存在安全隐患) |
> ⚠️ **安全建议**:为确保服务安全,建议使用 `127.0.0.1` 绑定本地端口,再通过反向代理对外提供服务。
@@ -81,7 +81,7 @@
## 验证部署
配置完成后,通过浏览器访问您的域名,应能正常访问 BEpusdt 服务。
配置完成后,通过浏览器访问您的域名,应能正常访问 VUPAY 服务。
---
+2 -2
View File
@@ -1,3 +1,3 @@
# 异次元发卡 BEpusdt 对接
# 异次元发卡 VUPAY 对接
当前异次元官方应用商店里面已经上架了支付插件`BEpusdt`,直接在商店搜索安装使用即可。
当前异次元官方应用商店里面已经上架了支付插件`VUPAY`,直接在商店搜索安装使用即可。
+9 -9
View File
@@ -3,7 +3,7 @@
> 📡 **MQTT 实时推送**:系统支持将扫描到的链上交易广播到 MQTT 服务器,其它系统通过订阅即可实时获取数据,无需轮询
> API。详见 [《MQTT 对接开发文档》](./mqtt.md)。
> 💡 **推荐阅读**:在开始对接前,建议先阅读 [《BEpusdt 执行原理说明》](./how-it-works.md)
> 💡 **推荐阅读**:在开始对接前,建议先阅读 [《VUPAY 执行原理说明》](./how-it-works.md)
> ,了解订单匹配机制、金额匹配模式与汇率浮动等核心原理,有助于更准确地理解本文档中的参数设计。
### 基础信息
@@ -20,7 +20,7 @@
> **两种订单模式说明**
>
> BEpusdt 的订单创建接口支持两种工作模式,通过 `amount` 参数决定:
> VUPAY 的订单创建接口支持两种工作模式,通过 `amount` 参数决定:
>
> | 模式 | 触发条件 | 地址分配 | 匹配规则 | 典型场景 |
> |------|---------|---------|---------|---------|
@@ -449,7 +449,7 @@ POST /api/v1/pay/methods
}
```
假设 API Token 为:`epusdt_password_xasddawqe`
假设 API Token 为:`vupay_password_xasddawqe`
**步骤 1:排序拼接**
@@ -460,7 +460,7 @@ amount=42&notify_url=http://example.com/notify&order_id=20220201030210321&redire
**步骤 2:追加 Token 并加密**
```text
MD5(amount=42&notify_url=http://example.com/notify&order_id=20220201030210321&redirect_url=http://example.com/redirectepusdt_password_xasddawqe)
MD5(amount=42&notify_url=http://example.com/notify&order_id=20220201030210321&redirect_url=http://example.com/redirectvupay_password_xasddawqe)
```
**最终签名**:`1cd4b52df5587cfb1968b0c0c6e156cd`
@@ -468,8 +468,8 @@ MD5(amount=42&notify_url=http://example.com/notify&order_id=20220201030210321&re
### 代码参考
- **PHP 实现
**:[点击查看](https://github.com/v03413/Epay-BEpusdt/blob/b7fa8fd608d71ce50e0f8eabb1717783c96761ac/bepusdt_plugin.php#L108:L127)
- **Python 实现**:[BEpusdt Python SDK](https://github.com/luoyanglang/bepusdt-python-sdk)
**:[点击查看](https://github.com/v03413/Epay-VUPAY/blob/b7fa8fd608d71ce50e0f8eabb1717783c96761ac/vupay_plugin.php#L108:L127)
- **Python 实现**:[VUPAY Python SDK](https://github.com/luoyanglang/vupay-python-sdk)
### 签名规则总结
@@ -533,6 +533,6 @@ MD5(amount=42&notify_url=http://example.com/notify&order_id=20220201030210321&re
- [交易类型完整列表](../trade-type.md)
- [订单回调通知](../notify/readme.md)
- [易支付对接插件](https://github.com/v03413/Epay-BEpusdt)
- [Python SDK](https://github.com/luoyanglang/bepusdt-python-sdk)
- [原项目参考](https://github.com/assimon/epusdt/blob/master/wiki/API.md)
- [易支付对接插件](https://github.com/v03413/Epay-VUPAY)
- [Python SDK](https://github.com/luoyanglang/vupay-python-sdk)
- [原项目参考](https://github.com/assimon/vupay/blob/master/wiki/API.md)
+11 -11
View File
@@ -1,4 +1,4 @@
# DuJiao Next 对接 BEpusdt 集成指南
# DuJiao Next 对接 VUPAY 集成指南
**当前教程针对的是新版独角 [Dujiao Next](https://dujiao-next.com/),旧版独角数卡对接[请看这个](../dujiaoka/dujiaoka.md)**
@@ -6,9 +6,9 @@
在开始配置前,请确保已满足以下条件:
**BEpusdt 部署信息**
**VUPAY 部署信息**
- API 服务地址:`https://your-bepusdt.com`
- API 服务地址:`https://your-vupay.com`
- API 密钥:`your_api_token`
**DuJiao Next 部署信息**
@@ -19,16 +19,16 @@
## 配置步骤
在 DuJiao Next 后台中选择渠道类型为 BEpusdt,按照以下格式进行配置。
在 DuJiao Next 后台中选择渠道类型为 VUPAY,按照以下格式进行配置。
![BEpusdt 配置界面](./bepusdt.png)
![VUPAY 配置界面](./vupay.png)
**必填配置项**
| 配置项 | 说明 | 示例 |
|-----------|--------------------|----------------------------------------------------|
| 网关地址 | BEpusdt 的 API 服务地址 | `https://your-bepusdt.com` |
| API Token | BEpusdt 的 API 密钥 | `your_api_token` |
| 网关地址 | VUPAY 的 API 服务地址 | `https://your-vupay.com` |
| API Token | VUPAY 的 API 密钥 | `your_api_token` |
| 支付币种 | 支持的加密资产类型,严格区分大小写 | `usdt.trc20` |
| 法币类型 | 支持的法定货币类型 | `CNY`、`USD`、`EUR`、`JPY`、`GBP` |
| 异步通知地址 | 交易完成时的服务器异步回调地址 | `https://your-dujiao.com/api/v1/payments/callback` |
@@ -36,7 +36,7 @@
**配置说明**
- **支付币种**:详见 [支持的币种列表](https://github.com/v03413/BEpusdt/blob/main/docs/trade-type.md),必须严格区分大小写。
- **支付币种**:详见 [支持的币种列表](https://git.viaeon.com/admin/vupay/blob/main/docs/trade-type.md),必须严格区分大小写。
- **法币类型**:仅支持 `CNY`、`USD`、`EUR`、`JPY`、`GBP` 五种,必须严格区分大小写。
**⚠️ 重要说明:异步通知地址和同步回跳地址**
@@ -62,6 +62,6 @@
若出现网关错误提示,请按照以下步骤排查:
- **检查网络连通性**:确认 DuJiao Next API 所在服务器能够正常访问 BEpusdt API 地址。
- **检查 API Token**:确认所配置的 API Token 与 BEpusdt 中的密钥一致。
- **查看日志**:检查 DuJiao Next 和 BEpusdt 的应用日志,获取更详细的错误信息。
- **检查网络连通性**:确认 DuJiao Next API 所在服务器能够正常访问 VUPAY API 地址。
- **检查 API Token**:确认所配置的 API Token 与 VUPAY 中的密钥一致。
- **查看日志**:检查 DuJiao Next 和 VUPAY 的应用日志,获取更详细的错误信息。
+8 -8
View File
@@ -2,11 +2,11 @@
## 重要提示
由于新版 `BEpusdt` 支持多区块链 USDT、超时回调等新特性,独角数卡自带的 `Epusdt` 插件已无法兼容,**必须替换原有插件**。
由于新版 `VUPAY` 支持多区块链 USDT、超时回调等新特性,独角数卡自带的 `Vupay` 插件已无法兼容,**必须替换原有插件**。
> ⚠️ **重要警告**
>
> 独角数卡自带的 `Epusdt` 插件无法直接使用,强行使用必定出现问题!
> 独角数卡自带的 `Vupay` 插件无法直接使用,强行使用必定出现问题!
## 插件替换说明
@@ -18,19 +18,19 @@
下载更新后的控制器文件:
```
https://raw.githubusercontent.com/v03413/dujiaoka/refs/heads/master/app/Http/Controllers/Pay/EpusdtController.php
https://raw.githubusercontent.com/v03413/dujiaoka/refs/heads/master/app/Http/Controllers/Pay/VupayController.php
```
2. **替换原有文件**
将下载的文件替换到独角数卡网站目录:
```
app/Http/Controllers/Pay/EpusdtController.php
app/Http/Controllers/Pay/VupayController.php
```
## 配置步骤
确保 `BEpusdt` 已成功安装并运行后,按照以下步骤配置:
确保 `VUPAY` 已成功安装并运行后,按照以下步骤配置:
### 1. 进入支付配置
@@ -42,10 +42,10 @@
| 参数名称 | 填写内容 | 说明 |
|------------|-----------------------------------------------------------|---------------------------------------------------------------------------|
| **商户ID** | 与 `BEpusdt` 中 `AUTH_TOKEN` 参数保持一致 | 用于身份验证 |
| **商户ID** | 与 `VUPAY` 中 `AUTH_TOKEN` 参数保持一致 | 用于身份验证 |
| **支付标识** | 收款交易类型 | 可选值:`tron.trx`、`usdt.trc20`、`usdt.erc20` 等<br/>[完整列表参考](../../trade-type.md) |
| **商户密钥** | `https://your-domain.com/api/v1/order/create-transaction` | ⚠️ 请将 `your-domain.com` 替换为实际域名 |
| **支付处理路由** | `pay/epusdt` | 固定值,无需修改 |
| **支付处理路由** | `pay/vupay` | 固定值,无需修改 |
### 3. 完成配置
@@ -53,7 +53,7 @@
## 常见问题
- 如果遇到支付失败,请检查 `BEpusdt` 服务是否正常运行
- 如果遇到支付失败,请检查 `VUPAY` 服务是否正常运行
- 确认商户密钥中的域名是否正确配置
- 验证 `AUTH_TOKEN` 是否与独角数卡中的商户ID一致
+18 -18
View File
@@ -1,19 +1,19 @@
# EdgeKey 对接 BEpusdt 教程
# EdgeKey 对接 VUPAY 教程
**当前教程对接BEpusdt(v1.23.5)通过测试验收**
**当前教程对接VUPAY(v1.23.5)通过测试验收**
## 配置步骤
**配置说明**
- **网关地址**:只需填写域名,如 `https://test.shop.com`,系统会自动拼接 API 路径(`/api/v1/order/create-order`)。
- **App ID 和 App Secret**:在 BEpusdt 后台「系统管理 → 基本设置 → API 设置」中获取。
- **支付币种**:用户在 BEpusdt 收银台页面自由选择支付币种,具体在 BEpusdt 后台配置。
- **App ID 和 App Secret**:在 VUPAY 后台「系统管理 → 基本设置 → API 设置」中获取。
- **支付币种**:用户在 VUPAY 收银台页面自由选择支付币种,具体在 VUPAY 后台配置。
**配置步骤示例**:
1. 登录 EdgeKey 管理后台
2. 进入「支付配置」页面
3. 选择 BEpusdt 标签页
3. 选择 VUPAY 标签页
4. 填写具体配置
5. 启用支付方式:点击右上角的启用开关
6. 保存配置:点击「保存配置」按钮
@@ -34,18 +34,18 @@
- **Notify URL**:异步通知地址,支付完成后系统会回调此地址
- **Return URL**:同步回跳地址,用户支付完成后跳转的页面
**BEpusdt专用字段**:
- **App ID**:BEpusdt后台获取的应用ID
- **App Secret**:BEpusdt后台获取的应用密钥(API密钥)
**VUPAY专用字段**:
- **App ID**:VUPAY后台获取的应用ID
- **App Secret**:VUPAY后台获取的应用密钥(API密钥)
## 异步通知地址和同步回跳地址
这两个地址的路由部分 **严格按要求填写**,只需将域名部分替换为您实际部署的 EdgeKey 服务器地址:
- **异步通知地址**:`/api/payments/bepusdt/notify`
- 路由固定为 `/api/payments/bepusdt/notify`
- 示例:若部署地址为 `https://example.com`,则填写 `/api/payments/bepusdt/notify`
- **异步通知地址**:`/api/payments/vupay/notify`
- 路由固定为 `/api/payments/vupay/notify`
- 示例:若部署地址为 `https://example.com`,则填写 `/api/payments/vupay/notify`
- **同步回跳地址**:`/order/{orderNo}?token={token}`
- 路由固定为 `/order/{orderNo}?token={token}`(`:orderNo` 和 `{token}` 为动态参数)
@@ -56,24 +56,24 @@
配置完成后,请按照以下步骤进行测试:
1. 进入 EdgeKey 前台,选择一个商品进行购买。
2. 在结算页面选择 BEpusdt 支付方式。
2. 在结算页面选择 VUPAY 支付方式。
3. 观察是否正常跳转到收银台页面。
## 故障排查
若出现网关错误提示,请按照以下步骤排查:
- **检查网络连通性**:确认 EdgeKey 服务器能够正常访问 BEpusdt API 地址。
- **检查 App ID 和 App Secret**:确认所配置的 App ID 和 App Secret 与 BEpusdt 中的一致。
- **检查网络连通性**:确认 EdgeKey 服务器能够正常访问 VUPAY API 地址。
- **检查 App ID 和 App Secret**:确认所配置的 App ID 和 App Secret 与 VUPAY 中的一致。
- **检查回调地址**:确保异步通知地址可以从外部访问,且格式正确。
- **检查站点设置**:确保在「站点设置」中配置了正确的网站地址。
- **查看日志**:检查 EdgeKey 和 BEpusdt 的应用日志,获取更详细的错误信息。
- **查看日志**:检查 EdgeKey 和 VUPAY 的应用日志,获取更详细的错误信息。
## BEpusdt 工作模式
## VUPAY 工作模式
本项目使用 **收银台模式**(`/api/v1/order/create-order`),用户在 BEpusdt 收银台页面自由选择支付链,无需在代码中指定 `trade_type`。
本项目使用 **收银台模式**(`/api/v1/order/create-order`),用户在 VUPAY 收银台页面自由选择支付链,无需在代码中指定 `trade_type`。
## 相关链接
- [BEpusdt 项目主页](https://github.com/v03413/bepusdt)
- [VUPAY 项目主页](https://git.viaeon.com/admin/vupay)
- [EdgeKey 项目主页](https://github.com/34892002/edgeKey)

Some files were not shown because too many files have changed in this diff Show More