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