Actions
이슈 #435
진행중
JL
HP
[Go backport] AGX 회계 user_id 종속 전환 — Phase 2
이슈 #435:
[Go backport] AGX 회계 user_id 종속 전환 — Phase 2
시작일:
2026/05/12
완료일:
2026/05/12 (약 6달 지연)
진척도:
0%
추정시간:
설명
배경¶
GoTrue 인증 전환 (#434 Phase 1, commit:server|03c6c64) 의 후속. 식별 권한을 user_id 기반으로 옮겼으나, AGX 잔액 / 수익 / 집계 는 여전히 wallet_address 키 기반이다. Rust 측 #421 을 Go 원본으로 백포트해 AGX 회계의 단일 키를 GoTrue user_id 로 통일한다.
작업 범위¶
DB 스키마 v13 (마이그레이션, clean rewrite)¶
-
wallets재설계: 기존 (account_id, balance, total_earned) 1:1 →(user_id UUID, wallet_address TEXT, label TEXT, created_at)1:N.UNIQUE(user_id, wallet_address) -
job_receipts.user_id UUID컬럼 추가 + 인덱스(user_id, completed_at DESC) -
aggregated_earnings.user_id UUID컬럼 추가 +UNIQUE(user_id, period_date, period_type) -
wallet_adjustments신규 테이블:(id, user_id UUID, delta_agx DOUBLE PRECISION, reason TEXT, ref_code TEXT, created_at). redeem / admin credit·debit 결제를 기록 - 잔액 공식:
Σ job_receipts.reward_agx WHERE user_id=$1 + Σ wallet_adjustments.delta_agx WHERE user_id=$1 - clean rewrite: receipts / aggregated_earnings / wallets dev 데이터 DROP
Store 계층¶
-
store/wallets.go(신규 모듈):AddWallet(userID, wallet),RemoveWallet,ListWalletsByUser,GetUserIDByWallet -
store/wallet_adjustments.go(신규):InsertAdjustment,SumByUser,ListByUser -
store/wallet_queries.go재작성: 수익/잔액 조회를 user_id 기반으로 교체. 기존 wallet_address 기반 함수는 deprecated -
store/receipts.go:ListByUser,CountByUser,SummaryForUser,TodayForUser,EntriesByRangeuser_id 기반으로. 삽입 시 user_id 함께 저장 -
store/edge_node.go::UpsertAggregatedEarning: user_id 인자 추가
Proto¶
-
wallet.proto에서 다음 요청 메시지의wallet_address제거:WalletJobsRequest,WalletNodesRequest,WalletEarningsRequest,WalletEarningsTodayRequest,WalletReceiptsRequest,WalletNodesDetailRequest,WalletEarningsByRangeRequest,WalletEarningsSummaryRequest,ClaimVirtualNodesRequest. 서버는 caller user_id 로 조회
Handler¶
-
handler/wallet_auth.go::requireAuthenticatedWallet→requireAuthenticatedUser(caller user_id 만 검증. wallet 권한 검사가 필요한 곳은 별도 헬퍼) -
handler/wallet.go: 6개 RPC user_id 기반으로 재작성. Wallet 조회 계산 공식 적용 -
handler/wallet_vip.go: 3개 RPC. 관리자도 caller user_id 기반으로 (admin proxy 는 user_id 로 우회)
본 phase 에서 다루지 않는 것¶
-
FriendsService테이블 user_id 전환 (Phase 3 이슈 예정) -
virtual_node_assignments/virtual_node_credits/virtual_node_packages스키마를 user_id 기반으로 (이는 그대로 유지하고 user→wallet 매핑으로 우회) - Admin Dev Console GoTrue UI (#424 백포트— 별도 phase)
마이그레이션 전략¶
Clean rewrite. dev/qa DB 는 reset 필요. Phase 1 과 동일한 정책 (scripts/ec2/reset-db.sh).
DoD¶
-
make build,make test통과 - WalletService 9개 RPC 가 GoTrue user JWT 없으면 Unauthenticated 거부
- Wallet 잔액 = Σ receipts (user_id) + Σ adjustments (user_id) 로 계산
-
wallet_adjustments으로 admin credit/debit 가능 (store 계층 귀니)
관련 이슈¶
Actions