This commit is contained in:
lzx
2025-11-13 17:08:38 +08:00
parent 8d7da5d345
commit 00389efb75
25 changed files with 2919 additions and 1967 deletions

53
internal/msg/config.go Normal file
View File

@@ -0,0 +1,53 @@
package msg
import "time"
// 配置文件结构
type Config struct {
Net []string `json:"net"`
RmqConfig RmqConfig `json:"rmq_config"`
MsgConfig MsgConfig `json:"msg_config"`
MysqlConfig map[string]MysqlConfig `json:"mysql_config"` // {dbname: MysqlConfig{}, ...}
ETHConfig ETHConfig `json:"eth_config"`
}
type RmqConfig struct {
SubAddr string `json:"sub_addr"`
Pay Queue `json:"pay"`
Topup Queue `json:"topup"`
Withdraw Queue `json:"withdraw"`
Remove Queue `json:"remove"`
PayResp Queue `json:"pay_resp"`
TopupResp Queue `json:"topup_resp"`
WithdrawResp Queue `json:"withdraw_resp"`
RemoveResp Queue `json:"remove_resp"`
}
type Queue struct {
Queue string `json:"queue"`
Exchange string `json:"exchange"`
Routing []string `json:"routing"`
}
type MsgConfig struct {
SqlitePath string `json:"sqlite_path"` // sqlite3数据库文件路径
}
type MysqlConfig struct {
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port int `json:"port"`
Database string `json:"database"`
MaxOpenConns int `json:"maxOpenConns"`
MaxIdleConns int `json:"maxIdleConns"`
ConnMaxLife time.Duration `json:"connMaxLife"`
}
type ETHConfig struct {
RpcUrl string `json:"rpc_url"`
WsUrl string `json:"ws_url"`
ConfirmHeight uint64 `json:"confirm_height"`
SqlitePath string `json:"sqlite_path"` // sqlite3数据库文件路径
SupportTokens []string `json:"support_tokens"` // 支持的代币列表,如["USDT", "DAI"]
}

View File

