Files
sylearn c592d3fb7a fix: fold truncate matching into has_prefix
Per review, drop the separate truncate mode and use its logic for
has_prefix instead. Order amounts are stored without trailing zeros
(1.50 as "1.5"), so the plain string prefix check let the 1.5 order
claim a 1.51 payment meant for a concurrent order on the same address.
Truncate the received amount to the larger of the atom precision and
the order's own decimals, then compare exactly: overpayment below the
atom precision still matches, underpayment and overpayment of a full
atom no longer do.
2026-11-01 22:49:44 +09:00

129 lines
5.9 KiB
Go

package model
import "github.com/shopspring/decimal"
type ConfKey string
type Fiat string
type CoinId string
type Crypto string
type TradeType string
type MatchMode string
type Network string
type Range struct {
MinAmount decimal.Decimal
MaxAmount decimal.Decimal
}
type TradeTypeConf struct {
Alias string // 类型别名,主要用户前端展示
NetworkName string // 网络名称,用于前端展示
Network Network // 所属区块链网络
Crypto Crypto // 币种类型
Native bool // 是否原生币
Contract string // 合约地址,原生币为空
Decimal int32 // 小数位
AmountRange Range // 合法数额范围;这里特指则扫块时[数额范围],目前偷懒全部写死一个大概合理的范围,后面有问题再说...
ExplorerFmt string // 区块浏览器交易链接格式化字符串,%s 位置替换为交易哈希
EndpointKey ConfKey // RPC 端点配置键
AddrCaseSens bool // 钱包地址是否大小写敏感,如果为 false 则会统一转为小写比较
}
const (
AdminUsername ConfKey = "admin_username"
AdminPassword ConfKey = "admin_password"
AdminSecure ConfKey = "admin_secure"
AdminSecret ConfKey = "admin_secret"
AdminLoginIP ConfKey = "admin_login_ip"
AdminLoginAt ConfKey = "admin_login_at"
ApiAuthToken ConfKey = "api_auth_token" // API 对接令牌
ApiAppUri ConfKey = "api_app_uri" // API 对接地址(收银台地址)
AtomUSDT ConfKey = "atom_usdt"
AtomUSDC ConfKey = "atom_usdc"
AtomTRX ConfKey = "atom_trx"
AtomBNB ConfKey = "atom_bnb"
AtomETH ConfKey = "atom_eth"
AtomGRAM ConfKey = "atom_gram"
MonitorMinAmount ConfKey = "monitor_min_amount" // 监控最小金额,低于此金额的入账不进行通知
PaymentMinAmount ConfKey = "payment_min_amount"
PaymentMaxAmount ConfKey = "payment_max_amount"
PaymentTimeout ConfKey = "payment_timeout" // 订单支付超时时间,单位秒
PaymentCheckout ConfKey = "payment_checkout" // 收银台模板
PaymentMatchMode ConfKey = "payment_match_mode" // 订单金额匹配模式
PaymentSupportUrl ConfKey = "payment_support_url" // 订单支付客服链接
PaymentLookbackHour ConfKey = "payment_lookback_hour" // 订单回溯时间
PaymentNetworkSort ConfKey = "payment_network_sort" // 收银台网络顺序,逗号分隔
RpcEndpointPlasma ConfKey = "rpc_endpoint_plasma" // Plasma RPC节点
RpcEndpointBsc ConfKey = "rpc_endpoint_bsc" // BSC RPC节点
RpcEndpointSolana ConfKey = "rpc_endpoint_solana" // Solana RPC节点
RpcEndpointXlayer ConfKey = "rpc_endpoint_xlayer" // Xlayer RPC节点
RpcEndpointPolygon ConfKey = "rpc_endpoint_polygon" // Polygon RPC节点
RpcEndpointArbitrum ConfKey = "rpc_endpoint_arbitrum" // Arbitrum RPC节点
RpcEndpointEthereum ConfKey = "rpc_endpoint_ethereum" // Ethereum RPC节点
RpcEndpointBase ConfKey = "rpc_endpoint_base" // Base RPC节点
RpcEndpointAptos ConfKey = "rpc_endpoint_aptos" // APTOS RPC节点
RpcEndpointTron ConfKey = "rpc_endpoint_tron" // TRON RPC节点
RpcEndpointTronGridApiKey ConfKey = "rpc_endpoint_tron_grid_api_key" // TRON RPC节点 TronGrid Api Key
RpcGlobalConfigUrlTon ConfKey = "rpc_global_config_url_ton" // Ton Global Config Url
RateSyncCoingeckoApiUrl ConfKey = "rate_sync_coingecko_api_url" // 汇率同步 Coingecko Api URL
RateSyncCoingeckoApiKey ConfKey = "rate_sync_coingecko_api_key" // 汇率同步 Coingecko Api Key
RateSyncInterval ConfKey = "rate_sync_interval" // 汇率同步间隔,单位秒
RateSyncHistoryDays ConfKey = "rate_sync_history_days" // 历史汇率保存天数
NotifyMaxRetry ConfKey = "notify_max_retry" // 最大重试次数,订单回调失败
BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描
BlockOffsetConfirm ConfKey = "block_offset_confirm" // 区块偏移确认数,扫描时以当前区块高度减去此偏移量为准,避免重链导致的订单回调失败
MqttHost ConfKey = "mqtt_host"
MqttPort ConfKey = "mqtt_port"
MqttUser ConfKey = "mqtt_user"
MqttPass ConfKey = "mqtt_pass"
MqttPublishQos ConfKey = "mqtt_publish_qos"
MqttTopicPrefix ConfKey = "mqtt_topic_prefix" // 消息发布 Topic 路径前缀
MqttNetworks ConfKey = "mqtt_networks" // 需要持续监控的区块网络
NotifierParams ConfKey = "notifier_params" // 通知参数 (token, chat_id, email
NotifierChannel ConfKey = "notifier_channel" // 通知渠道 (telegram, wechat, email
SystemInstallLock ConfKey = "system_install_lock" // 系统安装锁
HomeRedirectUrl ConfKey = "home_redirect_url"
)
const (
CNY Fiat = "CNY"
USD Fiat = "USD"
JPY Fiat = "JPY"
EUR Fiat = "EUR"
GBP Fiat = "GBP"
)
const (
USDT Crypto = "USDT"
USDC Crypto = "USDC"
TRX Crypto = "TRX"
BNB Crypto = "BNB"
ETH Crypto = "ETH"
GRAM Crypto = "GRAM" // 其实就是 Ton
)
const (
Classic MatchMode = "classic" // 经典模式,精确匹配
HasPrefix MatchMode = "has_prefix" // 前缀匹配,按原子精度截断后比较,只容忍精度以下的多付
RoundOff MatchMode = "round_off" // 数值修约,四舍五入,允许容错
)
// USD 交易类型常见扫描范围
var usdGeneralRange = Range{
MinAmount: decimal.NewFromFloat(0.01),
MaxAmount: decimal.NewFromFloat(1000000),
}
// registry 交易类型注册表【由init函数自动维护】
var networkTradesMap = make(map[Network][]TradeType)
var networkEndpointMap = make(map[Network]ConfKey)
var contractTradeMap = make(map[string]TradeType)
var contractDecimalMap = make(map[string]int32)
var tradeAmountRangeMap = make(map[TradeType]Range)
var explorerUrlMap = make(map[TradeType]string)
var cryptoAtomKeys = make(map[Crypto]ConfKey)