model

package
v1.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderApiTypeEpusdt = "epusdt" // epusdt
	OrderApiTypeEpay   = "epay"   // 彩虹易支付
)
View Source
const (
	WaStatusEnable  uint8 = 1
	WaStatusDisable uint8 = 0
	WaOtherEnable   uint8 = 1
	WaOtherDisable  uint8 = 0
)

Variables

View Source
var Db *gorm.DB

Functions

func AddrCaseSens added in v1.23.0

func AddrCaseSens(t TradeType) bool

func AuthToken added in v1.23.0

func AuthToken() string

func AutoMigrate added in v1.9.26

func AutoMigrate() error

func CalcTradeAmount

func CalcTradeAmount(address []string, rate, money decimal.Decimal, t TradeType) (string, string, error)

CalcTradeAmount 计算当前实际可用的交易金额

func CalcTradeExpiredAt added in v1.22.1

func CalcTradeExpiredAt(sec int64) time.Time

CalcTradeExpiredAt 计算订单过期时间 最小180,最大3600,默认1200

func CheckoutCounter added in v1.23.0

func CheckoutCounter(host, id string) string

func Close added in v1.23.0

func Close()

func CoingeckoRate added in v1.23.0

func CoingeckoRate() error

func ConfInit added in v1.23.0

func ConfInit()

func Endpoint added in v1.23.0

func Endpoint(net Network) string

func GetAllAlias added in v1.23.0

func GetAllAlias() map[string]string

func GetAtomicity added in v1.23.0

func GetAtomicity(t TradeType) (decimal.Decimal, int32)

func GetAvailableAddress

func GetAvailableAddress(t TradeType) []string

func GetC added in v1.23.0

func GetC(k ConfKey) string

GetC 从缓存获取配置,适用于高频读取,依赖 RefreshC 刷新缓存

func GetContractDecimal added in v1.23.0

func GetContractDecimal(addr string) int32

func GetInstallInfo added in v1.23.0

func GetInstallInfo() gin.H

func GetK added in v1.13.29

func GetK(k ConfKey) string

func GetSupportCrypto added in v1.23.0

func GetSupportCrypto() map[Crypto]CoinId

func GetSupportFiat added in v1.23.0

func GetSupportFiat() map[Fiat]struct{}

func GetTradeDecimal added in v1.23.0

func GetTradeDecimal(t TradeType) int32

func GetTxUrl added in v1.23.0

func GetTxUrl(t TradeType, hash string) string

func GetVs added in v1.23.0

func GetVs(keys []ConfKey) map[ConfKey]string

func Init

func Init(path, dsn string) error

func InstallLock added in v1.23.0

func InstallLock()

func IsAmountValid added in v1.23.0

func IsAmountValid(t TradeType, d decimal.Decimal) bool

func IsInstalled added in v1.23.0

func IsInstalled() bool

func IsNeedNotifyByTxid

func IsNeedNotifyByTxid(txid string) bool

func IsSupportedTradeType added in v1.23.0

func IsSupportedTradeType(t TradeType) bool

func ParseFloatRate added in v1.23.0

func ParseFloatRate(syntax string, rawVal float64) float64

func RefreshC added in v1.23.0

func RefreshC()

func SetK added in v1.13.29

func SetK(k ConfKey, v string)

Types

type AutoTimeAt added in v1.23.0

type AutoTimeAt struct {
	CreatedAt *Datetime `gorm:"column:created_at;type:Datetime;not null;comment:记录创建时间;index" json:"created_at"`
	UpdatedAt *Datetime `gorm:"column:updated_at;type:Datetime;not null;comment:最后更新时间" json:"updated_at"`
}

type CoinId added in v1.23.0

type CoinId string

type Conf added in v1.23.0

type Conf struct {
	K ConfKey `gorm:"column:k;type:varchar(32);not null;primaryKey" json:"key"`
	V string  `gorm:"column:v;type:varchar(255);not null" json:"val"`
}

func (Conf) TableName added in v1.23.0

func (c Conf) TableName() string

type ConfKey added in v1.23.0

