topfans/backend/services/assetService/config/asset_config.go
2026-04-07 22:29:48 +08:00

95 lines
2.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
// AssetConfig 资产服务配置
type AssetConfig struct {
// MintConfig 铸造相关配置
MintConfig MintConfig
// BlockchainConfig 区块链相关配置(目前模拟)
BlockchainConfig BlockchainConfig
}
// MintConfig 铸造相关配置
type MintConfig struct {
// MintFee 铸造费用(水晶数量)
MintFee int64
// MaxRetryCount 最大重试次数
MaxRetryCount int32
// MintSimulationDelaySeconds 模拟上链延迟(秒)
// 用于模拟异步上链过程
MintSimulationDelaySeconds int
}
// BlockchainConfig 区块链相关配置(目前模拟)
type BlockchainConfig struct {
// Enabled 是否启用区块链功能
// 目前为false只做模拟
Enabled bool
// NetworkID 网络ID预留
NetworkID string
// ContractAddress 合约地址(预留)
ContractAddress string
}
// GlobalAssetConfig 全局资产配置实例
var GlobalAssetConfig = &AssetConfig{
MintConfig: MintConfig{
MintFee: 100, // 100水晶
MaxRetryCount: 3, // 最多重试3次
MintSimulationDelaySeconds: 3, // 模拟3秒上链延迟
},
BlockchainConfig: BlockchainConfig{
Enabled: false, // 暂不启用区块链
NetworkID: "", // 预留
ContractAddress: "", // 预留
},
}
// ========== 铸造相关辅助方法 ==========
// GetMintFee 获取铸造费用
func (c *AssetConfig) GetMintFee() int64 {
return c.MintConfig.MintFee
}
// GetMaxRetryCount 获取最大重试次数
func (c *AssetConfig) GetMaxRetryCount() int32 {
return c.MintConfig.MaxRetryCount
}
// GetMintSimulationDelaySeconds 获取模拟上链延迟(秒)
func (c *AssetConfig) GetMintSimulationDelaySeconds() int {
return c.MintConfig.MintSimulationDelaySeconds
}
// ========== 区块链相关辅助方法 ==========
// IsBlockchainEnabled 检查是否启用区块链功能
func (c *AssetConfig) IsBlockchainEnabled() bool {
return c.BlockchainConfig.Enabled
}
// ========== 配置更新方法(预留) ==========
// UpdateMintFee 更新铸造费用
// 注意:后续可以从规则表或配置中心读取配置并调用此方法更新
func (c *AssetConfig) UpdateMintFee(fee int64) {
c.MintConfig.MintFee = fee
}
// UpdateMaxRetryCount 更新最大重试次数
func (c *AssetConfig) UpdateMaxRetryCount(count int32) {
c.MintConfig.MaxRetryCount = count
}
// UpdateBlockchainConfig 更新区块链配置
func (c *AssetConfig) UpdateBlockchainConfig(enabled bool, networkID, contractAddress string) {
c.BlockchainConfig.Enabled = enabled
c.BlockchainConfig.NetworkID = networkID
c.BlockchainConfig.ContractAddress = contractAddress
}