diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/TronChainDataClient.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/TronChainDataClient.java index ad31d4e..2efb7ec 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/TronChainDataClient.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/TronChainDataClient.java @@ -9,11 +9,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -24,13 +20,7 @@ import org.springframework.web.util.UriComponentsBuilder; import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * TRON HTTP 链上数据统一入口。 @@ -49,7 +39,9 @@ public class TronChainDataClient { private final String apiKey; private String tronscanApiKey = "47fae50b-b5e8-4d1b-8329-501a422a3169"; - /** TronScan 与 TronGrid 是不同平台,凭证必须分别配置,禁止跨平台发送。 */ + /** + * TronScan 与 TronGrid 是不同平台,凭证必须分别配置,禁止跨平台发送。 + */ @Value("${tron.chain-data.tronscan-api-key:}") public void setTronscanApiKey(String key) { this.tronscanApiKey = key == null ? "" : key.trim(); @@ -70,21 +62,23 @@ public class TronChainDataClient { } TronChainDataClient(RestTemplate restTemplate, Map> transactionEndpoints, - Map> accountEndpoints, String apiKey) { + Map> accountEndpoints, String apiKey) { this.restTemplate = restTemplate; this.transactionEndpoints = transactionEndpoints; this.accountEndpoints = accountEndpoints; this.apiKey = apiKey == null ? "" : apiKey.trim(); } - /** 查询已确认的 TRC20 交易,返回结构与 TronGrid v1 的 data 数组保持一致。 */ + /** + * 查询已确认的 TRC20 交易,返回结构与 TronGrid v1 的 data 数组保持一致。 + */ public JSONArray queryConfirmedTrc20Transactions(ITronService tronService, String address, int limit) { return queryConfirmedTrc20Transactions(tronService.type(), address, tronService.contractAddress(), tronService.tronscanApiKey(), limit); } JSONArray queryConfirmedTrc20Transactions(String network, String address, String contractAddress, - String serviceApiKey, int limit) { + String serviceApiKey, int limit) { List endpoints = endpoints(transactionEndpoints, network); RuntimeException lastFailure = null; for (String endpoint : endpoints) { @@ -128,13 +122,13 @@ public class TronChainDataClient { * 使用 Trident/gRPC 查询余额、质押本金和代理关系明细。 */ public EnergyAndBandwidthVo queryDelegatedResourceSummary(ITronService tronService, - String address) { + String address) { return queryDelegatedResourceSummary(tronService.type(), address, tronService.tronscanApiKey()); } EnergyAndBandwidthVo queryDelegatedResourceSummary(String network, String address, - String serviceApiKey) { + String serviceApiKey) { for (String endpoint : endpoints(accountEndpoints, network)) { try { URI uri = UriComponentsBuilder.fromHttpUrl(endpoint) @@ -155,7 +149,9 @@ public class TronChainDataClient { return emptyDelegatedResourceSummary(); } - /** 提供给 Trident 主网客户端使用,配置值禁止写入日志。 */ + /** + * 提供给 Trident 主网客户端使用,配置值禁止写入日志。 + */ public String getApiKey() { return apiKey; } @@ -183,7 +179,9 @@ public class TronChainDataClient { } } - /** 自定义代理地址可通过 tronscan|URL 显式指定协议,普通历史配置按域名识别。 */ + /** + * 自定义代理地址可通过 tronscan|URL 显式指定协议,普通历史配置按域名识别。 + */ private boolean isTronscan(String endpoint) { if (endpoint.startsWith("tronscan|")) return true; if (endpoint.startsWith("trongrid|")) return false; @@ -192,7 +190,9 @@ public class TronChainDataClient { || host.endsWith(".tronscanapi.com")); } - /** 只接受已确认、执行成功且合约匹配的转账,金额保留原始最小单位字符串。 */ + /** + * 只接受已确认、执行成功且合约匹配的转账,金额保留原始最小单位字符串。 + */ private JSONArray normalizeTronscanTransfers(JSONObject body, String contract) { JSONArray transfers = body.getJSONArray("token_transfers"); if (transfers == null) throw new IllegalStateException("响应缺少 token_transfers 数组");