update
This commit is contained in:
@@ -293,77 +293,77 @@ func (e *ETHNode) handleUSDTEvent(vLog types.Log, ch chan any) {
|
||||
return
|
||||
}
|
||||
tx_hash := vLog.TxHash.Hex()
|
||||
tx, tx_ok := e.UnConfirmTxs[tx_hash]
|
||||
if tx_ok {
|
||||
// 【支付/提现】待确认交易中存在该交易Hash(说明是我们主动发起的交易)
|
||||
// 直接走确认流程,不发送待确认消息
|
||||
// log.Printf("🔍 检测到已发起的交易: TxHash=%s, Type=%d", tx_hash, tx.TxType)
|
||||
e.confirm("USDT", height, tx, ch)
|
||||
} else {
|
||||
// 【充值】待确认交易中不存在该交易hash(说明是外部转账)
|
||||
// 添加至待确认交易中,并立即发送待确认消息
|
||||
// 1,先根据to查询RmqMsgs,再根据存在的rmq_msg中的相关数据,存入待确认交易
|
||||
value, rmq_msg_ok := e.RmqMsgs[toAddr]
|
||||
var tx_type int
|
||||
if rmq_msg_ok {
|
||||
for _, v := range value {
|
||||
_, ok := v.(message.TopupMsg_req)
|
||||
if ok {
|
||||
tx_type = 0
|
||||
}
|
||||
_, ok1 := v.(message.WithdrawMsg_req)
|
||||
if ok1 {
|
||||
tx_type = 1
|
||||
}
|
||||
_, ok2 := v.(message.PayMsg_req)
|
||||
if ok2 {
|
||||
tx_type = 2
|
||||
}
|
||||
// tx, tx_ok := e.UnConfirmTxs[tx_hash]
|
||||
// if tx_ok {
|
||||
// // 【支付/提现】待确认交易中存在该交易Hash(说明是我们主动发起的交易)
|
||||
// // 直接走确认流程,不发送待确认消息
|
||||
// // log.Printf("🔍 检测到已发起的交易: TxHash=%s, Type=%d", tx_hash, tx.TxType)
|
||||
// e.confirm("USDT", height, tx, ch)
|
||||
// } else {
|
||||
// 【充值】待确认交易中不存在该交易hash(说明是外部转账)
|
||||
// 添加至待确认交易中,并立即发送待确认消息
|
||||
// 1,先根据to查询RmqMsgs,再根据存在的rmq_msg中的相关数据,存入待确认交易
|
||||
value, rmq_msg_ok := e.RmqMsgs[toAddr]
|
||||
var tx_type int
|
||||
if rmq_msg_ok {
|
||||
for _, v := range value {
|
||||
_, ok := v.(message.TopupMsg_req)
|
||||
if ok {
|
||||
tx_type = 0
|
||||
}
|
||||
_, ok1 := v.(message.WithdrawMsg_req)
|
||||
if ok1 {
|
||||
tx_type = 1
|
||||
}
|
||||
_, ok2 := v.(message.PayMsg_req)
|
||||
if ok2 {
|
||||
tx_type = 2
|
||||
}
|
||||
}
|
||||
e.UnConfirmTxs[tx_hash] = message.Tx_msg{
|
||||
TxType: tx_type,
|
||||
Tx: message.Tx{
|
||||
From: fromAddr,
|
||||
To: toAddr,
|
||||
Height: height,
|
||||
TxHash: tx_hash,
|
||||
Symbol: "USDT",
|
||||
Value: utils.BigIntUSDTToFloat64(transferEvent.Value),
|
||||
Status: 2, // 待确认状态
|
||||
},
|
||||
}
|
||||
// log.Printf("📝 待确认交易新增: TxHash=%s, Height=%d, To=%s, Type=%d", tx_hash, height, toAddr, tx_type)
|
||||
}
|
||||
e.UnConfirmTxs[tx_hash] = message.Tx_msg{
|
||||
TxType: tx_type,
|
||||
Tx: message.Tx{
|
||||
From: fromAddr,
|
||||
To: toAddr,
|
||||
Height: height,
|
||||
TxHash: tx_hash,
|
||||
Symbol: "USDT",
|
||||
Value: utils.BigIntUSDTToFloat64(transferEvent.Value),
|
||||
Status: 2, // 待确认状态
|
||||
},
|
||||
}
|
||||
// log.Printf("📝 待确认交易新增: TxHash=%s, Height=%d, To=%s, Type=%d", tx_hash, height, toAddr, tx_type)
|
||||
|
||||
// 🔔 【仅充值】立即发送待确认状态的消息(支付/提现不发送待确认消息)
|
||||
if tx_type == 0 && rmq_msg_ok {
|
||||
for _, v := range value {
|
||||
d1, ok := v.(message.TopupMsg_req)
|
||||
if ok && strings.ToLower(d1.Address) == toAddr {
|
||||
pendingMsg := message.TopupMsg_resp{
|
||||
Address: toAddr,
|
||||
Status: 2, // 待确认状态
|
||||
Chain: d1.Chain,
|
||||
Symbol: d1.Symbol,
|
||||
Amount: utils.BigIntUSDTToFloat64(transferEvent.Value),
|
||||
TxHash: tx_hash,
|
||||
// 🔔 【仅充值】立即发送待确认状态的消息(支付/提现不发送待确认消息)
|
||||
if tx_type == 0 && rmq_msg_ok {
|
||||
for _, v := range value {
|
||||
d1, ok := v.(message.TopupMsg_req)
|
||||
if ok && strings.ToLower(d1.Address) == toAddr {
|
||||
pendingMsg := message.TopupMsg_resp{
|
||||
Address: toAddr,
|
||||
Status: 2, // 待确认状态
|
||||
Chain: d1.Chain,
|
||||
Symbol: d1.Symbol,
|
||||
Amount: utils.BigIntUSDTToFloat64(transferEvent.Value),
|
||||
TxHash: tx_hash,
|
||||
}
|
||||
// log.Printf("📤 发送待确认充值消息: TxHash=%s, Address=%s, Amount=%.2f",
|
||||
// tx_hash, toAddr, pendingMsg.Amount)
|
||||
|
||||
// 异步发送,避免阻塞事件处理
|
||||
go func(msg message.TopupMsg_resp) {
|
||||
select {
|
||||
case ch <- msg:
|
||||
log.Printf("✅ 待确认充值消息已发送")
|
||||
default:
|
||||
log.Printf("⚠️ 通道阻塞,待确认消息发送失败")
|
||||
}
|
||||
// log.Printf("📤 发送待确认充值消息: TxHash=%s, Address=%s, Amount=%.2f",
|
||||
// tx_hash, toAddr, pendingMsg.Amount)
|
||||
|
||||
// 异步发送,避免阻塞事件处理
|
||||
go func(msg message.TopupMsg_resp) {
|
||||
select {
|
||||
case ch <- msg:
|
||||
log.Printf("✅ 待确认充值消息已发送")
|
||||
default:
|
||||
log.Printf("⚠️ 通道阻塞,待确认消息发送失败")
|
||||
}
|
||||
}(pendingMsg)
|
||||
break
|
||||
}
|
||||
}(pendingMsg)
|
||||
break
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,11 +577,11 @@ func (e *ETHNode) decodePrivatekey(address string) string {
|
||||
func (e *ETHNode) usdt_transfer(msg any) error {
|
||||
var user_from, final_from, to string
|
||||
var amount float64
|
||||
var tx_type int
|
||||
now_height, err := e.getBlockHeight()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get lastest height error: %v", err)
|
||||
}
|
||||
// var tx_type int
|
||||
// now_height, err := e.getBlockHeight()
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("get lastest height error: %v", err)
|
||||
// }
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 断言,确定本次转账是哪个类型
|
||||
// 支付操作
|
||||
@@ -590,7 +590,7 @@ func (e *ETHNode) usdt_transfer(msg any) error {
|
||||
e.AddAddress(v.ToAddress, v) // 存入该笔msg(AddAddress内部会转小写)
|
||||
// 统一转换为小写
|
||||
user_from, final_from, to, amount = strings.ToLower(v.FromAddress), strings.ToLower(v.FromAddress), strings.ToLower(v.ToAddress), v.Amount
|
||||
tx_type = 2
|
||||
// tx_type = 2
|
||||
}
|
||||
// 提现操作
|
||||
k, ok1 := msg.(message.WithdrawMsg_req)
|
||||
@@ -598,7 +598,7 @@ func (e *ETHNode) usdt_transfer(msg any) error {
|
||||
e.AddAddress(k.ToAddress, k) // 存入该笔msg(AddAddress内部会转小写)
|
||||
// 统一转换为小写
|
||||
user_from, final_from, to, amount = strings.ToLower(k.FromAddress), strings.ToLower(k.FromAddress), strings.ToLower(k.ToAddress), k.Amount
|
||||
tx_type = 1
|
||||
// tx_type = 1
|
||||
}
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 1,校验钱包余额
|
||||
@@ -658,7 +658,7 @@ func (e *ETHNode) usdt_transfer(msg any) error {
|
||||
)
|
||||
// 6, 签名交易并获得txHash
|
||||
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(e.NetId), privateKey)
|
||||
txHash := signedTx.Hash().Hex() // 通过签名信息解析出交易hash
|
||||
// txHash := signedTx.Hash().Hex() // 通过签名信息解析出交易hash
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to sign transaction: %w", err)
|
||||
}
|
||||
@@ -667,21 +667,21 @@ func (e *ETHNode) usdt_transfer(msg any) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send transaction: %w", err)
|
||||
}
|
||||
// 8, 构造交易消息
|
||||
tx_msg := message.Tx_msg{
|
||||
TxType: tx_type,
|
||||
Tx: message.Tx{
|
||||
From: final_from,
|
||||
To: to,
|
||||
Height: now_height,
|
||||
TxHash: txHash,
|
||||
Symbol: "USDT",
|
||||
Value: amount,
|
||||
Status: 2,
|
||||
},
|
||||
}
|
||||
// 9, 将构造的交易消息存入待确认交易中
|
||||
e.UnConfirmTxs[txHash] = tx_msg
|
||||
// // 8, 构造交易消息
|
||||
// tx_msg := message.Tx_msg{
|
||||
// TxType: tx_type,
|
||||
// Tx: message.Tx{
|
||||
// From: final_from,
|
||||
// To: to,
|
||||
// Height: now_height,
|
||||
// TxHash: txHash,
|
||||
// Symbol: "USDT",
|
||||
// Value: amount,
|
||||
// Status: 2,
|
||||
// },
|
||||
// }
|
||||
// // 9, 将构造的交易消息存入待确认交易中
|
||||
// e.UnConfirmTxs[txHash] = tx_msg
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user