type ConfKey string
const (
	AdminUsername ConfKey = "admin_username"
	AdminPassword ConfKey = "admin_password"
	AdminSecure   ConfKey = "admin_secure"
	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"

	MonitorMinAmount  ConfKey = "monitor_min_amount" // 监控最小金额,低于此金额的入账不进行通知
	PaymentMinAmount  ConfKey = "payment_min_amount"
	PaymentMaxAmount  ConfKey = "payment_max_amount"
	PaymentTimeout    ConfKey = "payment_timeout"     // 订单支付超时时间,单位秒
	PaymentStaticPath ConfKey = "payment_static_path" // 收银台静态资源路径
	PaymentMatchMode  ConfKey = "payment_match_mode"  // 订单金额匹配模式

	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

	RateSyncInterval   ConfKey = "rate_sync_interval"    // 汇率同步间隔,单位秒
	NotifyMaxRetry     ConfKey = "notify_max_retry"      // 最大重试次数,订单回调失败
	BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描

	NotifierParams  ConfKey = "notifier_params"  // 通知参数 (token, chat_id, email
	NotifierChannel ConfKey = "notifier_channel" // 通知渠道 (telegram, wechat, email

	SystemInstallLock ConfKey = "system_install_lock" // 系统安装锁
)

func GetTradeAtomKey added in v1.23.0

func GetTradeAtomKey(t TradeType) (ConfKey, bool)

type Crypto added in v1.23.0

type Crypto string
const (
	USDT Crypto = "USDT"
	USDC Crypto = "USDC"
	TRX  Crypto = "TRX"
	BNB  Crypto = "BNB"
	ETH  Crypto = "ETH"
)

func GetCrypto added in v1.23.0

func GetCrypto(t TradeType) (Crypto, error)

type Datetime added in v1.23.0

type Datetime time.Time

func (*Datetime) Before added in v1.23.0

func (d *Datetime) Before(u time.Time) bool

func (*Datetime) Format added in v1.23.0

func (d *Datetime) Format(layout string) string

func (*Datetime) MarshalJSON added in v1.23.0

func (d *Datetime) MarshalJSON() ([]byte, error)

func (*Datetime) Scan added in v1.23.0

func (d *Datetime) Scan(v interface{}) error

func (*Datetime) String added in v1.23.0

func (d *Datetime) String() string

func (*Datetime) Time added in v1.23.0

func (d *Datetime) Time() time.Time

func (Datetime) Value added in v1.23.0

func (d Datetime) Value() (driver.Value, error)

func (*Datetime) Year added in v1.23.0

func (d *Datetime) Year() string

type Fiat added in v1.23.0

type Fiat string
const (
	CNY Fiat = "CNY"
	USD Fiat = "USD"
	JPY Fiat = "JPY"
	EUR Fiat = "EUR"
	GBP Fiat = "GBP"
)

type Id added in v1.23.0

type Id struct {
	ID int64 `gorm:"column:id;primaryKey;autoIncrement;not null;comment:主键ID" json:"id"`
}

type MatchMode added in v1.23.0

type MatchMode string
const (
	Classic   MatchMode = "classic"    // 经典模式,精确匹配
	HasPrefix MatchMode = "has_prefix" // 前缀匹配,允许多付
	RoundOff  MatchMode = "round_off"  // 数值修约,四舍五入,允许容错
)

type Network added in v1.23.0

type Network string

type NotifyRecord

type NotifyRecord struct {
	Id
	Txid string `gorm:"type:varchar(128);uniqueIndex;not null;comment:交易哈希"`
	AutoTimeAt
}

func (NotifyRecord) TableName

func (nr NotifyRecord) TableName() string

type Order added in v1.23.0

