钱包逻辑调整
This commit is contained in:
1 parent
5530885c79
commit
0bc37fc5cc
1 file changed
+11
-18
+11
-18
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user