Helius
2021-05-26 5575818556096be1dadaf5ff356b5db4c832aaa2
modify
5 files deleted
10 files modified
978 ■■■■■ changed files
pom.xml 14 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/system/controller/CommonController.java 39 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/Impl/BlockSeriveImpl.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/Trc20Service.java 110 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java 378 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java 10 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java 71 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/netty/initalizer/WebSocketServerInitializer.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/netty/server/WebSocketServer.java 10 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java 130 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/NotionalPoolingJob.java 85 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/UsdtUpdateConsumer.java 76 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 2 ●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/TrcTest.java 35 ●●●● patch | view | raw | blame | history
pom.xml
@@ -293,13 +293,13 @@
            <scope>system</scope>
            <systemPath>${basedir}/lib/taobao-sdk-java.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>ztron-sdk</groupId>
            <artifactId>ztron-sdk</artifactId>
            <version>0.0.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/tron-sdk.jar</systemPath>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>ztron-sdk</groupId>-->
<!--            <artifactId>ztron-sdk</artifactId>-->
<!--            <version>0.0.1</version>-->
<!--            <scope>system</scope>-->
<!--            <systemPath>${basedir}/lib/tron-sdk.jar</systemPath>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
src/main/java/com/xcong/excoin/common/system/controller/CommonController.java
@@ -11,7 +11,6 @@
import com.xcong.excoin.common.system.service.CommonService;
import com.xcong.excoin.common.system.vo.Base64UploadFilesVo;
import com.xcong.excoin.configurations.properties.AliOssProperties;
import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService;
import com.xcong.excoin.modules.platform.dao.SysExceptionDetailDao;
import com.xcong.excoin.utils.MessageSourceUtils;
import com.xcong.excoin.utils.OssUtils;
@@ -140,25 +139,25 @@
        }
        return Result.ok(MessageSourceUtils.getString("result_success_msg"), base64UploadFilesVo);
    }
    @Autowired
    private TrxUsdtUpdateService trxUsdtUpdateService;
    @ApiOperation(value = "trc20测试")
    @Transactional(rollbackFor = Exception.class)
    @GetMapping(value = "/getTrc20Test")
    public Result getTrc20Test() {
        long start = System.currentTimeMillis();
        System.out.println(start);
        long getnowblock = trxUsdtUpdateService.getnowblock();
        System.out.println(System.currentTimeMillis());
        Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM");
        TrxUsdtUpdateService.getblockbynum(BigInteger.valueOf(Long.parseLong(trc20BlockNum.toString())));
        long end = System.currentTimeMillis();
        System.out.println(end);
        BigDecimal.ONE.divide(BigDecimal.ZERO);
        return Result.ok(end - start);
    }
//
//    @Autowired
//    private TrxUsdtUpdateService trxUsdtUpdateService;
//
//    @ApiOperation(value = "trc20测试")
//    @Transactional(rollbackFor = Exception.class)
//    @GetMapping(value = "/getTrc20Test")
//    public Result getTrc20Test() {
//        long start = System.currentTimeMillis();
//        System.out.println(start);
//        long getnowblock = trxUsdtUpdateService.getnowblock();
//        System.out.println(System.currentTimeMillis());
//        Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM");
//        TrxUsdtUpdateService.getblockbynum(BigInteger.valueOf(Long.parseLong(trc20BlockNum.toString())));
//        long end = System.currentTimeMillis();
//        System.out.println(end);
//        BigDecimal.ONE.divide(BigDecimal.ZERO);
//        return Result.ok(end - start);
//    }
    @Autowired
    private SysExceptionDetailDao sysExceptionDetailDao;