@@ -1,61 +1,6 @@
package msg
import "time"
// 配置文件结构
type Config struct {
SQLite3 SQLite3 `json:"sqlite3"`
RMQConfig RMQConfig `json:"rmq_config"`
ETHConfig ETHConfig `json:"eth_config"`
TRONConfig TRONConfig `json:"tron_config"`
}
type SQLite3 struct {
MsgPath string `json:"msg_path"`
}
type RMQConfig struct {
SubAddr string `json:"sub_addr"` // 监听地址
PayConfig QueueConfig `json:"pay"` // 支付
TopUpConfig QueueConfig `json:"topup"` // 充值
WithdrawConfig QueueConfig `json:"withdraw"` // 提现
RemoveConfig QueueConfig `json:"remove"` // 移除监听
PayRespConfig QueueConfig `json:"pay_resp"` // 支付回复
TopUpRespConfig QueueConfig `json:"topup_resp"` // 充值回复
WithdrawRespConfig QueueConfig `json:"withdraw_resp"` // 提现回复
RemoveRespConfig QueueConfig `json:"remove_resp"` // 移除监听回复
}
type QueueConfig struct {
QueueName string `json:"queue"`
ExchangeName string `json:"exchange"`
Routing []string `json:"routing"`
}
type ETHConfig struct {
RpcURL string `json:"rpcUrl"` // rpc连接地址
WsURL string `json:"wsUrl"` // websocket连接地址
ConfirmHeight uint64 `json:"confirmHeight"` // 确认所需区块数
DbConfig DbConfig `json:"dbConfig"`
}
type TRONConfig struct {
RpcUrl string `json:"rpcUrl"`
ConfirmHeight uint64 `json:"confirmHeight"`
DbConfig DbConfig `json:"dbConfig"`
}
// Config 数据库配置
type DbConfig struct {
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port int `json:"port"`
Database string `json:"database"`
MaxOpenConns int `json:"maxOpenConns"` // 最大打开连接数
MaxIdleConns int `json:"maxIdleCoons"` // 最大空闲连接数
ConnMaxLife time.Duration `json:"connMaxLife"` // 连接最大存活时间
}
import "math/big"
// =============================== type0 ===============================
// 接收的充值消息
@@ -66,31 +11,32 @@ type TopupMsg_req struct {
Address string `json:"address"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
Status int `json:"status,omitempty"`
Status int `json:"status,omitempty"` // 1监听中2停止监听
}
// 返回充值结果消息
type TopupMsg_resp struct {
QueueId string `json:"queue_id"`
Address string `json:"address"`
Status int `json:"status"` // 0失败1成功2待定3sign校验失败
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
Amount float64 `json:"amount"`
TxHash string `json:"tx_hash"`
BlockHeight uint64 `json:"block_height"` // 区块高度
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
FromAddress string `json:"from_address,omitempty"` // 充值来源地址
Address string `json:"address"` // 充值目标地址
TxHash string `json:"tx_hash,omitempty"`
Amount float64 `json:"amount,omitempty"`
BlockHeight uint64 `json:"block_height,omitempty"` // 区块高度
Status int `json:"status"` // 0失败1成功2待定3sign校验失败
}
// =============================== type1 ===============================
// 接收的提现消息
type WithdrawMsg_req struct {
QueueId string `json:"queue_id"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
FromAddress string `json:"from_address"` // 我们提供的地址
ToAddress string `json:"to_address"` // 用户要提现到的地址
Amount float64 `json:"amount"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
TxHash string `json:"tx_hash,omitempty"`
Fee float64 `json:"fee"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
Status int `json:"status,omitempty"`
@@ -99,80 +45,52 @@ type WithdrawMsg_req struct {
// 返回提现结果消息
type WithdrawMsg_resp struct {
QueueId string `json:"queue_id"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
Status int `json:"status"` // 0失败1成功3sign校验失败
Amount float64 `json:"amount"`
TxHash string `json:"tx_hash"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
FromAddress string `json:"from_address"` // 来源地址
ToAddress string `json:"to_address"` // 目标地址
BlockHeight uint64 `json:"block_height"` // 区块高度
TxHash string `json:"tx_hash,omitempty"`
Amount float64 `json:"amount,omitempty"`
Fee float64 `json:"fee,omitempty"`
BlockHeight uint64 `json:"block_height,omitempty"` // 区块高度
Status int `json:"status"` // 0失败1成功3sign校验失败
}
// =============================== type2 ===============================
type PayMsg_req struct {
QueueId string `json:"queue_id"`
FromAddress string `json:"from_address"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
TotalAmount float64 `json:"total_amount"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
Trasnactions map[string]*PayData_req `json:"transactions"` // {"to_address": PayData_req{}, ...}
}
type PayData_req struct {
OrderId string `json:"order_id"`
ToAddress string `json:"to_address"`
TxHash string `json:"tx_hash,omitempty"`
Amount float64 `json:"amount"`
Status int `json:"status,omitempty"`
QueueId string `json:"queue_id"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
FromAddress string `json:"from_address"`
TotalAmount float64 `json:"total_amount"`
TotalFee float64 `json:"total_fee"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
Transactions map[string]PayData `json:"transactions"` // {"to_address": PayData_req{}, ...}
Status int `json:"status,omitempty"`
}
type PayMsg_resp struct {
QueueId string `json:"queue_id"`
FromAddress string `json:"from_address"`
PayStatus int `json:"pay_status"` // 1至少有一笔转账成功3sign校验失败4钱包余额不足
Transactions map[string]*PayData_resp `json:"transactions"` // {"to_address": PayData_resp{}, ...}
}
type PayData_resp struct {
OrderId string `json:"order_id"`
FromAddress string `json:"from_address"`
ToAddress string `json:"to_address"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
Amount float64 `json:"amount"`
TxHash string `json:"tx_hash,omitempty"`
BlockHeight uint64 `json:"block_height,omitempty"`
Status int `json:"status"` // 0失败1成功
QueueId string `json:"queue_id"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
FromAddress string `json:"from_address"`
PayStatus int `json:"pay_status"` // 1至少有一笔转账成功3sign校验失败4钱包余额不足
Transactions map[string]PayData `json:"transactions"` // {"to_address": PayData_resp{}, ...}
}
// 接收到的支付消息
// type PayMsg_req struct {
// QueueId string `json:"queue_id"`
// FromAddress string `json:"from_address"` // 我们提供的地址
// ToAddress string `json:"to_address"` // 卖家地址
// Amount float64 `json:"amount"`
// Chain string `json:"chain"` // 链名称
// Symbol string `json:"symbol"` // 币种
// OrderId string `json:"order_id"` // 订单号
// Timestamp uint64 `json:"timestamp"`
// Sign string `json:"sign"`
// Transactions map[string]Transaction `json:"tx"`
// }
// 返回支付结果消息
// type PayMsg_resp struct {
// QueueId string `json:"queue_id"`
// Status int `json:"status"`
// Amount float64 `json:"amount"`
// Chain string `json:"chain"` // 链名称
// Symbol string `json:"symbol"` // 币种
// OrderId string `json:"order_id"` // 订单号
// TxHash string `json:"tx_hash"`
// FromAddress string `json:"from_address"` // 来源地址
// ToAddress string `json:"to_address"` // 目标地址
// BlockHeight uint64 `json:"block_height"` // 区块高度
// }
type PayData struct {
QueueId string `json:"queue_id,omitempty"`
Chain string `json:"chain,omitempty"`
Symbol string `json:"symbol,omitempty"`
TxHash string `json:"tx_hash,omitempty"`
ToAddress string `json:"to_address"`
Amount float64 `json:"amount"`
Fee float64 `json:"fee"`
BlockHeight uint64 `json:"block_height,omitempty"`
Status int `json:"status,omitempty"` // 0失败1成功, 2待确认
}
// =============================== type3 ===============================
// 接收到的删除监听地址消息
@@ -184,6 +102,7 @@ type RemoveListenMsg_req struct {
Address string `json:"address"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
Stauts int `json:"status,omitempty"`
}
// 返回收到的删除监听地址消息
@@ -196,28 +115,43 @@ type RemoveListenMsg_resp struct {
Status int `json:"status"` // 0失败 1成功
}
// =====================================================================
// 节点通用消息结构
type Tx_msg struct {
TxType int `json:"tx_type"` // 转账类型0充值1提现2支付
Tx Tx `json:"tx"`
}
type Tx struct {
From string `json:"from"` // 充值/提现/支付的来源地址
To string `json:"to"` // 充值/提现/支付的目标地址
Height uint64 `json:"height"` // 区块高度
TxHash string `json:"tx_hash"` // 交易哈希
Symbol string `json:"symbol"` // 币种
Value float64 `json:"value"` // 数量,单位是币
Status int `json:"status"` // 交易状态1成功0失败, 2待确认
// =============================== ChainServer -> ListenServer ===============================
// 节点服务响应
type ChainServer_resp struct {
QueueId string
MsgType int
Chain string
Symbol string
Status int // 遵循constant模块定义
}
// =============================== 其他 ===============================
type Transaction struct {
From string `json:"from"` // 充值/提现/支付的来源地址
To string `json:"to"` // 充值/提现/支付的目标地址
Height uint64 `json:"height"` // 区块高度
TxHash string `json:"tx_hash"` // 交易哈希
Symbol string `json:"symbol"` // 币种
Value float64 `json:"value"` // 数量,单位是币
Status int `json:"status"` // 交易状态1成功0失败, 2待确认
QueueId string `json:"queue_id,omitempty"` // 交易对应的QueueId
// 交易对应的消息类型0充值 1提现 2支付
// 充值tx.to_address = msg.Address
// 提现/支付tx.to_address = msg.ToAddress && tx.from_address = msg.FromAddress && tx.value = msg.Amount
// 同时还要通过msg确认属于哪种类型即上述3个条件是否都存在于某个msg钟
TxType int `json:"tx_type,omitempty"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
From string `json:"from"`
To string `json:"to"`
TxHash string `json:"tx_hash,omitempty"`
Height uint64 `json:"height,omitempty"`
Amount *big.Int `json:"amount"`
GasUsed *big.Int `json:"gas_used,omitempty"` // 转账实际产生的eth消耗
FreezeFee *big.Int `json:"freeze_fee,omitempty"` // erc20转账冻结的usdt,只有提现才会修改
Status int `json:"status"` // 交易状态1成功0失败, 2待确认
}
type TransferResult struct {
QueueId string
MsgType int // 1提现2支付
Chain string
Symbol string
FromAddress string
ToAddress string
Amount float64
Status int
}