| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.tron.common.utils.ByteArray; |
| | | import org.tron.trident.core.ApiWrapper; |
| | | import org.tron.trident.core.contract.Contract; |
| | | import org.tron.trident.core.contract.Trc20Contract; |
| | | import org.tron.walletserver.WalletApi; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | public class TrxUsdtUpdateService { |
| | | |
| | | public static List<String> addressList = new ArrayList<>(); |
| | | private static String http = "https://api.trongrid.io"; |
| | | private static String http = "https://api.shasta.trongrid.io"; |
| | | |
| | | private static String TRC20_CONTRACT_ADDRESS = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; |
| | | |
| | | /** |
| | | * 代币合约地址 |
| | | */ |
| | | public static String COIN_CONTRACT_ADDRESS = "TRTE68V3TJBLduBoJPLMgBsvwkq8LJBin6"; |
| | | /** |
| | | * 手续费 |
| | | */ |
| | |
| | | * @param addressList |
| | | * @param num |
| | | */ |
| | | private void httpTransactionInfo(List<String> addressList, Long num) { |
| | | public void httpTransactionInfo(List<String> addressList, Long num) { |
| | | // 查询详情,包含了所有交易信息 |
| | | String transactionInfoByBlockNum = getblockbynum(BigInteger.valueOf(num)); |
| | | if (StringUtils.isBlank(transactionInfoByBlockNum)) { |
| | |
| | | } |
| | | |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | //相匹配的合约地址 |
| | | if (!TRC20_CONTRACT_ADDRESS.equals(contract_address)) { |
| | | // 相匹配的合约地址 USDT合约地址和代币合约地址 |
| | | if (!TRC20_CONTRACT_ADDRESS.equals(contract_address) && !COIN_CONTRACT_ADDRESS.equals(contract_address)) { |
| | | return; |
| | | } |
| | | |
| | |
| | | // 金额 |
| | | // 发送消息队列 |
| | | EthUsdtChargeDto dto = new EthUsdtChargeDto(address, txId, amount); |
| | | dto.setSymbol(EthUsdtChargeDto.Symbol.USDT_TRC20); |
| | | if (TRC20_CONTRACT_ADDRESS.equals(contract_address)) { |
| | | dto.setSymbol(EthUsdtChargeDto.Symbol.USDT_TRC20); |
| | | } else { |
| | | dto.setSymbol(EthUsdtChargeDto.Symbol.COIN_TRC20); |
| | | } |
| | | usdtUpdateProducer.sendMsg(JSONObject.toJSONString(dto)); |
| | | log.info("===to_address:" + to_address + "===amount:" + amount); |
| | | } |
| | |
| | | return false; |
| | | } |
| | | if (trxBalance.compareTo(TRX_FEE) >= 0) { |
| | | // 转 |
| | | BigDecimal trc20Balance = Trc20Service.getTrc20Balance(address); |
| | | if (trc20Balance == null) { |
| | | |
| | | boolean usdtResult = poolUsdt(address); |
| | | boolean coinResult = poolCoin(address); |
| | | if (usdtResult && coinResult) { |
| | | return false; |
| | | } |
| | | MemberCoinAddressEntity coinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(address, "USDT", "TRC20"); |
| | | if (coinAddressEntity == null) { |
| | | return false; |
| | | } |
| | | Trc20Service.sendTrc20(coinAddressEntity.getPrivateKey(), Trc20Service.POOL_ADDRESS, trc20Balance); |
| | | |
| | | // 需要将存在redis的待归集地址删除 |
| | | Object trc20_pool = redisUtils.get("TRC20_POOL"); |
| | | if (trc20_pool != null) { |
| | |
| | | } |
| | | } |
| | | |
| | | // https://api.trongrid.io/wallet/getnowblock |
| | | public boolean poolUsdt(String address) { |
| | | // 转 |
| | | BigDecimal trc20Balance = Trc20Service.getTrc20Balance(address); |
| | | if (trc20Balance == null) { |
| | | return false; |
| | | } |
| | | MemberCoinAddressEntity coinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(address, "USDT", "TRC20"); |
| | | if (coinAddressEntity == null) { |
| | | return false; |
| | | } |
| | | Trc20Service.sendTrc20(coinAddressEntity.getPrivateKey(), Trc20Service.POOL_ADDRESS, trc20Balance); |
| | | return true; |
| | | } |
| | | |
| | | public boolean poolCoin(String address) { |
| | | MemberCoinAddressEntity coinAddress = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, CoinTypeEnum.XCT.name()); |
| | | if (coinAddress == null) { |
| | | return false; |
| | | } |
| | | |
| | | Trc20Contract token = contractToken(coinAddress.getAddress(), coinAddress.getPrivateKey()); |
| | | BigInteger balance = token.balanceOf(address); |
| | | if (balance == null || balance.compareTo(BigInteger.ZERO) == 0) { |
| | | return false; |
| | | } |
| | | |
| | | token.transfer(Trc20Service.POOL_ADDRESS, balance.longValue(), 0, "memo", 100000000L); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 获取最新区块 |
| | | * https://api.trongrid.io/wallet/getnowblock |
| | | * |
| | | * @return |
| | | */ |
| | |
| | | String wholeBlockCount = JSON.parseObject(forObject).getString("whole_block_count"); |
| | | return Long.valueOf(wholeBlockCount); |
| | | } |
| | | |
| | | /** |
| | | * 获取对应代币合约token |
| | | * |
| | | * @param address 地址 |
| | | * @param privateKey 密钥 |
| | | * @return |
| | | */ |
| | | public Trc20Contract contractToken(String address, String privateKey) { |
| | | ApiWrapper wrapper = ApiWrapper.ofMainnet(privateKey, Trc20Service.API_KEY); |
| | | Contract trc20Contract = wrapper.getContract(COIN_CONTRACT_ADDRESS); |
| | | return new Trc20Contract(trc20Contract, address, wrapper); |
| | | } |
| | | } |