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