From 0bc37fc5cc61734635772072dfac39c9758ecbbf Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Sun, 11 Oct 2026 11:38:27 -0400 Subject: [PATCH] =?UTF-8?q?=E9=92=B1=E5=8C=85=E9=80=BB=E8=BE=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WalletAddressController.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WalletAddressController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WalletAddressController.java index 7e835e1..229007c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WalletAddressController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WalletAddressController.java @@ -18,10 +18,6 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.List; -import java.math.BigDecimal; -import org.tron.trident.core.ApiWrapper; -import com.ruoyi.system.service.ITronService; -import com.ruoyi.system.service.TronServiceProvider; import com.ruoyi.system.domain.vo.WalletOperationRequest; /** @@ -36,11 +32,12 @@ public class WalletAddressController extends BaseController { @Autowired private IWalletAddressService walletAddressService; @Autowired - private TronServiceProvider tronServiceProvider; - @Autowired private WalletSigningService walletSigningService; - /** 查询链上账户快照。私钥只从服务端读取,响应永远不包含 tokenKey。 */ + /** + * 同步刷新并返回完整链上账户快照。 + * 该操作只查询公开链上数据,不解密助记词,也不需要钱包私钥。 + */ @PreAuthorize("@ss.hasPermi('system:address:query') or @ss.hasPermi('system:address:user-query')") @GetMapping("/{id}/chain") public AjaxResult chain(@PathVariable("id") Long id) { @@ -51,20 +48,16 @@ public class WalletAddressController extends BaseController { if (!SecurityUtils.isAdmin(getUserId()) && !getUserId().equals(wallet.getUserId())) { return AjaxResult.error("无权访问该钱包"); } - ApiWrapper api = null; try { - ITronService tronService = tronServiceProvider.getCurrentService(); - api = tronService.buildApiWrapper(); - wallet.setTrxBalance(tronService.getTRxBalance(api, wallet.getToken())); - wallet.setUsdtBalance(tronService.getUsdtBalance(api, wallet.getToken())); - com.ruoyi.system.domain.vo.EnergyAndBandwidthVo resource = tronService.energyAndBandwidth(wallet.getToken()); - wallet.setEnergyNum(resource.getEnergy().max(BigDecimal.ZERO).longValue()); - wallet.setBandwidthNum(resource.getBandwidth().max(BigDecimal.ZERO).longValue()); - return AjaxResult.success(wallet); + if (!walletAddressService.updateTronInfo(wallet)) { + return AjaxResult.error("链上账户快照保存失败,请稍后重试"); + } + WalletAddressPlus refreshed = walletAddressService.getById(id); + return refreshed == null + ? AjaxResult.error("钱包刷新成功,但重新读取数据失败") + : AjaxResult.success(refreshed); } catch (Exception ex) { return AjaxResult.error("链上查询失败,请稍后重试"); - } finally { - if (api != null) api.close(); } }