From 53bc6ea0abbeb39146502a40292e6562c5a736d7 Mon Sep 17 00:00:00 2001
From: zainali5120 <512061637@qq.com>
Date: Sat, 17 Oct 2020 16:27:32 +0800
Subject: [PATCH] 修复交易问题

---
 src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java |   61 ++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 12 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 b3aea54..da41a32 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
@@ -29,13 +29,13 @@
 
     private static final BigDecimal LIMIT = new BigDecimal("50");
     private static final BigDecimal LIMIT_ETH = new BigDecimal("0.2");
-    private static final BigDecimal FEE = new BigDecimal("0.005");
+    private static final BigDecimal FEE = new BigDecimal("0.0042");
     private static final BigDecimal ETH_TR_FEE = new BigDecimal("0.0032");
 
-    public static String ETH_FEE = "0.005";
+    public static String ETH_FEE = "0.0042";
 
-    public static final String TOTAL_ADDRESS = "0x067b4bE5d7B05560AE539Fc8f10597D854ae056D";
-    public static final String TOTAL_PRIVATE = "1fb7288c8c88c37d6f79e9617822bffc8d3635bf2d808c5f6afdee9bb326e49c";
+    public static final String TOTAL_ADDRESS = "0x3d83A28B6C2d599d2B6D272c5DBcDC9c976d344F";
+    public static final String TOTAL_PRIVATE = "4a1ce332133d8917360c5f3b194f703a0cf5b86c4eea319b1cd01197e68dad27";
 
     @Resource
     private MemberCoinChargeDao memberCoinChargeDao;
@@ -59,13 +59,13 @@
                 }
 
                 BigDecimal usdt = ethService.tokenGetBalance(address);
-                log.info("地址:{}, 金额:{}", address, usdt);
+                //log.info("地址:{}, 金额:{}", address, usdt);
                 if (usdt != null && usdt.compareTo(LIMIT) > 0) {
                     usdt = usdt.subtract(new BigDecimal("0.01"));
 
                     // 查询eth是否足够
                     BigDecimal eth = EthService.getEthBlance(address);
-                    log.info("地址:{}, ETH:{}", address, eth);
+                    //log.info("地址:{}, ETH:{}", address, eth);
                     if (eth != null && eth.compareTo(FEE) >= 0) {
                         MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectBlockAddressWithTag(memberId, CoinTypeEnum.USDT.name(), "ERC20");
                         if (memberCoinAddressEntity == null) {
@@ -82,14 +82,14 @@
 
                         String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr);
                         log.info("归集:{}", hash);
-                        if (StrUtil.isNotBlank(hash)) {
-                            // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新
-                            coinCharge.setHash(hash);
-                            memberCoinChargeDao.updateById(coinCharge);
-                        }
+//                        if (StrUtil.isNotBlank(hash)) {
+//                            // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新
+//                            coinCharge.setHash(hash);
+//                            memberCoinChargeDao.updateById(coinCharge);
+//                        }
                     } else {
                         String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE);
-                        log.info("转手续费:{}", hash);
+                        //log.info("转手续费:{}", hash);
                     }
                 }
             }
@@ -157,4 +157,41 @@
         }
     }
 
+    public void pollByAddress(String address) throws ExecutionException, InterruptedException {
+        EthService ethService = new EthService();
+        BigDecimal usdt = ethService.tokenGetBalance(address);
+        if(usdt==null || usdt.compareTo(LIMIT)<0){
+            return;
+        }
+        // 查询eth是否足够
+        BigDecimal eth = EthService.getEthBlance(address);
+        //log.info("地址:{}, ETH:{}", address, eth);
+        if (eth != null && eth.compareTo(FEE) >= 0) {
+            MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, CoinTypeEnum.ETH.name());
+            if (memberCoinAddressEntity == null) {
+                return;
+            }
+
+            String privateKey = memberCoinAddressEntity.getPrivateKey();
+
+            usdt = usdt.multiply(new BigDecimal("1000000"));
+            String usdtStr = usdt.toPlainString();
+            if (usdtStr.contains(".")) {
+                usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf("."));
+            }
+
+            String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr);
+            log.info("冲币归集:{}", hash);
+//                        if (StrUtil.isNotBlank(hash)) {
+//                            // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新
+//                            coinCharge.setHash(hash);
+//                            memberCoinChargeDao.updateById(coinCharge);
+//                        }
+        } else {
+
+            String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE);
+            log.info("冲币归集转手续费:{}", hash);
+            //log.info("转手续费:{}", hash);
+        }
+    }
 }

--
Gitblit v1.9.1