fix(scripts): 使用 docker exec blockchain-service 计算地址
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6fe615eac5
commit
b9b6dacbab
|
|
@ -386,30 +386,25 @@ derive_address() {
|
||||||
|
|
||||||
ADDRESS=""
|
ADDRESS=""
|
||||||
|
|
||||||
# 检查 node 是否可用
|
# 方法 1: 使用 Docker 容器里的 node (blockchain-service 容器有 ethers)
|
||||||
if ! command -v node &> /dev/null; then
|
log_debug "尝试使用 Docker 容器计算地址"
|
||||||
log_error "Node.js 未安装,无法计算地址"
|
ADDRESS=$(docker exec blockchain-service node -e "
|
||||||
echo "公钥 (hex): $PUBLIC_KEY"
|
const { computeAddress } = require('ethers');
|
||||||
return
|
console.log(computeAddress('0x$PUBLIC_KEY'));
|
||||||
fi
|
" 2>/dev/null)
|
||||||
|
|
||||||
# 获取脚本所在目录,进入 blockchain-service 目录执行(那里有 ethers)
|
# 方法 2: 使用本地 node + blockchain-service 目录的 ethers
|
||||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
if [ -z "$ADDRESS" ] && command -v node &> /dev/null; then
|
||||||
local service_dir="$script_dir/../services/blockchain-service"
|
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
|
if [ -d "$service_dir/node_modules/ethers" ]; then
|
||||||
log_debug "使用 blockchain-service 目录的 ethers"
|
log_debug "使用本地 blockchain-service 目录的 ethers"
|
||||||
ADDRESS=$(cd "$service_dir" && node -e "
|
ADDRESS=$(cd "$service_dir" && node -e "
|
||||||
const { computeAddress } = require('ethers');
|
const { computeAddress } = require('ethers');
|
||||||
console.log(computeAddress('0x$PUBLIC_KEY'));
|
console.log(computeAddress('0x$PUBLIC_KEY'));
|
||||||
" 2>/dev/null)
|
" 2>/dev/null)
|
||||||
else
|
fi
|
||||||
# 尝试直接执行
|
|
||||||
log_debug "尝试直接使用 node + ethers"
|
|
||||||
ADDRESS=$(node -e "
|
|
||||||
const { computeAddress } = require('ethers');
|
|
||||||
console.log(computeAddress('0x$PUBLIC_KEY'));
|
|
||||||
" 2>/dev/null)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$ADDRESS" ]; then
|
if [ -n "$ADDRESS" ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue