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

@@ -22,6 +22,15 @@ type Config struct {
AdminPassword string
BaseURL string
GameDir string
// Chain integration
ChainNodeURL string
ChainID string
OperatorKeyHex string
WalletEncryptionKey string
// Server-to-server auth
InternalAPIKey string
}
var C Config
@@ -45,6 +54,13 @@ func Load() {
AdminPassword: getEnv("ADMIN_PASSWORD", "admin1234"),
BaseURL: getEnv("BASE_URL", "http://localhost:8080"),
GameDir: getEnv("GAME_DIR", "/data/game"),
ChainNodeURL: getEnv("CHAIN_NODE_URL", "http://localhost:8545"),
ChainID: getEnv("CHAIN_ID", "tolchain-dev"),
OperatorKeyHex: getEnv("OPERATOR_KEY_HEX", ""),
WalletEncryptionKey: getEnv("WALLET_ENCRYPTION_KEY", ""),
InternalAPIKey: getEnv("INTERNAL_API_KEY", ""),
}
}

View File

@@ -52,3 +52,12 @@ func AdminOnly(c *fiber.Ctx) error {
}
return c.Next()
}
// ServerAuth validates X-API-Key header for server-to-server communication.
func ServerAuth(c *fiber.Ctx) error {
key := c.Get("X-API-Key")
if key == "" || config.C.InternalAPIKey == "" || key != config.C.InternalAPIKey {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "유효하지 않은 API 키입니다"})
}
return c.Next()
}