From 0bf52c7b2c598615104f3ba8de757c90dc4f29aa Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 15 Dec 2025 10:18:33 -0800 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20=E8=87=AA=E5=8A=A8=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=83=AD=E9=92=B1=E5=8C=85=20username?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - verify_and_fix_username 函数通过 docker exec 直接查询和更新数据库 - 移除手动回退,全自动化处理 - 将函数添加到主流程中 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/scripts/init-hot-wallet.sh | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/backend/scripts/init-hot-wallet.sh b/backend/scripts/init-hot-wallet.sh index 7021fec4..fa5a00b1 100644 --- a/backend/scripts/init-hot-wallet.sh +++ b/backend/scripts/init-hot-wallet.sh @@ -351,6 +351,69 @@ get_public_key() { echo " 公钥: ${PUBLIC_KEY:0:16}...${PUBLIC_KEY: -16}" } +# 验证并修复账户 username +# mpc-system 的 createAccountFromKeygen 会自动生成 wallet-xxx 格式的 username +# 需要查询并更新为用户指定的 username +verify_and_fix_username() { + log_info "验证账户 username..." + + # 等待账户创建完成 (session-coordinator 异步创建) + sleep 3 + + # 直接通过数据库查询和更新 (最可靠的方式) + log_info "通过数据库查询账户..." + + # 查询通过 keygen_session_id 创建的账户 + local db_query_result=$(docker exec mpc-postgres psql -U postgres -d mpc_system -t -A -c \ + "SELECT id, username FROM accounts WHERE keygen_session_id = '$SESSION_ID' LIMIT 1;" 2>/dev/null) || { + log_warn "无法连接到 mpc-postgres 数据库" + log_warn "可能 Docker 容器未运行或名称不同" + return + } + + log_debug "数据库查询结果: $db_query_result" + + if [ -z "$db_query_result" ]; then + log_warn "未找到 keygen_session_id=$SESSION_ID 对应的账户" + log_warn "session-coordinator 可能尚未创建账户,等待 5 秒后重试..." + sleep 5 + + db_query_result=$(docker exec mpc-postgres psql -U postgres -d mpc_system -t -A -c \ + "SELECT id, username FROM accounts WHERE keygen_session_id = '$SESSION_ID' LIMIT 1;" 2>/dev/null) + + if [ -z "$db_query_result" ]; then + log_error "仍未找到账户,请检查 session-coordinator 日志" + return + fi + fi + + # 解析结果 (格式: id|username) + local account_id=$(echo "$db_query_result" | cut -d'|' -f1) + local current_username=$(echo "$db_query_result" | cut -d'|' -f2) + + ACCOUNT_ID="$account_id" + log_debug "找到账户: id=$account_id, username=$current_username" + + # 检查 username 是否需要更新 + if [ "$current_username" == "$USERNAME" ]; then + log_success "账户 username 已正确: $USERNAME" + return + fi + + log_info "更新账户 username: $current_username -> $USERNAME" + + # 直接通过数据库更新 username + local update_result=$(docker exec mpc-postgres psql -U postgres -d mpc_system -t -A -c \ + "UPDATE accounts SET username = '$USERNAME' WHERE id = '$account_id' RETURNING username;" 2>/dev/null) + + if [ "$update_result" == "$USERNAME" ]; then + log_success "账户 username 已更新为: $USERNAME" + else + log_error "更新 username 失败" + log_debug "更新结果: $update_result" + fi +} + # 派生 EVM 地址 derive_address() { log_info "派生 EVM 地址..." @@ -476,6 +539,7 @@ main() { create_keygen_session wait_for_keygen get_public_key + verify_and_fix_username derive_address show_result