src/main/java/com/xcong/excoin/modules/blackchain/service/Impl/BlockSeriveImpl.java
@@ -190,9 +190,9 @@
                            // 发送新增的地址到监听集合
                            usdtUpdateProducer.sendAddressMsg(address+","+"ERC20");
                        } else if ("TRC20".equals(lable)) {
                            Map<String, String> usdtMap = Trc20Service.createAddress();
                            address = usdtMap.get("address");
                            key = usdtMap.get("privateKey");
//                            Map<String, String> usdtMap = Trc20Service.createAddress();
//                            address = usdtMap.get("address");
//                            key = usdtMap.get("privateKey");
                            map.put("address", address);
                            // 发送新增的地址到监听集合
                            usdtUpdateProducer.sendAddressMsg(address+","+"TRC20");
src/main/java/com/xcong/excoin/modules/blackchain/service/Trc20Service.java
File was deleted
src/main/java/com/xcong/excoin/modules/blackchain/service/TrxUsdtUpdateService.java
File was deleted
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -41,7 +41,6 @@
import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.Put;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
src/main/java/com/xcong/excoin/netty/dispatch/MsgDispatch.java
@@ -19,9 +19,7 @@
 */
@Slf4j
@Component("msgDispatch")
public class MsgDispatch implements ApplicationContextAware {
    private ApplicationContext applicationContext;
public class MsgDispatch {
    @Autowired
    private MsgLogic msgLogic;
@@ -35,11 +33,5 @@
            log.info("#websocket json error:{}#", e);
            ctx.channel().writeAndFlush(NettyTools.webSocketBytes("params error"));
        }
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java
@@ -38,14 +38,14 @@
@ChannelHandler.Sharable
public class WebSocketServerHandler extends ChannelInboundHandlerAdapter {
    private final ConcurrentMap<String, Integer> pingTimes = new ConcurrentHashMap<>();
//    private final ConcurrentMap<String, Integer> pingTimes = new ConcurrentHashMap<>();
    private static final int MAX_UN_REC_PING_TIMES = 3;
    private WebSocketServerHandshaker handshaker;
    @Resource(name = "msgDispatch")
    private MsgDispatch msgDispatch;
//    @Resource(name = "msgDispatch")
//    private MsgDispatch msgDispatch;
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
@@ -76,7 +76,7 @@
                if (content.contains(Contans.HEART_BEAT)) {
                    resetTimes(ctx.channel());
                } else {
                    this.msgDispatch.webSocketDispatch(ctx, content);
//                    this.msgDispatch.webSocketDispatch(ctx, content);
                }
            } catch (ClassCastException e) {
                content = ((CloseWebSocketFrame) frame).reasonText();
@@ -88,40 +88,40 @@
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        log.info("[触发器触发]");
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            if (event.state() == IdleState.READER_IDLE) {
            } else if (event.state() == IdleState.WRITER_IDLE) {
                /*写超时*/
                ctx.channel().writeAndFlush(NettyTools.webSocketBytes(Contans.HEART_BEAT));
                Integer times = pingTimes.get(ctx.channel().id().asShortText());
                if (times == null) {
                    times = 0;
                }
                /*读超时*/
                log.info("===服务端===({}写超时, {})", ctx.channel().id().asShortText(), times);
                // 失败计数器次数大于等于3次的时候,关闭链接,等待client重连
                if (times >= MAX_UN_REC_PING_TIMES) {
                    log.info("===服务端===(写超时,关闭chanel)");
                    // 连续超过N次未收到client的ping消息,那么关闭该通道,等待client重连
                    ctx.channel().close();
                } else {
                    // 失败计数器加1
                    times++;
                    pingTimes.remove(ctx.channel().id().asShortText());
                    pingTimes.put(ctx.channel().id().asShortText(), times);
                }
            } else if (event.state() == IdleState.ALL_IDLE) {
                /*总超时*/
                System.out.println("===服务端===(ALL_IDLE 总超时)");
            }
        }
//        if (evt instanceof IdleStateEvent) {
//            IdleStateEvent event = (IdleStateEvent) evt;
//            if (event.state() == IdleState.READER_IDLE) {
//
//            } else if (event.state() == IdleState.WRITER_IDLE) {
//                /*写超时*/
//                ctx.channel().writeAndFlush(NettyTools.webSocketBytes(Contans.HEART_BEAT));
//                Integer times = pingTimes.get(ctx.channel().id().asShortText());
//                if (times == null) {
//                    times = 0;
//                }
//                /*读超时*/
//                log.info("===服务端===({}写超时, {})", ctx.channel().id().asShortText(), times);
//                // 失败计数器次数大于等于3次的时候,关闭链接,等待client重连
//                if (times >= MAX_UN_REC_PING_TIMES) {
//                    log.info("===服务端===(写超时,关闭chanel)");
//                    // 连续超过N次未收到client的ping消息,那么关闭该通道,等待client重连
//                    ctx.channel().close();
//                } else {
//                    // 失败计数器加1
//                    times++;
//                    pingTimes.remove(ctx.channel().id().asShortText());
//                    pingTimes.put(ctx.channel().id().asShortText(), times);
//                }
//            } else if (event.state() == IdleState.ALL_IDLE) {
//                /*总超时*/
//                System.out.println("===服务端===(ALL_IDLE 总超时)");
//            }
//        }
    }
    private void resetTimes(Channel channel) {
        pingTimes.remove(channel.id().asShortText());
        pingTimes.put(channel.id().asShortText(), 0);
//        pingTimes.remove(channel.id().asShortText());
//        pingTimes.put(channel.id().asShortText(), 0);
    }
    @Override
@@ -132,6 +132,7 @@
    private void handlerWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
        System.out.println(111111111);
        // 判断是否关闭链路的指令
        if (frame instanceof CloseWebSocketFrame) {
            handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
src/main/java/com/xcong/excoin/netty/initalizer/WebSocketServerInitializer.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.netty.initalizer;
import com.xcong.excoin.netty.handler.WebSocketServerHandler;
import com.xcong.excoin.utils.SpringContextHolder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
@@ -11,6 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
 * @author wzy
 * @email wangdoubleone@gmail.com
@@ -19,8 +22,8 @@
@Component
public class WebSocketServerInitializer extends ChannelInitializer<NioSocketChannel> {
    @Autowired
    private WebSocketServerHandler webSocketServerHandler;
//    @Autowired
//    private WebSocketServerHandler webSocketServerHandler;
    @Override
    protected void initChannel(NioSocketChannel ch) throws Exception {
@@ -32,8 +35,8 @@
        cp.addLast(new HttpObjectAggregator(65536));
        cp.addLast(new ChunkedWriteHandler());
        // 心跳
        ch.pipeline().addLast(new IdleStateHandler(0, 10, 0));
//        ch.pipeline().addLast(new IdleStateHandler(0, 10, 0));
        // 自定义业务handler
        cp.addLast(webSocketServerHandler);
        cp.addLast(new WebSocketServerHandler());
    }
}
src/main/java/com/xcong/excoin/netty/server/WebSocketServer.java
@@ -23,9 +23,9 @@
    private EventLoopGroup work = new NioEventLoopGroup();
    private ChannelFuture channelFuture;
    @Autowired
    private WebSocketServerInitializer webSocketServerInitializer;
//
//    @Autowired
//    private WebSocketServerInitializer webSocketServerInitializer;
    @Override
    public void start() throws Exception {
@@ -34,9 +34,9 @@
            ServerBootstrap b = new ServerBootstrap();
            b.group(boss, work)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(webSocketServerInitializer);
                    .childHandler(new WebSocketServerInitializer() );
            channelFuture = b.bind(9998).sync();
            channelFuture = b.bind(9982).sync();
            log.info("[websocket服务器启动完成]-->{}", channelFuture.channel().localAddress());
        } finally {
src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java
File was deleted
src/main/java/com/xcong/excoin/quartz/job/NotionalPoolingJob.java
File was deleted
src/main/java/com/xcong/excoin/rabbit/consumer/UsdtUpdateConsumer.java
File was deleted
src/main/resources/application.yml
@@ -1,5 +1,5 @@
server:
  port: 8888
  port: 8894
  servlet:
    context-path: /
src/test/java/com/xcong/excoin/TrcTest.java
@@ -3,7 +3,6 @@
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.xcong.excoin.modules.blackchain.service.Trc20Service;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
@@ -27,22 +26,22 @@
    @Test
    public void trc20Test() {
        String url = "https://api.trongrid.io/wallet/getblockbynum";
        while(true) {
            Object current = redisUtils.get("USDT_TRC20_CURRENT_BLOCK_NUM");
            Map<String, Object> map = new HashMap<>();
            map.put("num", current);
            String param = JSON.toJSONString(map);
            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
            HttpResponse response = HttpUtil.createPost(url).body(param).contentType("application/json").header("TRON-PRO-API-KEY", Trc20Service.API_KEY).execute();
//            log.info(response.body());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
//        String url = "https://api.trongrid.io/wallet/getblockbynum";
//
//        while(true) {
//            Object current = redisUtils.get("USDT_TRC20_CURRENT_BLOCK_NUM");
//            Map<String, Object> map = new HashMap<>();
//            map.put("num", current);
//            String param = JSON.toJSONString(map);
//            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
//            HttpResponse response = HttpUtil.createPost(url).body(param).contentType("application/json").header("TRON-PRO-API-KEY", Trc20Service.API_KEY).execute();
////            log.info(response.body());
//
//            try {
//                Thread.sleep(2000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
    }
}