From 869769dedf8722109c944db9a5d9fac97591c2d3 Mon Sep 17 00:00:00 2001 From: zainali5120 <512061637@qq.com> Date: Sat, 16 Jan 2021 14:41:57 +0800 Subject: [PATCH] TRC20版本提交 --- src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java | 71 ++++++++++++----------------------- 1 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java b/src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java index 82ddfdf..f8595e8 100644 --- a/src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java +++ b/src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; import java.util.concurrent.ExecutionException; @@ -29,18 +30,18 @@ @Component public class UsdtEthService { - private static final String ETH_GAS_PRICE="ETH_GAS_PRICE"; + private static final String ETH_GAS_PRICE = "ETH_GAS_PRICE"; private static BigDecimal ETH_GAS_LIMIT = new BigDecimal(60000); - private static final BigDecimal LIMIT = new BigDecimal("50"); + private static final BigDecimal LIMIT = new BigDecimal("10"); private static final BigDecimal LIMIT_ETH = new BigDecimal("0.2"); - private static BigDecimal FEE = new BigDecimal("0.0042"); + private static BigDecimal FEE = new BigDecimal("0.0042"); private static final BigDecimal ETH_TR_FEE = new BigDecimal("0.0032"); public static String ETH_FEE = "0.0042"; - public static final String TOTAL_ADDRESS = "0x3d83A28B6C2d599d2B6D272c5DBcDC9c976d344F"; - public static final String TOTAL_PRIVATE = "4a1ce332133d8917360c5f3b194f703a0cf5b86c4eea319b1cd01197e68dad27"; - + public static final String TOTAL_ADDRESS = "0x0e9f7eEfa4Dd804dDAE2972A7195Ea1fE04d2253"; + public static final String TOTAL_PRIVATE = "2b9cb76dd75dddc8ab4c4614f4c66b53604da49672586a026b253fae873bd017"; + public static final String POOL_ADDRESS = "0x1A37e4B839E5b691a835ff5fCf7c7A760003155D"; @Resource private MemberCoinChargeDao memberCoinChargeDao; @Resource @@ -52,32 +53,27 @@ RedisUtils redisUtils; - public void pool() throws ExecutionException, InterruptedException { String gasPrice = getGasString(); - // 查询不归集的账号 - String not_pool_address = redisUtils.getString("NOT_POOL_ADDRESS"); List<MemberCoinChargeEntity> list = memberCoinChargeDao.selectAllBySymbolAndTag(CoinTypeEnum.USDT.name(), "ERC20", 1); if (CollUtil.isNotEmpty(list)) { EthService ethService = new EthService(); - for (MemberCoinChargeEntity coinCharge : list) { // 首先根据每个地址查询其是否有ETH 如果没有就充值ETH并设置1 表示初始状态 status=2(待充值)3:表示已提过 String address = coinCharge.getAddress(); Long memberId = coinCharge.getMemberId(); - BigDecimal lastAmount = coinCharge.getLastAmount(); - if(StringUtils.isNotBlank(not_pool_address) && not_pool_address.contains(address)){ - // 不归集的 - continue; - } - if (lastAmount == null || lastAmount.compareTo(LIMIT) < 0) { + BigDecimal usdt = coinCharge.getAmount(); + if (usdt == null || usdt.compareTo(LIMIT) < 0) { continue; } - BigDecimal usdt = ethService.tokenGetBalance(address); + BigDecimal usdt2 = ethService.tokenGetBalance(address); + /* if(usdt2==null || usdt2.compareTo(usdt)<0){ + continue; + }*/ //log.info("地址:{}, 金额:{}", address, usdt); - if (usdt != null && usdt.compareTo(LIMIT) > 0) { - usdt = usdt.subtract(new BigDecimal("0.01")); + if (usdt2 != null && usdt2.compareTo(LIMIT) >= 0) { + usdt = usdt2.setScale(2, RoundingMode.DOWN); // 查询eth是否足够 BigDecimal eth = EthService.getEthBlance(address); @@ -96,20 +92,9 @@ usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf(".")); } - String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr,gasPrice); - log.info("归集:{}", hash); -// if (StrUtil.isNotBlank(hash)) { -// // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新 -// coinCharge.setHash(hash); -// memberCoinChargeDao.updateById(coinCharge); -// } + String hash = ethService.tokenSend(privateKey, address, POOL_ADDRESS, usdtStr, gasPrice); } else { - String eth_transfer_fee = redisUtils.getString("ETH_TRANSFER_FEE_JYS"); - if(StringUtils.isNotBlank(eth_transfer_fee) && "yes".equals(eth_transfer_fee)){ - String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE,gasPrice); - log.info("转手续费:{}", hash); - } - + String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE, gasPrice); } } } @@ -142,7 +127,7 @@ String privateKey = coinAddress.getPrivateKey(); BigDecimal tr = eth.subtract(ETH_TR_FEE); - String hash = ethService.ethSend(privateKey, address, TOTAL_ADDRESS, tr.toPlainString(),gasPrice); + String hash = ethService.ethSend(privateKey, address, TOTAL_ADDRESS, tr.toPlainString(), gasPrice); if (StrUtil.isNotBlank(hash)) { coinCharge.setHash(hash); coinCharge.setLastAmount(new BigDecimal("0.0001")); @@ -155,12 +140,12 @@ } - - public void pollByAddress(String address) throws ExecutionException, InterruptedException { + public void pollByAddress(String address, BigDecimal balance) throws ExecutionException, InterruptedException { String gasPrice = getGasString(); EthService ethService = new EthService(); - BigDecimal usdt = ethService.tokenGetBalance(address); - if(usdt==null || usdt.compareTo(LIMIT)<0){ + //BigDecimal usdt = ethService.tokenGetBalance(address); + BigDecimal usdt = balance; + if (usdt == null || usdt.compareTo(LIMIT) < 0) { return; } // 查询eth是否足够 @@ -180,18 +165,10 @@ usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf(".")); } - String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr,gasPrice); - log.info("冲币归集:{}", hash); -// if (StrUtil.isNotBlank(hash)) { -// // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新 -// coinCharge.setHash(hash); -// memberCoinChargeDao.updateById(coinCharge); -// } + String hash = ethService.tokenSend(privateKey, address, POOL_ADDRESS, usdtStr, gasPrice); } else { + String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE, gasPrice); - String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE,gasPrice); - log.info("冲币归集转手续费:{}", hash); - //log.info("转手续费:{}", hash); } } -- Gitblit v1.9.1