update: add log-system
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"m2pool-payment/internal/blockchain"
|
||||
"m2pool-payment/internal/blockchain/eth"
|
||||
"m2pool-payment/internal/crypto"
|
||||
"m2pool-payment/internal/logger"
|
||||
message "m2pool-payment/internal/msg"
|
||||
rmq "m2pool-payment/internal/queue"
|
||||
"os"
|
||||
@@ -221,9 +222,13 @@ func handleChainEvent(chainEventCh chan any) {
|
||||
if msg.Status == STATUS_PENDING {
|
||||
log.Printf("📨 [链上] 充值待确认: Address=%s, Amount=%.2f, TxHash=%s",
|
||||
msg.Address, msg.Amount, msg.TxHash)
|
||||
// 记录交易日志:待确认
|
||||
logger.LogTopup(msg.Address, "待确认", msg.Amount, msg.TxHash, msg.BlockHeight)
|
||||
} else {
|
||||
log.Printf("✅ [链上] 充值确认: Address=%s, Amount=%.2f, TxHash=%s, Status=%d",
|
||||
msg.Address, msg.Amount, msg.TxHash, msg.Status)
|
||||
// 记录交易日志:已确认
|
||||
logger.LogTopup(msg.Address, "确认", msg.Amount, msg.TxHash, msg.BlockHeight)
|
||||
}
|
||||
err := s_ctx.rmqServer.PublishTopupResp(msg)
|
||||
if err != nil {
|
||||
@@ -234,6 +239,9 @@ func handleChainEvent(chainEventCh chan any) {
|
||||
// 提现确认
|
||||
log.Printf("✅ [链上] 提现确认: QueueId=%s, Amount=%.2f, TxHash=%s, Status=%d",
|
||||
msg.QueueId, msg.Amount, msg.TxHash, msg.Status)
|
||||
// 记录交易日志
|
||||
logger.LogWithdraw(msg.QueueId, "确认", msg.Amount, msg.FromAddress,
|
||||
msg.ToAddress, msg.TxHash, msg.BlockHeight)
|
||||
err := s_ctx.rmqServer.PublishWithdrawResp(msg)
|
||||
if err != nil {
|
||||
log.Printf("❌ 发送提现响应失败: %v", err)
|
||||
@@ -243,6 +251,9 @@ func handleChainEvent(chainEventCh chan any) {
|
||||
// 支付确认
|
||||
log.Printf("✅ [链上] 支付确认: QueueId=%s, OrderId=%s, Amount=%.2f, TxHash=%s, Status=%d",
|
||||
msg.QueueId, msg.OrderId, msg.Amount, msg.TxHash, msg.Status)
|
||||
// 记录交易日志
|
||||
logger.LogPay(msg.OrderId, msg.QueueId, "确认", msg.Amount, msg.FromAddress,
|
||||
msg.ToAddress, msg.TxHash, msg.BlockHeight)
|
||||
err := s_ctx.rmqServer.PublishPayResp(msg)
|
||||
if err != nil {
|
||||
log.Printf("❌ 发送支付响应失败: %v", err)
|
||||
@@ -263,6 +274,12 @@ func Start(msgKey string) {
|
||||
// 加载配置
|
||||
loadConfig(msgKey)
|
||||
|
||||
// 初始化交易日志系统
|
||||
if err := logger.InitTransactionLogger("logs"); err != nil {
|
||||
log.Fatalf("❌ 初始化交易日志系统失败: %v", err)
|
||||
}
|
||||
log.Println("✅ 交易日志系统初始化完成")
|
||||
|
||||
// ================== 初始化区块链节点 ==================
|
||||
initBlockChainServer()
|
||||
|
||||
@@ -294,6 +311,7 @@ func Start(msgKey string) {
|
||||
|
||||
s_ctx.blockChainServer.Stop("ETH")
|
||||
s_ctx.rmqServer.Close()
|
||||
logger.CloseTransactionLogger()
|
||||
|
||||
log.Println("👋 服务已全部关闭")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user