Files
m2pool_payment/internal/msg/msg.go

170 lines
6.0 KiB
Go
Raw Normal View History

2025-10-16 18:54:27 +08:00
package msg
import "time"
// 配置文件结构
type Config struct {
2025-10-27 16:27:33 +08:00
SQLite3 SQLite3 `json:"sqlite3"`
2025-10-21 10:58:58 +08:00
RMQConfig RMQConfig `json:"rmq_config"`
ETHConfig ETHConfig `json:"eth_config"`
TRONConfig TRONConfig `json:"tron_config"`
2025-10-16 18:54:27 +08:00
}
2025-10-27 16:27:33 +08:00
type SQLite3 struct {
MsgPath string `json:"msg_path"`
}
2025-10-16 18:54:27 +08:00
type RMQConfig struct {
SubAddr string `json:"sub_addr"` // 监听地址
PayConfig QueueConfig `json:"pay"` // 支付
TopUpConfig QueueConfig `json:"topup"` // 充值
WithdrawConfig QueueConfig `json:"withdraw"` // 提现
2025-10-27 16:27:33 +08:00
RemoveConfig QueueConfig `json:"remove"` // 移除监听
2025-10-16 18:54:27 +08:00
PayRespConfig QueueConfig `json:"pay_resp"` // 支付回复
TopUpRespConfig QueueConfig `json:"topup_resp"` // 充值回复
WithdrawRespConfig QueueConfig `json:"withdraw_resp"` // 提现回复
2025-10-27 16:27:33 +08:00
RemoveRespConfig QueueConfig `json:"remove_resp"` // 移除监听回复
2025-10-16 18:54:27 +08:00
}
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"`
}
2025-10-21 10:58:58 +08:00
type TRONConfig struct {
RpcUrl string `json:"rpcUrl"`
ConfirmHeight uint64 `json:"confirmHeight"`
DbConfig DbConfig `json:"dbConfig"`
}
2025-10-16 18:54:27 +08:00
// 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"` // 连接最大存活时间
}
2025-10-27 16:27:33 +08:00
// =============================== type0 ===============================
2025-10-16 18:54:27 +08:00
// 接收的充值消息
type TopupMsg_req struct {
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
Address string `json:"address"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
}
// 返回充值结果消息
type TopupMsg_resp struct {
2025-10-21 14:25:15 +08:00
Address string `json:"address"`
Status int `json:"status"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
Amount float64 `json:"amount"`
TxHash string `json:"tx_hash"`
BlockHeight uint64 `json:"block_height"` // 区块高度
2025-10-16 18:54:27 +08:00
}
2025-10-27 16:27:33 +08:00
// =============================== type1 ===============================
2025-10-16 18:54:27 +08:00
// 接收的提现消息
type WithdrawMsg_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"` // 币种
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
}
// 返回提现结果消息
type WithdrawMsg_resp struct {
2025-10-21 14:25:15 +08:00
QueueId string `json:"queue_id"`
Chain string `json:"chain"` // 链名称
Symbol string `json:"symbol"` // 币种
2025-10-27 16:27:33 +08:00
Status int `json:"status"`
Amount float64 `json:"amount"`
2025-10-21 14:25:15 +08:00
TxHash string `json:"tx_hash"`
FromAddress string `json:"from_address"` // 来源地址
ToAddress string `json:"to_address"` // 目标地址
BlockHeight uint64 `json:"block_height"` // 区块高度
2025-10-16 18:54:27 +08:00
}
2025-10-27 16:27:33 +08:00
// =============================== type2 ===============================
2025-10-16 18:54:27 +08:00
// 接收到的支付消息
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"`
}
// 返回支付结果消息
type PayMsg_resp struct {
2025-10-21 14:25:15 +08:00
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"` // 区块高度
2025-10-16 18:54:27 +08:00
}
2025-10-27 16:27:33 +08:00
// =============================== type3 ===============================
// 接收到的删除监听地址消息
type RemoveListenMsg_req struct {
MsgType int `json:"msg_type"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
Address string `json:"address"`
Timestamp uint64 `json:"timestamp"`
Sign string `json:"sign"`
}
// 返回收到的删除监听地址消息
type RemoveListenMsg_resp struct {
MsgType int `json:"msg_type"`
Chain string `json:"chain"`
Symbol string `json:"symbol"`
Address string `json:"address"`
Status int `json:"status"` // 0失败 1成功
}
// =====================================================================
2025-10-16 18:54:27 +08:00
// 节点通用消息结构
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待确认
}