From b9b6dacbabd686e36f17cc1290c78da687816b23 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 15 Dec 2025 10:32:43 -0800 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20=E4=BD=BF=E7=94=A8=20docker=20e?= =?UTF-8?q?xec=20blockchain-service=20=E8=AE=A1=E7=AE=97=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/scripts/init-hot-wallet.sh | 39 +++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/backend/scripts/init-hot-wallet.sh b/backend/scripts/init-hot-wallet.sh index fe4cdc9f..ff553798 100644 --- a/backend/scripts/init-hot-wallet.sh +++ b/backend/scripts/init-hot-wallet.sh @@ -386,30 +386,25 @@ derive_address() { ADDRESS="" - # 检查 node 是否可用 - if ! command -v node &> /dev/null; then - log_error "Node.js 未安装,无法计算地址" - echo "公钥 (hex): $PUBLIC_KEY" - return - fi + # 方法 1: 使用 Docker 容器里的 node (blockchain-service 容器有 ethers) + log_debug "尝试使用 Docker 容器计算地址" + ADDRESS=$(docker exec blockchain-service node -e " + const { computeAddress } = require('ethers'); + console.log(computeAddress('0x$PUBLIC_KEY')); + " 2>/dev/null) - # 获取脚本所在目录,进入 blockchain-service 目录执行(那里有 ethers) - local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - local service_dir="$script_dir/../services/blockchain-service" + # 方法 2: 使用本地 node + blockchain-service 目录的 ethers + if [ -z "$ADDRESS" ] && command -v node &> /dev/null; then + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + local service_dir="$script_dir/../services/blockchain-service" - if [ -d "$service_dir/node_modules/ethers" ]; then - log_debug "使用 blockchain-service 目录的 ethers" - ADDRESS=$(cd "$service_dir" && node -e " - const { computeAddress } = require('ethers'); - console.log(computeAddress('0x$PUBLIC_KEY')); - " 2>/dev/null) - else - # 尝试直接执行 - log_debug "尝试直接使用 node + ethers" - ADDRESS=$(node -e " - const { computeAddress } = require('ethers'); - console.log(computeAddress('0x$PUBLIC_KEY')); - " 2>/dev/null) + if [ -d "$service_dir/node_modules/ethers" ]; then + log_debug "使用本地 blockchain-service 目录的 ethers" + ADDRESS=$(cd "$service_dir" && node -e " + const { computeAddress } = require('ethers'); + console.log(computeAddress('0x$PUBLIC_KEY')); + " 2>/dev/null) + fi fi if [ -n "$ADDRESS" ]; then