type Order struct {
	Id
	OrderId     string     `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
	TradeId     string     `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
	TradeType   TradeType  `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
	Fiat        Fiat       `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
	Crypto      Crypto     `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
	Rate        string     `gorm:"column:rate;type:varchar(10);not null;comment:交易汇率" json:"rate"`
	Amount      string     `gorm:"column:amount;type:varchar(32);not null;default:0.00;comment:交易数额" json:"amount"`
	Money       string     `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
	Address     string     `gorm:"column:address;type:varchar(128);index;not null;comment:收款地址" json:"address"`
	FromAddress string     `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
	Status      int        `gorm:"column:status;type:tinyint(1);not null;default:1;index;comment:交易状态" json:"status"`
	Name        string     `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
	ApiType     string     `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
	ReturnUrl   string     `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
	NotifyUrl   string     `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
	NotifyNum   int        `gorm:"column:notify_num;type:int(11);not null;default:0;comment:回调次数" json:"notify_num"`
	NotifyState int        `gorm:"column:notify_state;type:tinyint(1);not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
	RefHash     string     `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
	RefBlockNum int64      `gorm:"column:ref_block_num;type:varchar(64);not null;default:0;comment:区块索引" json:"ref_block_num"`
	ExpiredAt   time.Time  `gorm:"column:expired_at;type:datetime;not null;comment:失效时间" json:"expired_at"`
	ConfirmedAt *time.Time `gorm:"column:confirmed_at;type:datetime;not null;comment:交易确认时间" json:"confirmed_at"`
	AutoTimeAt
}

func BuildOrder added in v1.23.0

func BuildOrder(p OrderParams) (Order, error)

func GetNotifyFailedTradeOrders

func GetNotifyFailedTradeOrders() ([]Order, error)

func GetOrderByStatus added in v1.19.1

func GetOrderByStatus(Status int) []Order

func GetTradeOrder

func GetTradeOrder(tradeId string) (Order, bool)

func NewOrder added in v1.23.0

func NewOrder(p OrderParams, data Trade) (Order, error)

func RebuildOrder added in v1.23.0

func RebuildOrder(t Order, p OrderParams) (Order, error)

func (*Order) GetStatusEmoji added in v1.23.0

func (o *Order) GetStatusEmoji() string

func (*Order) GetStatusLabel added in v1.23.0

func (o *Order) GetStatusLabel() string

func (*Order) GetTxUrl added in v1.23.0

func (o *Order) GetTxUrl() string

func (*Order) MarkConfirming added in v1.23.0

func (o *Order) MarkConfirming(blockNum int64, from, hash string, at time.Time)

func (*Order) SetCanceled added in v1.23.0

func (o *Order) SetCanceled() error

func (*Order) SetExpired added in v1.23.0

func (o *Order) SetExpired()

func (*Order) SetFailed added in v1.23.0

func (o *Order) SetFailed()

func (*Order) SetNotifyState added in v1.23.0

func (o *Order) SetNotifyState(state int) error

func (*Order) SetSuccess added in v1.23.0

func (o *Order) SetSuccess()

func (*Order) TableName added in v1.23.0

func (o *Order) TableName() string

type OrderParams added in v1.23.0

type OrderParams struct {
	Money       decimal.Decimal `json:"money"`        // 交易金额 (单位:法币)s
	ApiType     string          `json:"api_type"`     // 支付 API 类型
	Address     string          `json:"address"`      // 收款地址
	OrderId     string          `json:"order_id"`     // 商户订单 ID
	TradeType   TradeType       `json:"trade_type"`   // 交易类型
	RedirectUrl string          `json:"redirect_url"` // 成功跳转地址
	NotifyUrl   string          `json:"notify_url"`   // 异步通知地址
	Name        string          `json:"name"`         // 商品名称
	Timeout     int64           `json:"timeout"`      // 订单超时时间(秒)
	Rate        string          `json:"rate"`         // 强制指定汇率
	Fiat        Fiat            `json:"fiat"`         // 法币类型
}

type Range added in v1.23.0

type Range struct {
	MinAmount decimal.Decimal
	MaxAmount decimal.Decimal
}

type Rate added in v1.23.0

type Rate struct {
	Id
	Rate    string  `gorm:"column:rate;type:varchar(32);not null;comment:订单汇率" json:"rate"`
	Fiat    string  `gorm:"column:fiat;type:varchar(16);not null;comment:法币" json:"fiat"`
	Crypto  string  `gorm:"column:crypto;type:varchar(16);not null;comment:加密货币" json:"crypto"`
	RawRate float64 `gorm:"column:raw_rate;type:decimal(10,4);not null;comment:基准汇率" json:"raw_rate"`
	Syntax  string  `gorm:"column:syntax;type:varchar(32);not null;default:'';comment:浮动语法" json:"syntax"`
	AutoTimeAt
}

func (*Rate) BeforeCreate added in v1.23.0

func (r *Rate) BeforeCreate(*gorm.DB) error

func (*Rate) TableName added in v1.23.0

func (r *Rate) TableName() string

type Trade added in v1.23.0

type Trade struct {
	Crypto  Crypto
	Rate    decimal.Decimal
	Address string
	Amount  string
}

func BuildTrade added in v1.23.0

func BuildTrade(p OrderParams) (Trade, error)

type TradeType added in v1.20.4

type TradeType string
const (
	OrderNotifyStateSucc = 1 // 回调成功
	OrderNotifyStateFail = 0 // 回调失败

	OrderStatusWaiting    = 1 // 等待支付
	OrderStatusSuccess    = 2 // 交易确认成功
	OrderStatusExpired    = 3 // 订单过期
	OrderStatusCanceled   = 4 // 订单取消
	OrderStatusConfirming = 5 // 等待交易确认
	OrderStatusFailed     = 6 // 交易确认失败

	BscBnb      TradeType = "bsc.bnb"
	EthereumEth TradeType = "ethereum.eth"
	TronTrx     TradeType = "tron.trx"

	UsdtTrc20    TradeType = "usdt.trc20"
	UsdcTrc20    TradeType = "usdc.trc20"
	UsdtPolygon  TradeType = "usdt.polygon"
	UsdcPolygon  TradeType = "usdc.polygon"
	UsdtArbitrum TradeType = "usdt.arbitrum"
	UsdcArbitrum TradeType = "usdc.arbitrum"
	UsdtErc20    TradeType = "usdt.erc20"
	UsdcErc20    TradeType = "usdc.erc20"
	UsdtBep20    TradeType = "usdt.bep20"
	UsdcBep20    TradeType = "usdc.bep20"
	UsdtXlayer   TradeType = "usdt.xlayer"
	UsdcXlayer   TradeType = "usdc.xlayer"
	UsdcBase     TradeType = "usdc.base"
	UsdtSolana   TradeType = "usdt.solana"
	UsdcSolana   TradeType = "usdc.solana"
	UsdtAptos    TradeType = "usdt.aptos"
	UsdcAptos    TradeType = "usdc.aptos"
	UsdtPlasma   TradeType = "usdt.plasma"
)

func GetContractTrade added in v1.23.0

func GetContractTrade(addr string) (TradeType, bool)

func GetNetworkTrades added in v1.23.0

func GetNetworkTrades(n Network) []TradeType

type TradeTypeConf added in v1.23.0

type TradeTypeConf struct {
	Alias        string  // 类型别名,主要用户前端展示
	Network      Network // 所属区块链网络
	Crypto       Crypto  // 币种类型
	Native       bool    // 是否原生币
	Contract     string  // 合约地址,原生币为空
	Decimal      int32   // 小数位
	AmountRange  Range   // 合法数额范围;这里特指则扫块时[数额范围],目前偷懒全部写死一个大概合理的范围,后面有问题再说...
	ExplorerFmt  string  // 区块浏览器交易链接格式化字符串,%s 位置替换为交易哈希
	EndpointKey  ConfKey // RPC 端点配置键
	AddrCaseSens bool    // 钱包地址是否大小写敏感,如果为 false 则会统一转为小写比较
}

type TronResource added in v1.23.0

type TronResource struct {
	ID           string
	Type         core.Transaction_Contract_ContractType
	Balance      int64
	FromAddress  string
	RecvAddress  string
	Timestamp    time.Time
	ResourceCode core.ResourceCode
}

type TronTransfer added in v1.23.0

type TronTransfer struct {
	Network     string
	TxHash      string
	Amount      decimal.Decimal
	FromAddress string
	RecvAddress string
	Timestamp   time.Time
	TradeType   TradeType
	BlockNum    int64
}

type Wallet added in v1.23.0

type Wallet struct {
	Id
	Name        string `gorm:"column:name;type:varchar(32);not null;default:-';comment:名称" json:"name"`
	Status      uint8  `gorm:"column:status;type:tinyint(1);not null;default:1;comment:地址状态" json:"status"`
	Address     string `gorm:"column:address;type:varchar(128);not null;index;comment:钱包地址" json:"address"`
	MatchAddr   string `gorm:"column:match_addr;type:varchar(128);not null;uniqueIndex:idx_address;comment:匹配地址" json:"match_addr"`
	TradeType   string `gorm:"column:trade_type;type:varchar(20);not null;uniqueIndex:idx_address;comment:交易类型" json:"trade_type"`
	OtherNotify uint8  `gorm:"column:other_notify;type:tinyint(1);not null;default:0;comment:其它通知" json:"other_notify"`
	Remark      string `gorm:"column:remark;type:varchar(255);not null;default:'';comment:备注" json:"remark"`
	AutoTimeAt
}

func (*Wallet) Delete added in v1.23.0

func (wa *Wallet) Delete()

func (*Wallet) GetNetwork added in v1.23.0

func (wa *Wallet) GetNetwork() Network

func (*Wallet) GetTokenContract added in v1.23.0

func (wa *Wallet) GetTokenContract() string

func (*Wallet) GetTokenDecimals added in v1.23.0

func (wa *Wallet) GetTokenDecimals() int32

func (*Wallet) IsValid added in v1.23.0

func (wa *Wallet) IsValid() bool

func (*Wallet) SetOtherNotify added in v1.23.0

func (wa *Wallet) SetOtherNotify(notify uint8)

func (*Wallet) SetStatus added in v1.23.0

func (wa *Wallet) SetStatus(status uint8)

func (*Wallet) TableName added in v1.23.0

func (wa *Wallet) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL