新增tron加密逻辑
This commit is contained in:
1 parent
009955d560
commit
00a4a08c70
18 files changed
+1071
-55
No files matched your search
@@ -14,6 +14,9 @@ public interface ITronService {
|
||||
String type();
|
||||
ApiWrapper buildApiWrapper(String privateKey);
|
||||
|
||||
ApiWrapper buildApiWrapper();
|
||||
|
||||
|
||||
String contractAddress();
|
||||
|
||||
String tronscanApiUrl();
|
||||
|
||||
@@ -84,6 +84,12 @@ public class TronNileServiceImpl implements ITronService {
|
||||
return apiWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiWrapper buildApiWrapper() {
|
||||
ApiWrapper apiWrapper = ApiWrapper.ofNile(null);
|
||||
return apiWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String contractAddress() {
|
||||
return "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf";
|
||||
|
||||
@@ -11,15 +11,20 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
|
||||
/** 轮询已确认 TRC20 转账,按地址、六位金额和唯一交易哈希入账。 */
|
||||
/**
|
||||
* 轮询已确认 TRC20 转账,按地址、六位金额和唯一交易哈希入账。
|
||||
*/
|
||||
@Component
|
||||
public class TronPaymentScanner {
|
||||
@Autowired private IUsdtOrdersService orders;
|
||||
@Autowired private ITronService tron;
|
||||
@Autowired
|
||||
private IUsdtOrdersService orders;
|
||||
@Autowired
|
||||
private ITronService tron;
|
||||
private final RestTemplate http = new RestTemplate();
|
||||
|
||||
@Scheduled(fixedDelay = 30000L)
|
||||
@@ -28,18 +33,26 @@ public class TronPaymentScanner {
|
||||
if (order.getToken() == null || order.getActualAmount() == null) continue;
|
||||
try {
|
||||
String url = tron.tronscanApiUrl() + "/v1/accounts/" + order.getToken() + "/transactions/trc20?limit=200&only_confirmed=true&contract_address=" + tron.contractAddress();
|
||||
JSONObject root = JSON.parseObject(http.getForObject(url, String.class)); JSONArray data = root == null ? null : root.getJSONArray("data");
|
||||
JSONObject root = JSON.parseObject(http.getForObject(url, String.class));
|
||||
JSONArray data = root == null ? null : root.getJSONArray("data");
|
||||
if (data == null) continue;
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject tx = data.getJSONObject(i);
|
||||
if (!order.getToken().equals(tx.getString("to"))) continue;
|
||||
BigDecimal value = new BigDecimal(tx.getString("value")).movePointLeft(6).setScale(6, RoundingMode.DOWN);
|
||||
if (value.compareTo(order.getActualAmount().setScale(6, RoundingMode.DOWN)) != 0) continue;
|
||||
String hash = tx.getString("transaction_id"); if (hash == null || hash.trim().isEmpty()) continue;
|
||||
if (orders.count(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getBlockTransactionId, hash)) > 0) continue;
|
||||
order.setBlockTransactionId(hash); order.setStatus(2L); order.setUpdatedAt(new Date()); orders.updateById(order); break;
|
||||
String hash = tx.getString("transaction_id");
|
||||
if (hash == null || hash.trim().isEmpty()) continue;
|
||||
if (orders.count(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getBlockTransactionId, hash)) > 0)
|
||||
continue;
|
||||
order.setBlockTransactionId(hash);
|
||||
order.setStatus(2L);
|
||||
order.setUpdatedAt(new Date());
|
||||
orders.updateById(order);
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,11 @@ public class TronProServiceImpl implements ITronService {
|
||||
return ApiWrapper.ofMainnet(privateKey, "719b2ba2-dedd-48ad-99a6-df1caa6f08ae");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiWrapper buildApiWrapper() {
|
||||
return ApiWrapper.ofMainnet(null, "719b2ba2-dedd-48ad-99a6-df1caa6f08ae");
|
||||
}
|
||||
|
||||
private static byte[] keccak256(byte[] input) {
|
||||
Keccak.Digest256 digest = new Keccak.Digest256();
|
||||
return digest.digest(input);
|
||||
|
||||
@@ -167,6 +167,12 @@ public class TronShastaServiceImpl implements ITronService {
|
||||
return apiWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiWrapper buildApiWrapper() {
|
||||
ApiWrapper apiWrapper = ApiWrapper.ofShasta(null);
|
||||
return apiWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String contractAddress() {
|
||||
return "TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs";
|
||||
|
||||
+1
-2
@@ -35,12 +35,11 @@ public class UsdtAggregationExecutor {
|
||||
boolean failed = false;
|
||||
for (UsdtAggregationTaskItemPlus item : items) {
|
||||
WalletAddressPlus wallet = walletService.getByTokenAndAppId(item.getTokenAddress(), item.getAppId());
|
||||
if (wallet == null || wallet.getTokenKey() == null) { fail(item, "来源钱包不存在或未配置私钥"); failed = true; continue; }
|
||||
String tx = null;
|
||||
Exception last = null;
|
||||
for (int attempt = 0; attempt < 4 && tx == null; attempt++) {
|
||||
org.tron.trident.core.ApiWrapper api = null;
|
||||
try { api = tronService.buildApiWrapper(wallet.getTokenKey()); tx = tronService.usdtTrans(api, wallet.getToken(), item.getDistTokenAddress(), item.getOpeAmount().toPlainString()); }
|
||||
try { api = tronService.buildApiWrapper(); tx = tronService.usdtTrans(api, wallet.getToken(), item.getDistTokenAddress(), item.getOpeAmount().toPlainString()); }
|
||||
catch (Exception ex) { last = ex; }
|
||||
finally { if (api != null) api.close(); }
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ public class WalletAddressServiceImpl extends ServiceImpl<WalletAddressMapper, W
|
||||
|
||||
@Override
|
||||
public boolean updateTronInfo(WalletAddressPlus walletAddressPlus) {
|
||||
ApiWrapper api = tronService.buildApiWrapper(walletAddressPlus.getTokenKey());
|
||||
ApiWrapper api = tronService.buildApiWrapper();
|
||||
BigDecimal amout = tronService.getUsdtBalance(api,walletAddressPlus.getToken());
|
||||
walletAddressPlus.setUsdtBalance(amout);
|
||||
amout = tronService.getTRxBalance(api,walletAddressPlus.getToken());
|
||||
|
||||
Reference in new issue
Block a user