feat: 블록체인(chain) 통합 및 내부 API 추가
All checks were successful
Server CI/CD / deploy (push) Successful in 7s

- internal/chain 패키지 추가 (client, handler, service, repository, model)
- 체인 연동 엔드포인트: 지갑 조회, 잔액, 자산, 인벤토리, 마켓 등
- 관리자 전용 체인 엔드포인트: 민팅, 보상, 템플릿 등록
- 게임 서버용 내부 API (/api/internal/chain/*) + ServerAuth 미들웨어
- 회원가입 시 블록체인 월렛 자동 생성
- 체인 관련 환경변수 및 InternalAPIKey 설정 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 13:18:15 +09:00
parent 1b6260ee4e
commit f8b23e93bf
12 changed files with 1173 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ package auth
import (
"context"
"fmt"
"log"
"time"
"a301_server/pkg/config"
@@ -19,14 +20,21 @@ type Claims struct {
}
type Service struct {
repo *Repository
rdb *redis.Client
repo *Repository
rdb *redis.Client
walletCreator func(userID uint) error
}
func NewService(repo *Repository, rdb *redis.Client) *Service {
return &Service{repo: repo, rdb: rdb}
}
// SetWalletCreator sets the callback invoked after user registration
// to create a blockchain wallet.
func (s *Service) SetWalletCreator(fn func(userID uint) error) {
s.walletCreator = fn
}
func (s *Service) Login(username, password string) (string, *User, error) {
user, err := s.repo.FindByUsername(username)
if err != nil {
@@ -85,11 +93,20 @@ func (s *Service) Register(username, password string) error {
if err != nil {
return fmt.Errorf("비밀번호 처리에 실패했습니다")
}
return s.repo.Create(&User{
user := &User{
Username: username,
PasswordHash: string(hash),
Role: RoleUser,
})
}
if err := s.repo.Create(user); err != nil {
return err
}
if s.walletCreator != nil {
if err := s.walletCreator(user.ID); err != nil {
log.Printf("WARNING: wallet creation failed for user %d: %v", user.ID, err)
}
}
return nil
}
// VerifyToken validates a JWT and its Redis session, returning (username, error).