Documentation
¶
Index ¶
- Constants
- Variables
- func AddrCaseSens(t TradeType) bool
- func AuthToken() string
- func AutoMigrate() error
- func CalcTradeAmount(address []string, rate, money decimal.Decimal, t TradeType) (string, string, error)
- func CalcTradeExpiredAt(sec int64) time.Time
- func CheckoutCounter(host, id string) string
- func Close()
- func CoingeckoRate() error
- func ConfInit()
- func Endpoint(net Network) string
- func GetAllAlias() map[string]string
- func GetAtomicity(t TradeType) (decimal.Decimal, int32)
- func GetAvailableAddress(t TradeType) []string
- func GetC(k ConfKey) string
- func GetContractDecimal(addr string) int32
- func GetInstallInfo() gin.H
- func GetK(k ConfKey) string
- func GetSupportCrypto() map[Crypto]CoinId
- func GetSupportFiat() map[Fiat]struct{}
- func GetTradeDecimal(t TradeType) int32
- func GetTxUrl(t TradeType, hash string) string
- func GetVs(keys []ConfKey) map[ConfKey]string
- func Init(path, dsn string) error
- func InstallLock()
- func IsAmountValid(t TradeType, d decimal.Decimal) bool
- func IsInstalled() bool
- func IsNeedNotifyByTxid(txid string) bool
- func IsSupportedTradeType(t TradeType) bool
- func ParseFloatRate(syntax string, rawVal float64) float64
- func RefreshC()
- func SetK(k ConfKey, v string)
- type AutoTimeAt
- type CoinId
- type Conf
- type ConfKey
- type Crypto
- type Datetime
- func (d *Datetime) Before(u time.Time) bool
- func (d *Datetime) Format(layout string) string
- func (d *Datetime) MarshalJSON() ([]byte, error)
- func (d *Datetime) Scan(v interface{}) error
- func (d *Datetime) String() string
- func (d *Datetime) Time() time.Time
- func (d Datetime) Value() (driver.Value, error)
- func (d *Datetime) Year() string
- type Fiat
- type Id
- type MatchMode
- type Network
- type NotifyRecord
- type Order
- func BuildOrder(p OrderParams) (Order, error)
- func GetNotifyFailedTradeOrders() ([]Order, error)
- func GetOrderByStatus(Status int) []Order
- func GetTradeOrder(tradeId string) (Order, bool)
- func NewOrder(p OrderParams, data Trade) (Order, error)
- func RebuildOrder(t Order, p OrderParams) (Order, error)
- func (o *Order) GetStatusEmoji() string
- func (o *Order) GetStatusLabel() string
- func (o *Order) GetTxUrl() string
- func (o *Order) MarkConfirming(blockNum int64, from, hash string, at time.Time)
- func (o *Order) SetCanceled() error
- func (o *Order) SetExpired()
- func (o *Order) SetFailed()
- func (o *Order) SetNotifyState(state int) error
- func (o *Order) SetSuccess()
- func (o *Order) TableName() string
- type OrderParams
- type Range
- type Rate
- type Trade
- type TradeType
- type TradeTypeConf
- type TronResource
- type TronTransfer
- type Wallet
- func (wa *Wallet) Delete()
- func (wa *Wallet) GetNetwork() Network
- func (wa *Wallet) GetTokenContract() string
- func (wa *Wallet) GetTokenDecimals() int32
- func (wa *Wallet) IsValid() bool
- func (wa *Wallet) SetOtherNotify(notify uint8)
- func (wa *Wallet) SetStatus(status uint8)
- func (wa *Wallet) TableName() string
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 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
CalcTradeExpiredAt 计算订单过期时间 最小180,最大3600,默认1200
func CheckoutCounter ¶ added in v1.23.0
func CoingeckoRate ¶ added in v1.23.0
func CoingeckoRate() error
func GetAllAlias ¶ added in v1.23.0
func GetAvailableAddress ¶
func GetContractDecimal ¶ added in v1.23.0
func GetInstallInfo ¶ added in v1.23.0
func GetSupportCrypto ¶ added in v1.23.0
func GetSupportFiat ¶ added in v1.23.0
func GetSupportFiat() map[Fiat]struct{}
func GetTradeDecimal ¶ added in v1.23.0
func InstallLock ¶ added in v1.23.0
func InstallLock()
func IsInstalled ¶ added in v1.23.0
func IsInstalled() bool
func IsNeedNotifyByTxid ¶
func IsSupportedTradeType ¶ added in v1.23.0
func ParseFloatRate ¶ added in v1.23.0
Types ¶
type AutoTimeAt ¶ added in v1.23.0
type Conf ¶ added in v1.23.0
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
type Datetime ¶ added in v1.23.0
func (*Datetime) MarshalJSON ¶ added in v1.23.0
type Id ¶ added in v1.23.0
type Id struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;not null;comment:主键ID" json:"id"`
}
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 GetOrderByStatus ¶ added in v1.19.1
func GetTradeOrder ¶
func RebuildOrder ¶ added in v1.23.0
func RebuildOrder(t Order, p OrderParams) (Order, error)
func (*Order) GetStatusEmoji ¶ added in v1.23.0
func (*Order) GetStatusLabel ¶ added in v1.23.0
func (*Order) MarkConfirming ¶ added in v1.23.0
func (*Order) SetCanceled ¶ added in v1.23.0
func (*Order) SetExpired ¶ added in v1.23.0
func (o *Order) SetExpired()
func (*Order) SetNotifyState ¶ added in v1.23.0
func (*Order) SetSuccess ¶ added in v1.23.0
func (o *Order) SetSuccess()
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 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
}
type Trade ¶ added in v1.23.0
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 GetNetworkTrades ¶ added in v1.23.0
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 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) GetNetwork ¶ added in v1.23.0
func (*Wallet) GetTokenContract ¶ added in v1.23.0
func (*Wallet) GetTokenDecimals ¶ added in v1.23.0
func (*Wallet) SetOtherNotify ¶ added in v1.23.0
Click to show internal directories.
Click to hide internal directories.