feat: 블록체인(chain) 통합 및 내부 API 추가
All checks were successful
Server CI/CD / deploy (push) Successful in 7s
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:
29
main.go
29
main.go
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"a301_server/internal/announcement"
|
||||
"a301_server/internal/auth"
|
||||
"a301_server/internal/chain"
|
||||
"a301_server/internal/download"
|
||||
"a301_server/pkg/config"
|
||||
"a301_server/pkg/database"
|
||||
@@ -23,7 +24,7 @@ func main() {
|
||||
log.Println("MySQL 연결 성공")
|
||||
|
||||
// AutoMigrate
|
||||
database.DB.AutoMigrate(&auth.User{}, &announcement.Announcement{}, &download.Info{})
|
||||
database.DB.AutoMigrate(&auth.User{}, &announcement.Announcement{}, &download.Info{}, &chain.UserWallet{})
|
||||
|
||||
if err := database.ConnectRedis(); err != nil {
|
||||
log.Fatalf("Redis 연결 실패: %v", err)
|
||||
@@ -42,6 +43,30 @@ func main() {
|
||||
log.Printf("admin 계정 확인 완료: %s", config.C.AdminUsername)
|
||||
}
|
||||
|
||||
// Chain (blockchain integration)
|
||||
chainClient := chain.NewClient(config.C.ChainNodeURL)
|
||||
chainRepo := chain.NewRepository(database.DB)
|
||||
chainSvc, err := chain.NewService(chainRepo, chainClient, config.C.ChainID, config.C.OperatorKeyHex, config.C.WalletEncryptionKey)
|
||||
if err != nil {
|
||||
log.Fatalf("chain service init failed: %v", err)
|
||||
}
|
||||
chainHandler := chain.NewHandler(chainSvc)
|
||||
|
||||
// username → userID 변환 (게임 서버 내부 API용)
|
||||
chainSvc.SetUserResolver(func(username string) (uint, error) {
|
||||
user, err := authRepo.FindByUsername(username)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return user.ID, nil
|
||||
})
|
||||
|
||||
// 회원가입 시 블록체인 월렛 자동 생성
|
||||
authSvc.SetWalletCreator(func(userID uint) error {
|
||||
_, err := chainSvc.CreateWallet(userID)
|
||||
return err
|
||||
})
|
||||
|
||||
annRepo := announcement.NewRepository(database.DB)
|
||||
annSvc := announcement.NewService(annRepo)
|
||||
annHandler := announcement.NewHandler(annSvc)
|
||||
@@ -60,7 +85,7 @@ func main() {
|
||||
AllowMethods: "GET, POST, PUT, PATCH, DELETE",
|
||||
}))
|
||||
|
||||
routes.Register(app, authHandler, annHandler, dlHandler)
|
||||
routes.Register(app, authHandler, annHandler, dlHandler, chainHandler)
|
||||
|
||||
log.Fatal(app.Listen(":" + config.C.AppPort))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user