zainali5120
2021-02-20 bd9eaf28cb817c9f9bd878e6abeb547836c2cb3f
TRC20版本提交
3 files modified
56 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java 29 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/NotionalPoolingJob.java 23 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java
@@ -23,10 +23,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class TrxUsdtUpdateService {
@@ -225,7 +222,7 @@
        if (trxBalance == null) {
            return false;
        }
        if (trxBalance.compareTo(new BigDecimal(1)) < 0) {
        if (trxBalance.compareTo(new BigDecimal(1)) >= 0) {
            // 转
            BigDecimal trc20Balance = Trc20Service.getTrc20Balance(address);
            if (trc20Balance == null) {
@@ -236,10 +233,27 @@
                return false;
            }
            Trc20Service.sendTrc20(coinAddressEntity.getPrivateKey(), Trc20Service.POOL_ADDRESS, trc20Balance);
            // 需要将存在redis的待归集地址删除
            Object trc20_pool = redisUtils.get("TRC20_POOL");
            if(trc20_pool!=null){
                List<String> poolList = (List) trc20_pool;
                Iterator<String> iterator = poolList.iterator();
                while (iterator.hasNext()){
                    String next = iterator.next();
                    if(address.equals(next)){
                        iterator.remove();
                    }
                }
               if(CollectionUtils.isEmpty(poolList)) {
                   redisUtils.del("TRC20_POOL");
               }else{
                   redisUtils.set("TRC20_POOL", poolList);
               }
            }
            return true;
        } else {
            Trc20Service.sendTrx(Trc20Service.TRX_PRIVATE_KEY, address, new BigDecimal(1));
            // 将这个地址记录,后续同步 TODO
            // 将这个地址记录,后续同步
            Object trc20_pool = redisUtils.get("TRC20_POOL");
            List<String> poolList = new ArrayList<>();
            if (trc20_pool != null) {
@@ -247,8 +261,7 @@
            }
            poolList.add(address);
            redisUtils.set("TRC20_POOL", poolList);
            return true;
        }
        return false;
    }
}
src/main/java/com/xcong/excoin/quartz/job/NotionalPoolingJob.java
@@ -1,12 +1,17 @@
package com.xcong.excoin.quartz.job;
import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService;
import com.xcong.excoin.modules.blackchain.service.UsdtEthService;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
@@ -23,6 +28,12 @@
    @Resource
    private UsdtEthService usdtEthService;
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private TrxUsdtUpdateService trxUsdtUpdateService;
    /**
     * usdt 归集
@@ -52,4 +63,16 @@
            log.info("#ETH归集错误#", e);
        }
    }
    @Scheduled(cron = "0 1/5 * * * ? ")
    public void poolUsdtTrc20() {
        Object trc20_pool = redisUtils.get("TRC20_POOL");
        if(trc20_pool==null){
            return;
        }
        List<String> list = (List)trc20_pool;
        for(String address: list){
           trxUsdtUpdateService.poolByAddress(address);
        }
    }
}
src/main/resources/application.yml
@@ -53,11 +53,11 @@
    ## Redis数据库索引(默认为0)
    database: 1
    ## Redis服务器地址
    host: 47.114.114.219
    host: 120.27.238.55
    ## Redis服务器连接端口
    port: 6379
    ## Redis服务器连接密码(默认为空)
    password: biyi123
    password: xcong123
    jedis:
      pool:
        ## 连接池最大连接数(使用负值表示没有限制)