From cc856f132f5f96af0ad9e0bbda56f20877b1b655 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 30 Aug 2022 11:04:12 +0800
Subject: [PATCH] fix

---
 src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java |   27 +++++++++++++++++++++++++++
 src/test/java/cc/mrbird/febs/ChainTest.java               |    6 ++++++
 src/main/resources/mapper/dapp/DappSdeWithdrawFeeDao.xml  |    1 +
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
index 7500e8f..98f533d 100644
--- a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
+++ b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
@@ -21,11 +21,16 @@
 import org.web3j.protocol.core.methods.request.EthFilter;
 import org.web3j.protocol.core.methods.response.TransactionReceipt;
 import org.web3j.protocol.http.HttpService;
+import org.web3j.protocol.websocket.WebSocketClient;
+import org.web3j.protocol.websocket.WebSocketService;
 import org.web3j.tx.gas.StaticGasProvider;
 
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.net.ConnectException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import java.rmi.activation.UnknownObjectException;
 import java.util.HashMap;
@@ -88,6 +93,28 @@
         });
     }
 
+    public static void wssContractEventListener(BigInteger startBlock, ContractEventService event, String type) {
+        WebSocketService ws =null;
+        WebSocketClient webSocketClient=null;
+        Web3j web3j = null;
+
+        try {
+            webSocketClient=new WebSocketClient(new URI("wss://bsc-mainnet.blockvision.org/v1/2Dz4hDxe5vNtQxWkLXNwnzDePKp"));
+            ws = new WebSocketService(webSocketClient, false);
+            ws.connect();
+            web3j = Web3j.build(ws);
+            ChainEnum chain = ChainEnum.getValueByName(type);
+            assert chain != null;
+            EthFilter filter = getFilter(startBlock, null, chain.getContractAddress());
+            web3j.ethLogFlowable(filter).subscribe(log -> {
+                System.out.println(111);
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
 
     private static EthUsdtContract contract(String privateKey, String contractAddress, String url) {
         Credentials credentials = Credentials.create(privateKey);
diff --git a/src/main/resources/mapper/dapp/DappSdeWithdrawFeeDao.xml b/src/main/resources/mapper/dapp/DappSdeWithdrawFeeDao.xml
index 432a0bb..486536d 100644
--- a/src/main/resources/mapper/dapp/DappSdeWithdrawFeeDao.xml
+++ b/src/main/resources/mapper/dapp/DappSdeWithdrawFeeDao.xml
@@ -8,6 +8,7 @@
             sum(amount) amount
         from dapp_sde_withdraw_fee
         where has_return=2
+        group by address
     </select>
 
     <update id="updateHasReturnToFinish">
diff --git a/src/test/java/cc/mrbird/febs/ChainTest.java b/src/test/java/cc/mrbird/febs/ChainTest.java
index ce41e6f..74b42ef 100644
--- a/src/test/java/cc/mrbird/febs/ChainTest.java
+++ b/src/test/java/cc/mrbird/febs/ChainTest.java
@@ -16,6 +16,7 @@
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.web3j.protocol.core.DefaultBlockParameterName;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -159,4 +160,9 @@
     public void sendCardTest() {
 //        ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT("0x691DEaf9b678Cba6747Eec9a4800a9ad2048E39C");
     }
+
+    @Test
+    public void wssTest() {
+        ChainService.wssContractEventListener(new BigInteger("20882595"), bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
+    }
 }

--
Gitblit v1.9.1