From c2ac41925658c88ed75b2677d5d41162b1be3e78 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 03 Jul 2023 11:45:33 +0800
Subject: [PATCH] andao上联测试
---
src/main/java/cc/mrbird/febs/dapp/contract/ContractInit.java | 24 +-
src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractMain.java | 169 +++++++++++++++
src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java | 2
src/main/java/cc/mrbird/febs/dapp/contract/andao/Abi.java | 411 +++++++++++++++++++++++++++++++++++++
src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractInit.java | 37 +++
5 files changed, 631 insertions(+), 12 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java b/src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java
index 54f27ee..6fec420 100644
--- a/src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java
+++ b/src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java
@@ -5,6 +5,8 @@
/**
* 链类型
+ * -- todo
+ * 0xD88F63aCbcF82cC6D2255b8082D7bdE43b559d00 测试链
*/
@Getter
public enum ChainEnum {
diff --git a/src/main/java/cc/mrbird/febs/dapp/contract/ContractInit.java b/src/main/java/cc/mrbird/febs/dapp/contract/ContractInit.java
index 9a4c82d..6889a6b 100644
--- a/src/main/java/cc/mrbird/febs/dapp/contract/ContractInit.java
+++ b/src/main/java/cc/mrbird/febs/dapp/contract/ContractInit.java
@@ -25,16 +25,16 @@
private RedisService redisService;
- @PostConstruct
- public void init(){
- // 设置起始区块编号 TODO
- BigInteger start = new BigInteger("28282373");
- // 需要打开 获取最新区块编号
- Object bnb_block_number = redisService.get("BNB_BLOCK_NUMBER");
- if(bnb_block_number !=null){
- start = BigInteger.valueOf(Long.valueOf(bnb_block_number.toString()));
- }
- System.out.println("启动区块事件监听,监听起始:"+start);
-// contractMain.listenBetting(start);
- }
+// @PostConstruct
+// public void init(){
+// // 设置起始区块编号 TODO
+// BigInteger start = new BigInteger("28282373");
+// // 需要打开 获取最新区块编号
+// Object bnb_block_number = redisService.get("BNB_BLOCK_NUMBER");
+// if(bnb_block_number !=null){
+// start = BigInteger.valueOf(Long.valueOf(bnb_block_number.toString()));
+// }
+// System.out.println("启动区块事件监听,监听起始:"+start);
+//// contractMain.listenBetting(start);
+// }
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/contract/andao/Abi.java b/src/main/java/cc/mrbird/febs/dapp/contract/andao/Abi.java
new file mode 100644
index 0000000..8a2b0a9
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/dapp/contract/andao/Abi.java
@@ -0,0 +1,411 @@
+package cc.mrbird.febs.dapp.contract.andao;
+
+import io.reactivex.Flowable;
+import io.reactivex.functions.Function;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.web3j.abi.EventEncoder;
+import org.web3j.abi.TypeReference;
+import org.web3j.abi.datatypes.Address;
+import org.web3j.abi.datatypes.Event;
+import org.web3j.abi.datatypes.Type;
+import org.web3j.abi.datatypes.Utf8String;
+import org.web3j.abi.datatypes.generated.Uint256;
+import org.web3j.abi.datatypes.generated.Uint8;
+import org.web3j.crypto.Credentials;
+import org.web3j.protocol.Web3j;
+import org.web3j.protocol.core.DefaultBlockParameter;
+import org.web3j.protocol.core.RemoteCall;
+import org.web3j.protocol.core.RemoteFunctionCall;
+import org.web3j.protocol.core.methods.request.EthFilter;
+import org.web3j.protocol.core.methods.response.BaseEventResponse;
+import org.web3j.protocol.core.methods.response.Log;
+import org.web3j.protocol.core.methods.response.TransactionReceipt;
+import org.web3j.tx.Contract;
+import org.web3j.tx.TransactionManager;
+import org.web3j.tx.gas.ContractGasProvider;
+
+/**
+ * <p>Auto generated code.
+ * <p><strong>Do not modify!</strong>
+ * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
+ * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
+ * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
+ *
+ * <p>Generated with web3j version 4.5.5.
+ */
+@SuppressWarnings("rawtypes")
+public class Abi extends Contract {
+ private static final String BINARY = "608060405273ca143ce32fe78f1f7019d7d551a6402fc5350c73600860006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555030600960006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507355d398326f99059ff775485246999027b3197955600a60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555073adc5331ac7f46c63e877aec2dfbb5523c7680812600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550737a9bfe048d110ef90a467803653f9b8666f9096c600c60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550737a9bfe048d110ef90a467803653f9b8666f9096c600d60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550348015620001fb57600080fd5b5060006200020e620007bf60201b60201c565b9050806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3506040518060400160405280600d81526020017f444d44746573743120436f696e0000000000000000000000000000000000000081525060069080519060200190620002f99291906200096f565b506040518060400160405280600881526020017f444d44746573743100000000000000000000000000000000000000000000000081525060059080519060200190620003479291906200096f565b506008600460006101000a81548160ff021916908360ff160217905550651319718a5000600381905550600354600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555033600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c9c65396600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600a60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050602060405180830381600087803b1580156200051257600080fd5b505af115801562000527573d6000803e3d6000fd5b505050506040513d60208110156200053e57600080fd5b8101908080519060200190929190505050600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000620005c86064620005b46055600354620007c760201b62001b1e1790919060201c565b6200085260201b62001ba41790919060201c565b90503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3600062000669606462000655600a600354620007c760201b62001b1e1790919060201c565b6200085260201b62001ba41790919060201c565b9050600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a360006200072c6064620007186005600354620007c760201b62001b1e1790919060201c565b6200085260201b62001ba41790919060201c565b9050600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505062000a1e565b600033905090565b600080831415620007dc57600090506200084c565b6000828402905082848281620007ee57fe5b041462000847576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180620028a96021913960400191505060405180910390fd5b809150505b92915050565b60006200089c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250620008a460201b60201c565b905092915050565b6000808311829062000954576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101562000918578082015181840152602081019050620008fb565b50505050905090810190601f168015620009465780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385816200096157fe5b049050809150509392505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620009b257805160ff1916838001178555620009e3565b82800160010185558215620009e3579182015b82811115620009e2578251825591602001919060010190620009c5565b5b509050620009f29190620009f6565b5090565b62000a1b91905b8082111562000a17576000816000905550600101620009fd565b5090565b90565b611e7b8062000a2e6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c80638da5cb5b116100a2578063a457c2d711610071578063a457c2d71461053b578063a9059cbb146105a1578063c45a015514610607578063dd62ed3e14610651578063f2fde38b146106c957610116565b80638da5cb5b146103de5780638f99d7371461042857806395d89b4114610472578063a0712d68146104f557610116565b8063313ce567116100e9578063313ce567146102a857806339509351146102cc57806370a0823114610332578063715018a61461038a578063893d20e81461039457610116565b806306fdde031461011b578063095ea7b31461019e57806318160ddd1461020457806323b872dd14610222575b600080fd5b61012361070d565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610163578082015181840152602081019050610148565b50505050905090810190601f1680156101905780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101ea600480360360408110156101b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107af565b604051808215151515815260200191505060405180910390f35b61020c6107cd565b6040518082815260200191505060405180910390f35b61028e6004803603606081101561023857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107d7565b604051808215151515815260200191505060405180910390f35b6102b06108b0565b604051808260ff1660ff16815260200191505060405180910390f35b610318600480360360408110156102e257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108c7565b604051808215151515815260200191505060405180910390f35b6103746004803603602081101561034857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061097a565b6040518082815260200191505060405180910390f35b6103926109c3565b005b61039c610b4b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103e6610b5a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610430610b83565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61047a610ba9565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104ba57808201518184015260208101905061049f565b50505050905090810190601f1680156104e75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6105216004803603602081101561050b57600080fd5b8101908080359060200190929190505050610c4b565b604051808215151515815260200191505060405180910390f35b6105876004803603604081101561055157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d30565b604051808215151515815260200191505060405180910390f35b6105ed600480360360408110156105b757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610dfd565b604051808215151515815260200191505060405180910390f35b61060f610e1b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6106b36004803603604081101561066757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e41565b6040518082815260200191505060405180910390f35b61070b600480360360208110156106df57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ec8565b005b606060068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107a55780601f1061077a576101008083540402835291602001916107a5565b820191906000526020600020905b81548152906001019060200180831161078857829003601f168201915b5050505050905090565b60006107c36107bc610f9d565b8484610fa5565b6001905092915050565b6000600354905090565b60006107e484848461119c565b6108a5846107f0610f9d565b6108a085604051806060016040528060288152602001611d6e60289139600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610856610f9d565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115279092919063ffffffff16565b610fa5565b600190509392505050565b6000600460009054906101000a900460ff16905090565b60006109706108d4610f9d565b8461096b85600260006108e5610f9d565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115e790919063ffffffff16565b610fa5565b6001905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6109cb610f9d565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a8c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000610b55610b5a565b905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606060058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610c415780601f10610c1657610100808354040283529160200191610c41565b820191906000526020600020905b815481529060010190602001808311610c2457829003601f168201915b5050505050905090565b6000610c55610f9d565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610d16576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b610d27610d21610f9d565b8361166f565b60019050919050565b6000610df3610d3d610f9d565b84610dee85604051806060016040528060258152602001611e006025913960026000610d67610f9d565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115279092919063ffffffff16565b610fa5565b6001905092915050565b6000610e11610e0a610f9d565b848461119c565b6001905092915050565b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610ed0610f9d565b73ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f91576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b610f9a8161182c565b50565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561102b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611d246024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156110b1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180611e256022913960400191505060405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611222576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180611cff6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112a8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611ddd6023913960400191505060405180910390fd5b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614806113515750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b1561136657611361838383611970565b611522565b600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561143d5760006113e560646113d7600385611b1e90919063ffffffff16565b611ba490919063ffffffff16565b905060006113fc8284611bee90919063ffffffff16565b905061142b85600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611970565b611436858583611970565b5050611521565b8173ffffffffffffffffffffffffffffffffffffffff16600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156115145760006114bc60646114ae600385611b1e90919063ffffffff16565b611ba490919063ffffffff16565b905060006114d38284611bee90919063ffffffff16565b905061150285600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611970565b61150d858583611970565b5050611520565b61151f838383611970565b5b5b5b505050565b60008383111582906115d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561159957808201518184015260208101905061157e565b50505050905090810190601f1680156115c65780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015611665576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611712576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f42455032303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b611727816003546115e790919063ffffffff16565b60038190555061177f81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115e790919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156118b2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611d486026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6119dc81604051806060016040528060268152602001611db760269139600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115279092919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611a7181600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546115e790919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600080831415611b315760009050611b9e565b6000828402905082848281611b4257fe5b0414611b99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180611d966021913960400191505060405180910390fd5b809150505b92915050565b6000611be683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611c38565b905092915050565b6000611c3083836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611527565b905092915050565b60008083118290611ce4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611ca9578082015181840152602081019050611c8e565b50505050905090810190601f168015611cd65780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611cf057fe5b04905080915050939250505056fe42455032303a207472616e736665722066726f6d20746865207a65726f206164647265737342455032303a20617070726f76652066726f6d20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737342455032303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7742455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737342455032303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f42455032303a20617070726f766520746f20746865207a65726f2061646472657373a265627a7a7231582090355699300bd47b0b324e616a03330295cfa071e27d7b6c9e54949a9294b4e364736f6c63430005100032536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77";
+
+ public static final String FUNC_ALLOWANCE = "allowance";
+
+ public static final String FUNC_APPROVE = "approve";
+
+ public static final String FUNC_BALANCEOF = "balanceOf";
+
+ public static final String FUNC_DECIMALS = "decimals";
+
+ public static final String FUNC_DECREASEALLOWANCE = "decreaseAllowance";
+
+ public static final String FUNC_FACTORY = "factory";
+
+ public static final String FUNC_GETOWNER = "getOwner";
+
+ public static final String FUNC_INCREASEALLOWANCE = "increaseAllowance";
+
+ public static final String FUNC_LPACC = "lpacc";
+
+ public static final String FUNC_MINT = "mint";
+
+ public static final String FUNC_NAME = "name";
+
+ public static final String FUNC_OWNER = "owner";
+
+ public static final String FUNC_RENOUNCEOWNERSHIP = "renounceOwnership";
+
+ public static final String FUNC_SYMBOL = "symbol";
+
+ public static final String FUNC_TOTALSUPPLY = "totalSupply";
+
+ public static final String FUNC_TRANSFER = "transfer";
+
+ public static final String FUNC_TRANSFERFROM = "transferFrom";
+
+ public static final String FUNC_TRANSFEROWNERSHIP = "transferOwnership";
+
+ public static final Event APPROVAL_EVENT = new Event("Approval",
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {}));
+ ;
+
+ public static final Event OWNERSHIPTRANSFERRED_EVENT = new Event("OwnershipTransferred",
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}));
+ ;
+
+ public static final Event TRANSFER_EVENT = new Event("Transfer",
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {}));
+ ;
+
+ @Deprecated
+ protected Abi(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
+ super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
+ }
+
+ protected Abi(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
+ super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
+ }
+
+ @Deprecated
+ protected Abi(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
+ super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
+ }
+
+ protected Abi(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
+ super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
+ }
+
+ public List<ApprovalEventResponse> getApprovalEvents(TransactionReceipt transactionReceipt) {
+ List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(APPROVAL_EVENT, transactionReceipt);
+ ArrayList<ApprovalEventResponse> responses = new ArrayList<ApprovalEventResponse>(valueList.size());
+ for (Contract.EventValuesWithLog eventValues : valueList) {
+ ApprovalEventResponse typedResponse = new ApprovalEventResponse();
+ typedResponse.log = eventValues.getLog();
+ typedResponse.owner = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.spender = (String) eventValues.getIndexedValues().get(1).getValue();
+ typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
+ responses.add(typedResponse);
+ }
+ return responses;
+ }
+
+ public Flowable<ApprovalEventResponse> approvalEventFlowable(EthFilter filter) {
+ return web3j.ethLogFlowable(filter).map(new Function<Log, ApprovalEventResponse>() {
+ @Override
+ public ApprovalEventResponse apply(Log log) {
+ Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(APPROVAL_EVENT, log);
+ ApprovalEventResponse typedResponse = new ApprovalEventResponse();
+ typedResponse.log = log;
+ typedResponse.owner = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.spender = (String) eventValues.getIndexedValues().get(1).getValue();
+ typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
+ return typedResponse;
+ }
+ });
+ }
+
+ public Flowable<ApprovalEventResponse> approvalEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
+ EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
+ filter.addSingleTopic(EventEncoder.encode(APPROVAL_EVENT));
+ return approvalEventFlowable(filter);
+ }
+
+ public List<OwnershipTransferredEventResponse> getOwnershipTransferredEvents(TransactionReceipt transactionReceipt) {
+ List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(OWNERSHIPTRANSFERRED_EVENT, transactionReceipt);
+ ArrayList<OwnershipTransferredEventResponse> responses = new ArrayList<OwnershipTransferredEventResponse>(valueList.size());
+ for (Contract.EventValuesWithLog eventValues : valueList) {
+ OwnershipTransferredEventResponse typedResponse = new OwnershipTransferredEventResponse();
+ typedResponse.log = eventValues.getLog();
+ typedResponse.previousOwner = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.newOwner = (String) eventValues.getIndexedValues().get(1).getValue();
+ responses.add(typedResponse);
+ }
+ return responses;
+ }
+
+ public Flowable<OwnershipTransferredEventResponse> ownershipTransferredEventFlowable(EthFilter filter) {
+ return web3j.ethLogFlowable(filter).map(new Function<Log, OwnershipTransferredEventResponse>() {
+ @Override
+ public OwnershipTransferredEventResponse apply(Log log) {
+ Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(OWNERSHIPTRANSFERRED_EVENT, log);
+ OwnershipTransferredEventResponse typedResponse = new OwnershipTransferredEventResponse();
+ typedResponse.log = log;
+ typedResponse.previousOwner = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.newOwner = (String) eventValues.getIndexedValues().get(1).getValue();
+ return typedResponse;
+ }
+ });
+ }
+
+ public Flowable<OwnershipTransferredEventResponse> ownershipTransferredEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
+ EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
+ filter.addSingleTopic(EventEncoder.encode(OWNERSHIPTRANSFERRED_EVENT));
+ return ownershipTransferredEventFlowable(filter);
+ }
+
+ public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
+ List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt);
+ ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
+ for (Contract.EventValuesWithLog eventValues : valueList) {
+ TransferEventResponse typedResponse = new TransferEventResponse();
+ typedResponse.log = eventValues.getLog();
+ typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
+ typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
+ responses.add(typedResponse);
+ }
+ return responses;
+ }
+
+ public Flowable<TransferEventResponse> transferEventFlowable(EthFilter filter) {
+ return web3j.ethLogFlowable(filter).map(new Function<Log, TransferEventResponse>() {
+ @Override
+ public TransferEventResponse apply(Log log) {
+ Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(TRANSFER_EVENT, log);
+ TransferEventResponse typedResponse = new TransferEventResponse();
+ typedResponse.log = log;
+ typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
+ typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
+ typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
+ return typedResponse;
+ }
+ });
+ }
+
+ public Flowable<TransferEventResponse> transferEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
+ EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
+ filter.addSingleTopic(EventEncoder.encode(TRANSFER_EVENT));
+ return transferEventFlowable(filter);
+ }
+
+ public RemoteFunctionCall<BigInteger> allowance(String owner, String spender) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_ALLOWANCE,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, owner),
+ new org.web3j.abi.datatypes.Address(160, spender)),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
+ return executeRemoteCallSingleValueReturn(function, BigInteger.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> approve(String spender, BigInteger amount) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_APPROVE,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, spender),
+ new org.web3j.abi.datatypes.generated.Uint256(amount)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<BigInteger> balanceOf(String account) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_BALANCEOF,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, account)),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
+ return executeRemoteCallSingleValueReturn(function, BigInteger.class);
+ }
+
+ public RemoteFunctionCall<BigInteger> decimals() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_DECIMALS,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Uint8>() {}));
+ return executeRemoteCallSingleValueReturn(function, BigInteger.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> decreaseAllowance(String spender, BigInteger subtractedValue) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_DECREASEALLOWANCE,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, spender),
+ new org.web3j.abi.datatypes.generated.Uint256(subtractedValue)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<String> factory() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FACTORY,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<String> getOwner() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_GETOWNER,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> increaseAllowance(String spender, BigInteger addedValue) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_INCREASEALLOWANCE,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, spender),
+ new org.web3j.abi.datatypes.generated.Uint256(addedValue)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<String> lpacc() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_LPACC,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> mint(BigInteger amount) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_MINT,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(amount)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<String> name() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_NAME,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<String> owner() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_OWNER,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> renounceOwnership() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_RENOUNCEOWNERSHIP,
+ Arrays.<Type>asList(),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<String> symbol() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_SYMBOL,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
+ return executeRemoteCallSingleValueReturn(function, String.class);
+ }
+
+ public RemoteFunctionCall<BigInteger> totalSupply() {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_TOTALSUPPLY,
+ Arrays.<Type>asList(),
+ Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
+ return executeRemoteCallSingleValueReturn(function, BigInteger.class);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> transfer(String recipient, BigInteger amount) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_TRANSFER,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, recipient),
+ new org.web3j.abi.datatypes.generated.Uint256(amount)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> transferFrom(String sender, String recipient, BigInteger amount) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_TRANSFERFROM,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, sender),
+ new org.web3j.abi.datatypes.Address(160, recipient),
+ new org.web3j.abi.datatypes.generated.Uint256(amount)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ public RemoteFunctionCall<TransactionReceipt> transferOwnership(String newOwner) {
+ final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
+ FUNC_TRANSFEROWNERSHIP,
+ Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, newOwner)),
+ Collections.<TypeReference<?>>emptyList());
+ return executeRemoteCallTransaction(function);
+ }
+
+ @Deprecated
+ public static Abi load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
+ return new Abi(contractAddress, web3j, credentials, gasPrice, gasLimit);
+ }
+
+ @Deprecated
+ public static Abi load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
+ return new Abi(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
+ }
+
+ public static Abi load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
+ return new Abi(contractAddress, web3j, credentials, contractGasProvider);
+ }
+
+ public static Abi load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
+ return new Abi(contractAddress, web3j, transactionManager, contractGasProvider);
+ }
+
+ public static RemoteCall<Abi> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
+ return deployRemoteCall(Abi.class, web3j, credentials, contractGasProvider, BINARY, "");
+ }
+
+ public static RemoteCall<Abi> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
+ return deployRemoteCall(Abi.class, web3j, transactionManager, contractGasProvider, BINARY, "");
+ }
+
+ @Deprecated
+ public static RemoteCall<Abi> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
+ return deployRemoteCall(Abi.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
+ }
+
+ @Deprecated
+ public static RemoteCall<Abi> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
+ return deployRemoteCall(Abi.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
+ }
+
+ public static class ApprovalEventResponse extends BaseEventResponse {
+ public String owner;
+
+ public String spender;
+
+ public BigInteger value;
+ }
+
+ public static class OwnershipTransferredEventResponse extends BaseEventResponse {
+ public String previousOwner;
+
+ public String newOwner;
+ }
+
+ public static class TransferEventResponse extends BaseEventResponse {
+ public String from;
+
+ public String to;
+
+ public BigInteger value;
+ }
+}
diff --git a/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractInit.java b/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractInit.java
new file mode 100644
index 0000000..ea56436
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractInit.java
@@ -0,0 +1,37 @@
+package cc.mrbird.febs.dapp.contract.andao;
+
+import cc.mrbird.febs.common.service.RedisService;
+import cc.mrbird.febs.dapp.mapper.DataDictionaryCustomMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.math.BigInteger;
+
+
+@Component
+public class AndaoContractInit {
+
+ @Autowired
+ private AndaoContractMain andaoContractMain;
+
+ @Autowired
+ private DataDictionaryCustomMapper dataDictionaryCustomMapper;
+
+ @Autowired
+ private RedisService redisService;
+
+
+ @PostConstruct
+ public void init(){
+ // 设置起始区块编号 TODO
+ BigInteger start = new BigInteger("29629081");
+ // 需要打开 获取最新区块编号
+ Object bnb_block_number = redisService.get("BNB_BLOCK_NUMBER");
+ if(bnb_block_number !=null){
+ start = BigInteger.valueOf(Long.valueOf(bnb_block_number.toString()));
+ }
+ System.out.println("启动区块事件监听,监听起始:"+start);
+ andaoContractMain.listenBetting(start);
+ }
+}
diff --git a/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractMain.java b/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractMain.java
new file mode 100644
index 0000000..0ac213a
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/dapp/contract/andao/AndaoContractMain.java
@@ -0,0 +1,169 @@
+package cc.mrbird.febs.dapp.contract.andao;
+
+import cc.mrbird.febs.common.contants.SystemConstants;
+import cc.mrbird.febs.common.service.RedisService;
+import cc.mrbird.febs.rabbit.producer.ChainProducer;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.web3j.crypto.Credentials;
+import org.web3j.protocol.Web3j;
+import org.web3j.protocol.core.DefaultBlockParameterName;
+import org.web3j.protocol.core.DefaultBlockParameterNumber;
+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.tx.gas.DefaultGasProvider;
+import org.web3j.tx.gas.StaticGasProvider;
+import org.web3j.utils.Convert;
+
+import java.math.BigInteger;
+
+
+@Component
+public class AndaoContractMain {
+
+ @Autowired
+ private ChainProducer chainProducer;
+
+ @Autowired
+ private SystemConstants systemConstants;
+
+ private static Web3j web3;
+
+ @Autowired
+ private RedisService redisService;
+
+ private static Web3j getInstance() {
+ if (web3 == null) {
+ HttpService httpService = new HttpService(blockchainNode);
+ web3 = Web3j.build(httpService);
+ }
+ return web3;
+ }
+ // gas费用单价
+ public static final BigInteger GAS_PRICE = Convert.toWei(getGas(), Convert.Unit.GWEI).toBigInteger();
+ // gas费用最大值
+ public static final BigInteger GAS_LIMIT = Convert.toWei("100000", Convert.Unit.WEI).toBigInteger();
+ private static StaticGasProvider getStaticGasProvider(){
+ return new StaticGasProvider(GAS_PRICE,GAS_LIMIT);
+ }
+
+ private static String getGas() {
+ String gas = "5";
+// try{
+// String resp = HttpUtil.get("https://gbsc.blockscan.com/gasapi.ashx?apikey=key&method=gasoracle");
+// JSONObject data = JSONObject.parseObject(resp);
+// gas = data.getString("FastGasPrice");
+// }catch (Exception exception) {
+// exception.printStackTrace();
+// }
+ return StrUtil.isBlank(gas) ? "5" : gas;
+ }
+
+ private static Web3j getInstanceScope() {
+
+ HttpService httpService = new HttpService(blockchainNode);
+ return Web3j.build(httpService);
+ }
+
+ // 区块链节点地址 TODO
+// private static String blockchainNode = "https://bsc-dataseed.binance.org";
+ private static String blockchainNode = "https://bsc-dataseed1.ninicoin.io";
+
+ // 合约地址 TODO
+// private static String contractAddr = "0xb5a1aC0fA05BFb8ad16B231e84b0bAC1d46eAfD0";//测试
+ private static String contractAddr = "0xD88F63aCbcF82cC6D2255b8082D7bdE43b559d00";
+
+ // 操作账号 手续费钱包地址的私钥(合约里会把手续费转到你这个私钥地址上) 用于操作合约内方法 TODO
+ private static String privateKey = "221be67f85375a5af6dd0f4b77fbe877ad2e57e05db201de1b1383fb76494d18";//测试
+
+// private static String privateKey = AppContants.FEE_ADDRESS_KEY.get("feeAddressKey").toString() ;
+
+ private EthFilter getFilter(BigInteger startBlock) {
+ if (startBlock != null) {
+ EthFilter filter = new EthFilter(new DefaultBlockParameterNumber(startBlock),
+ DefaultBlockParameterName.LATEST, contractAddr);
+ return filter;
+ } else {
+ return new EthFilter(DefaultBlockParameterName.EARLIEST,
+ DefaultBlockParameterName.LATEST, contractAddr);
+ }
+ }
+
+
+ /**
+ * 监听投注 参数是起始的区块值
+ */
+ public void listenBetting(BigInteger startBlock){
+ System.out.println("启动投注监听事件");
+ // 指定密钥文件并进行账号和密码的验证
+ Credentials credentials = Credentials.create(privateKey);
+ Abi contract = Abi.load(contractAddr, getInstanceScope(), credentials, new DefaultGasProvider());
+ EthFilter filter = getFilter(startBlock);
+ contract.transferEventFlowable(filter).subscribe(e->{
+ try {
+ // 投注人的地址
+ String from = e.from;
+ String to = e.to;
+ BigInteger amount = e.value;
+ if(from==null){
+ // 为空则不进入后续逻辑
+ return;
+ }
+
+ // TODO 业务操作逻辑代码
+ System.out.println("from:"+from+",to:"+to+",amount:"+amount);
+ // 更新区块编号 TODO
+ redisService.set("BNB_BLOCK_NUMBER",e.log.getBlockNumber().intValue());
+ //投注人
+// DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(from, "BSC");
+// if(ObjectUtil.isNotEmpty(dappMemberEntity)){
+// //投注人是否加入
+// DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectByMemberIdAndState(dappMemberEntity.getId(), DappSystemProfit.STATE_IN);
+// if(ObjectUtil.isNotEmpty(dappSystemProfit)){
+// List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectListByState(DappFundFlowEntity.WITHDRAW_STATUS_ING);
+// if(CollUtil.isNotEmpty(dappFundFlowEntities)){
+// for(DappFundFlowEntity dappFundFlowEntity : dappFundFlowEntities){
+// //发送转币消息
+// chainProducer.sendBnbTransferMsg(dappFundFlowEntity.getId());
+// }
+// }
+// }
+// }
+ }catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ });
+ }
+
+ /**
+ * 从合约内转币到制定地址
+ */
+ public String trans(BigInteger amount, String to1){
+ String transactionHash = null;
+ Credentials credentials = Credentials.create(privateKey);
+ Abi contract = Abi.load(contractAddr, getInstance(), credentials, getStaticGasProvider());
+ try {
+ //BigInteger bigInteger = Convert.toWei(amount.toString(), Convert.Unit.ETHER).toBigInteger();
+ TransactionReceipt send = contract.transfer(to1, amount).send();
+ if(ObjectUtil.isNotEmpty(send)){
+ transactionHash = send.getTransactionHash();
+ }
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ return transactionHash;
+ }
+
+ public static void main(String[] args) {
+ AndaoContractMain andaoContractMain = new AndaoContractMain();
+
+ String address = "0xAdC5331AC7F46c63e877aeC2DFbB5523C7680812";
+// String address = "0x785D5Aa2951Ac4C6f28Dc593AF0b0536Dd3E82Fe";
+ BigInteger bigInteger = new BigInteger(Convert.toWei("1", Convert.Unit.ETHER).setScale(0).toString());
+ String hash = andaoContractMain.trans(bigInteger,address);
+ System.out.println(hash);
+ }
+}
--
Gitblit v1.9.1