全局usdt,trx账户
This commit is contained in:
1 parent
15a80de8a6
commit
2602897c23
5 files changed
+146
-1
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package com.ruoyi.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.UsdtConfigPlus;
|
||||
import com.ruoyi.system.mapper.UsdtConfigMapper;
|
||||
import com.ruoyi.system.service.ITronService;
|
||||
import com.ruoyi.system.service.TronServiceProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 定时刷新全局配置中主钱包的链上余额缓存。
|
||||
*
|
||||
* <p>任务只读取公开地址,不解密助记词或私钥;单次查询使用同一个 TRON 客户端,
|
||||
* 并通过专用 SQL 只更新余额字段,避免覆盖并发修改的其他全局配置。</p>
|
||||
*/
|
||||
@Component
|
||||
public class UsdtConfigBalanceRefreshTask {
|
||||
private static final Logger log = LoggerFactory.getLogger(UsdtConfigBalanceRefreshTask.class);
|
||||
|
||||
@Autowired
|
||||
private UsdtConfigMapper usdtConfigMapper;
|
||||
@Autowired
|
||||
private TronServiceProvider tronServiceProvider;
|
||||
|
||||
/** 默认每 30 秒刷新一次,完成上一轮后再计算间隔,防止慢查询堆积。 */
|
||||
@Scheduled(fixedDelayString = "${payment.usdt-config-balance.refresh-delay-ms:30000}")
|
||||
public void refresh() {
|
||||
UsdtConfigPlus config = usdtConfigMapper.selectOne(new LambdaQueryWrapper<UsdtConfigPlus>()
|
||||
.select(UsdtConfigPlus::getId, UsdtConfigPlus::getTokenAddress)
|
||||
.orderByAsc(UsdtConfigPlus::getId)
|
||||
.last("limit 1"));
|
||||
if (config == null || StringUtils.isBlank(config.getTokenAddress())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ApiWrapper api = null;
|
||||
try {
|
||||
ITronService tronService = tronServiceProvider.getCurrentService();
|
||||
api = tronService.buildApiWrapper();
|
||||
BigDecimal usdtBalance = tronService.getUsdtBalance(api, config.getTokenAddress());
|
||||
BigDecimal trxBalance = tronService.getTRxBalance(api, config.getTokenAddress());
|
||||
int updated = usdtConfigMapper.updateMainWalletBalances(
|
||||
config.getId(), usdtBalance, trxBalance);
|
||||
if (updated != 1) {
|
||||
log.warn("主钱包余额刷新未更新到全局配置,配置ID={}", config.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 地址属于公开信息,但仍不在错误日志中输出,以保持任务日志简洁并避免带出节点响应细节。
|
||||
log.warn("主钱包余额刷新失败,配置ID={},原因={}", config.getId(), e.getMessage());
|
||||
} finally {
|
||||
if (api != null) {
|
||||
api.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user