钱包逻辑调整

This commit is contained in:
lu7213 committed 2026-10-11 11:38:27 -04:00
1 parent 5530885c79
commit 0bc37fc5cc
1 file changed
+11 -18
@@ -18,10 +18,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; 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; import com.ruoyi.system.domain.vo.WalletOperationRequest;
/** /**
@@ -36,11 +32,12 @@ public class WalletAddressController extends BaseController {
@Autowired @Autowired
private IWalletAddressService walletAddressService; private IWalletAddressService walletAddressService;
@Autowired @Autowired
private TronServiceProvider tronServiceProvider;
@Autowired
private WalletSigningService walletSigningService; private WalletSigningService walletSigningService;
/** 查询链上账户快照。私钥只从服务端读取,响应永远不包含 tokenKey。 */ /**
* 同步刷新并返回完整链上账户快照。
* 该操作只查询公开链上数据,不解密助记词,也不需要钱包私钥。
*/
@PreAuthorize("@ss.hasPermi('system:address:query') or @ss.hasPermi('system:address:user-query')") @PreAuthorize("@ss.hasPermi('system:address:query') or @ss.hasPermi('system:address:user-query')")
@GetMapping("/{id}/chain") @GetMapping("/{id}/chain")
public AjaxResult chain(@PathVariable("id") Long id) { public AjaxResult chain(@PathVariable("id") Long id) {
@@ -51,20 +48,16 @@ public class WalletAddressController extends BaseController {
if (!SecurityUtils.isAdmin(getUserId()) && !getUserId().equals(wallet.getUserId())) { if (!SecurityUtils.isAdmin(getUserId()) && !getUserId().equals(wallet.getUserId())) {
return AjaxResult.error("无权访问该钱包"); return AjaxResult.error("无权访问该钱包");
} }
ApiWrapper api = null;
try { try {
ITronService tronService = tronServiceProvider.getCurrentService(); if (!walletAddressService.updateTronInfo(wallet)) {
api = tronService.buildApiWrapper(); return AjaxResult.error("链上账户快照保存失败,请稍后重试");
wallet.setTrxBalance(tronService.getTRxBalance(api, wallet.getToken())); }
wallet.setUsdtBalance(tronService.getUsdtBalance(api, wallet.getToken())); WalletAddressPlus refreshed = walletAddressService.getById(id);
com.ruoyi.system.domain.vo.EnergyAndBandwidthVo resource = tronService.energyAndBandwidth(wallet.getToken()); return refreshed == null
wallet.setEnergyNum(resource.getEnergy().max(BigDecimal.ZERO).longValue()); ? AjaxResult.error("钱包刷新成功,但重新读取数据失败")
wallet.setBandwidthNum(resource.getBandwidth().max(BigDecimal.ZERO).longValue()); : AjaxResult.success(refreshed);
return AjaxResult.success(wallet);
} catch (Exception ex) { } catch (Exception ex) {
return AjaxResult.error("链上查询失败,请稍后重试"); return AjaxResult.error("链上查询失败,请稍后重试");
} finally {
if (api != null) api.close();
} }
} }