From d32514b46ec0a90f0f3d2297d1ff5cb5dcdeb7f1 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 22 Apr 2021 10:50:14 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java | 46 ++++++++++++++++++++++++++++++++++------------
1 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java b/src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java
index d1cd4b1..1324df6 100644
--- a/src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java
+++ b/src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java
@@ -9,6 +9,7 @@
import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity;
import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer;
import com.xcong.excoin.utils.RedisUtils;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpEntity;
@@ -28,6 +29,7 @@
/**
* TRX TRC20服务类
*/
+@Slf4j
@Service
public class TrxUsdtUpdateService {
@@ -69,13 +71,16 @@
}
Long blockNum = Long.valueOf(trc20BlockNum.toString());
- redisUtils.set("USDT_TRC20_BLOCK_NUM",blockNum);
+// log.info("---{}",blockNum);
// 查询一下最新区块
long getnowblock = getnowblock()-20L;
+// log.info("--->{}, {}", blockNum, System.currentTimeMillis());
if(getnowblock<blockNum){
// 如果当前区块比最新已确认区块还大,则不继续执行
return;
}
+
+ redisUtils.set("USDT_TRC20_BLOCK_NUM",blockNum + 1L);
if (CollectionUtils.isEmpty(addressList)) {
return;
}
@@ -92,23 +97,26 @@
* @param num
*/
private void httpTransactionInfo(List<String> addressList, Long num) {
- String transactionInfoByBlockNum = getTransactionInfoByBlockNum(BigInteger.valueOf(num));
+ // 查询详情,包含了所有交易信息
+ String transactionInfoByBlockNum = getblockbynum(BigInteger.valueOf(num));
if (StringUtils.isBlank(transactionInfoByBlockNum)) {
return;
}
+// log.info("--->{}, {}", num, System.currentTimeMillis());
// 不用等到扫完再累加 只要进来就加 还有一个条件是必须查询出区块再加 否则当区块超过实际区块
- redisUtils.set("USDT_TRC20_BLOCK_NUM", (num + 1L));
- JSONArray parseArray = JSON.parseArray(transactionInfoByBlockNum);
- if (parseArray.size() > 0) {
+// redisUtils.set("USDT_TRC20_BLOCK_NUM", (num + 1L));
+ JSONArray parseArray = JSON.parseObject(transactionInfoByBlockNum).getJSONArray("transactions");
+ if (parseArray != null && parseArray.size() > 0) {
for (Object e : parseArray) {
try {
- String txId = JSON.parseObject(e.toString()).getString("id");
- String contract_address = JSON.parseObject(e.toString()).getString("contract_address");
- if(!"41a614f803b6fd780986a42c78ec9c7f77e6ded13c".equals(contract_address)){
- continue;
- }
+// String txId = JSON.parseObject(e.toString()).getString("id");
+// String contract_address = JSON.parseObject(e.toString()).getString("contract_address");
+// if(!"41a614f803b6fd780986a42c78ec9c7f77e6ded13c".equals(contract_address)){
+// continue;
+// }
//判断 数据库 txId 有 就不用往下继续了
- JSONObject parseObject = JSON.parseObject(getTransactionById(txId));
+ JSONObject parseObject = JSON.parseObject(e.toString());
+ String txId = parseObject.getString("txID");
String contractRet = parseObject.getJSONArray("ret").getJSONObject(0).getString("contractRet");
//交易成功
if ("SUCCESS".equals(contractRet)) {
@@ -119,7 +127,7 @@
} else if ("TransferContract".equals(type)) {
//trx 转账
- transferContract(parseObject);
+ //transferContract(parseObject);
}
}
} catch (Exception exception) {
@@ -164,6 +172,20 @@
return postForEntity(url, param).getBody();
}
+ /**
+ * 获取特定区块的所有交易 Info 信息
+ *
+ * @param num 区块
+ * @return
+ */
+ public static String getblockbynum(BigInteger num) {
+ String url = http + "/wallet/getblockbynum";
+ Map<String, Object> map = new HashMap<>();
+ map.put("num", num);
+ String param = JSON.toJSONString(map);
+ return postForEntity(url, param).getBody();
+ }
+
/**
* https://cn.developers.tron.network/docs/%E4%BA%A4%E6%98%9311#%E4%BA%A4%E6%98%93%E7%A1%AE%E8%AE%A4%E6%96%B9%E6%B3%95
--
Gitblit v1.9.1