| | |
| | | <version>4.3.5</version> |
| | | </dependency> |
| | | <!-- submail邮件 end --> |
| | | |
| | | <!-- 引入poi,解析workbook视图 --> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi</artifactId> |
| | | <version>3.16</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.apache.poi</groupId> |
| | | <artifactId>poi-ooxml</artifactId> |
| | | <version>3.14</version> |
| | | </dependency> |
| | | <!-- 处理excel和上面功能是一样的--> |
| | | <dependency> |
| | | <groupId>net.sourceforge.jexcelapi</groupId> |
| | | <artifactId>jxl</artifactId> |
| | | <version>2.6.10</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.xcong.excoin.modules.blackchain.service.*;
|
| | | import com.xcong.excoin.modules.coin.dao.TrcAddressDao;
|
| | | import com.xcong.excoin.modules.coin.entity.TrcAddressEntity;
|
| | | import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer;
|
| | | import com.xcong.excoin.utils.TRC20ApiUtils;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | |
| | | MemberDao memberDao;
|
| | | @Resource
|
| | | MemberCoinAddressDao memberMapper;
|
| | | @Resource
|
| | | private TrcAddressDao trcAddressDao;
|
| | |
|
| | | @Resource
|
| | | private UsdtUpdateProducer usdtUpdateProducer;
|
| | |
| | |
|
| | | if ("USDT".equals(symbol)) {
|
| | | memberCoinAddress = memberMapper.selectBlockAddressWithTag(Long.parseLong(mId), symbol, lable);
|
| | |
|
| | | TrcAddressEntity srcAddressEntity = trcAddressDao.selectSrcAddressByMemberId(member.getId());
|
| | | if (srcAddressEntity != null) {
|
| | | map.put("trc20_address", srcAddressEntity.getAddress());
|
| | | map.put("trc20_label", "TRC20");
|
| | | } else {
|
| | | // 分布式redis锁
|
| | | for (;;) {
|
| | | boolean flag = redisUtil.setNotExist("LOCK_TRC20", 1, 5);
|
| | | if (!flag) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | TrcAddressEntity address = trcAddressDao.selectOneSrcAddressUnUse();
|
| | | address.setMemberId(member.getId());
|
| | | address.setIsUse(1);
|
| | |
|
| | | TRC20ApiUtils.createWallet(member.getId(), member.getInviteId(), "USDT", address.getAddress());
|
| | | trcAddressDao.updateById(address);
|
| | |
|
| | | map.put("trc20_address", address.getAddress());
|
| | | map.put("trc20_label", "TRC20");
|
| | | break;
|
| | | }
|
| | | }
|
| | | } else {
|
| | | memberCoinAddress = memberMapper.selectBlockAddress(Long.parseLong(mId), symbol);
|
| | | }
|
| | |
| | | } |
| | | } else { |
| | | String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE,gasPrice); |
| | | log.info("转手续费:{}", hash); |
| | | log.info("转手续费:{}, address: {}", hash, address); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.xcong.excoin.modules.platform.dao.PlatformSymbolsCoinDao; |
| | | import com.xcong.excoin.modules.platform.entity.PlatformFeeSettingEntity; |
| | | import com.xcong.excoin.modules.platform.entity.PlatformSymbolsCoinEntity; |
| | | import com.xcong.excoin.utils.MessageSourceUtils; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import com.xcong.excoin.utils.ShareCodeUtil; |
| | | import com.xcong.excoin.utils.ThreadPoolUtils; |
| | | import com.xcong.excoin.utils.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | BigDecimal coinNumber = memberSubmitCoinApplyDto.getCoinNumber(); |
| | | if (availableBalance.compareTo(BigDecimal.ZERO) > 0 |
| | | && availableBalance.compareTo(coinNumber) >= 0) { |
| | | //新增提币记录 |
| | | //新增提币记录 |
| | | MemberCoinWithdrawEntity memberCoinWithdrawEntity = new MemberCoinWithdrawEntity(); |
| | | memberCoinWithdrawEntity.setAddress(memberSubmitCoinApplyDto.getAddress()); |
| | | memberCoinWithdrawEntity.setAmount(coinNumber); |
| | |
| | | memberCoinWithdrawEntity.setMemberId(memberId); |
| | | memberCoinWithdrawEntity.setStatus(MemberCoinWithdrawEntity.STATUS_DOING); |
| | | |
| | | if ("TRC20".equals(memberSubmitCoinApplyDto.getLable()) && CoinTypeEnum.USDT.name().equals(memberSubmitCoinApplyDto.getSymbol())) { |
| | | String orderNo = commonservice.generateOrderNo(memberId); |
| | | TRC20ApiUtils.coinApply(orderNo, memberId.toString(), CoinTypeEnum.USDT.name(), coinNumber.toPlainString(), memberSubmitCoinApplyDto.getAddress()); |
| | | memberCoinWithdrawEntity.setTag(orderNo); |
| | | memberCoinWithdrawEntity.setLabel("TRC20"); |
| | | } |
| | | |
| | | Map<String, Object> columnMap = new HashMap<>(); |
| | | columnMap.put("symbol", memberSubmitCoinApplyDto.getSymbol()); |
| | | columnMap.put("address", memberSubmitCoinApplyDto.getAddress()); |
| | |
| | | package com.xcong.excoin.quartz.job;/** |
| | | * |
| | | * @author wzy |
| | | * @date 2020-11-05 |
| | | **/ |
| | | package com.xcong.excoin.quartz.job; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity; |
| | | import com.xcong.excoin.utils.TRC20ApiUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-11-05 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | public class TRC20OrderJob { |
| | | |
| | | @Resource |
| | | private MemberCoinWithdrawDao memberCoinWithdrawDao; |
| | | |
| | | public void trc20WithdrawOrder() { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("label", "TRC20"); |
| | | param.put("status", 1); |
| | | List<MemberCoinWithdrawEntity> withdrawEntities = memberCoinWithdrawDao.selectByMap(param); |
| | | if (CollUtil.isNotEmpty(withdrawEntities)) { |
| | | for (MemberCoinWithdrawEntity withdrawEntity : withdrawEntities) { |
| | | String applyOrderInfo = TRC20ApiUtils.getApplyOrderInfo(withdrawEntity.getTag()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.common.exception.GlobalException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | |
| | | * @author wzy |
| | | * @date 2020-11-05 |
| | | **/ |
| | | @Slf4j |
| | | public class TRC20ApiUtils { |
| | | private static final String SRC_API = "http://27.50.59.35:5002/"; |
| | | private static final String TRC20_API = "http://27.50.59.35:5002/"; |
| | | private static final String SIGN_STR = "w@a!llokmet"; |
| | | |
| | | public static void apply() { |
| | | /** |
| | | * 提币申请 |
| | | */ |
| | | public static void coinApply(String orderNo, String userId, String symbol, String amount, String toAddress) { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | String orderNo = "123445"; |
| | | String userid = "11"; |
| | | String symbol = "USDT"; |
| | | String amount = "1"; |
| | | String toAddress = "Ox"; |
| | | param.put("orderno", orderNo); |
| | | param.put("userid", userid); |
| | | param.put("userid", userId); |
| | | param.put("symbol", symbol); |
| | | param.put("toAddress", toAddress); |
| | | param.put("amount", new BigDecimal(amount)); |
| | | param.put("sign", SecureUtil.md5(orderNo + userid + symbol + amount + toAddress + SIGN_STR)); |
| | | HttpRequest request = HttpRequest.post(SRC_API + "transout/created"); |
| | | param.put("sign", SecureUtil.md5(orderNo + userId + symbol + amount + toAddress + SIGN_STR)); |
| | | HttpRequest request = HttpRequest.post(TRC20_API + "transout/created"); |
| | | String body = request.body(JSONObject.toJSONString(param)).execute().body(); |
| | | System.out.println(body); |
| | | if (!"200".equals(JSONObject.parseObject(body).getString("code"))) { |
| | | log.error("TRC20提币申请失败 : {}", body); |
| | | throw new GlobalException("提币申请失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提币订单查询 |
| | | * |
| | | * @param orderNo 订单编号 |
| | | */ |
| | | public static String getApplyOrderInfo(String orderNo) { |
| | | String body = HttpRequest.get(TRC20_API + "transout/gettransout?orderNo=" + orderNo).execute().body(); |
| | | if (!"200".equals(JSONObject.parseObject(body).getString("code"))) { |
| | | log.error("TRC20获取订单失败:{}, {}", orderNo, body); |
| | | throw new GlobalException("获取订单失败"); |
| | | } |
| | | |
| | | return JSONObject.parseObject(body).getString("row"); |
| | | } |
| | | |
| | | public static void createWallet(Long userId, String userName, String symbol, String address) { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("userId", userId); |
| | | param.put("symbol", symbol); |
| | | param.put("userName", userName); |
| | | param.put("walletAddress", address); |
| | | param.put("accountFlag", 1); |
| | | param.put("sign", SecureUtil.md5(userId + symbol + address + SIGN_STR)); |
| | | String body = HttpRequest.post(TRC20_API + "account/created").body(JSONObject.toJSONString(param)).execute().body(); |
| | | if (!"200".equals(JSONObject.parseObject(body).getString("code"))) { |
| | | log.error("TRC20创建钱包失败:{}, {}, {}", userId, address, body); |
| | | throw new GlobalException("获取订单失败"); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | createWallet(1L, "1", "USDT", "11"); |
| | | } |
| | | } |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?>
|
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
| | | <mapper namespace="com.xcong.excoin.modules.coin.dao.MemberSelectSymbolsDao">
|
| | | |
| | | <select id="selectSymbolByMemIdAndSymbol" resultType="com.xcong.excoin.modules.member.entity.MemberSelectSymbolsEntity">
|
| | | select id id,symbol symbol,member_id memberId from member_select_symbols where member_id = #{memberId} and symbol = #{symbol}
|
| | | </select>
|
| | | |
| | | <select id="selectSymbolByMemId" resultType="com.xcong.excoin.modules.member.entity.MemberSelectSymbolsEntity">
|
| | | select id id,symbol symbol,member_id memberId from member_select_symbols where member_id = #{memberId} GROUP BY symbol
|
| | | </select>
|
| | | |
| | | <mapper namespace="com.xcong.excoin.modules.coin.dao.TrcAddressDao">
|
| | |
|
| | | <select id="selectSrcAddressByMemberId" resultType="com.xcong.excoin.modules.coin.entity.TrcAddressEntity">
|
| | | select * from trc_address where member_id=#{memberId} and is_use=1
|
| | | </select>
|
| | |
|
| | | <select id="selectOneSrcAddressUnUse" resultType="com.xcong.excoin.modules.coin.entity.TrcAddressEntity">
|
| | | select * from trc_address where is_use=2 limit 1
|
| | | </select>
|
| | | </mapper> |
| | |
| | | package com.xcong.excoin;/** |
| | | * |
| | | * @author wzy |
| | | * @date 2020-11-04 |
| | | **/ |
| | | package com.xcong.excoin; |
| | | |
| | | import com.xcong.excoin.modules.blackchain.service.EthUsdtContract; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | 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.http.HttpService; |
| | | import org.web3j.tx.gas.StaticGasProvider; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-11-04 |
| | | **/ |
| | | @Slf4j |
| | | public class FilterTest { |
| | | |
| | | |
| | | public static BigInteger GAS_PRICE = BigInteger.valueOf(45000000000L); |
| | | //public static final BigInteger GAS_LIMIT = BigInteger.valueOf(4300000L); |
| | | public static final BigInteger GAS_LIMIT = BigInteger.valueOf(2000000L); |
| | | |
| | | private static Web3j web3; |
| | | |
| | | private static String blockchainNode = "http://114.55.250.231:8545"; |
| | | |
| | | private static String contractAddr = "0xdac17f958d2ee523a2206206994597c13d831ec7"; |
| | | |
| | | |
| | | // 操作账号 |
| | | private static String privateKey = "4576fafdd215f52051c60e04618ef8997fbc5cee8413d3b34d210e296e6e9a3d"; |
| | | @Test |
| | | public void testAA() { |
| | | BigInteger blockNum = new BigInteger("11189995"); |
| | | Credentials credentials = Credentials.create(privateKey); |
| | | EthUsdtContract contract = EthUsdtContract.load(contractAddr, getInstance(), credentials, getStaticGasProvider()); |
| | | EthFilter filter = getFilter(blockNum); |
| | | Map<String,BigInteger> map = new HashMap<String,BigInteger>(); |
| | | map.put("blockNum",blockNum); |
| | | |
| | | contract.transferEventFlowable(filter).subscribe(e->{ |
| | | // System.out.println(1); |
| | | // Thread.sleep(60); |
| | | // System.out.println(2); |
| | | }); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BigInteger blockNum = new BigInteger("11190135"); |
| | | Credentials credentials = Credentials.create(privateKey); |
| | | EthUsdtContract contract = EthUsdtContract.load(contractAddr, getInstance(), credentials, getStaticGasProvider()); |
| | | EthFilter filter = getFilter(blockNum); |
| | | Map<String,BigInteger> map = new HashMap<String,BigInteger>(); |
| | | map.put("blockNum",blockNum); |
| | | |
| | | contract.transferEventFlowable(filter).subscribe(e->{ |
| | | Thread.sleep(120); |
| | | }); |
| | | } |
| | | |
| | | private static Web3j getInstance() { |
| | | if (web3 == null) { |
| | | HttpService httpService = new HttpService(blockchainNode); |
| | | web3 = Web3j.build(httpService); |
| | | } |
| | | return web3; |
| | | } |
| | | |
| | | private static 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); |
| | | } |
| | | } |
| | | |
| | | private static StaticGasProvider getStaticGasProvider(){ |
| | | return new StaticGasProvider(GAS_PRICE,GAS_LIMIT); |
| | | } |
| | | } |
| | |
| | | import lombok.extern.slf4j.Slf4j;
|
| | |
|
| | | @Slf4j
|
| | | @SpringBootTest
|
| | | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
| | | public class GuijiTest {
|
| | |
|
| | | private static final BigDecimal LIMIT = new BigDecimal("50");
|
| | |
| | | @Resource
|
| | | private MemberWalletCoinDao memberWalletCoinDao;
|
| | |
|
| | | @Test
|
| | | public void poolTest() {
|
| | | String address = "0x19177bfd062852a4398cae3ab701a82a6b959bf2";
|
| | | EthService ethService = new EthService();
|
| | | BigDecimal balance = ethService.tokenGetBalance(address);
|
| | | BigDecimal eth = EthService.getEthBlance(address);
|
| | |
|
| | | log.info("--->{}, {}", balance, eth);
|
| | | }
|
| | |
|
| | | public void pool() throws ExecutionException, InterruptedException {
|
| | | //List<MemberCoinChargeEntity> list = memberCoinChargeDao.selectAllBySymbolAndTag(CoinTypeEnum.USDT.name(), "ERC20", 1);
|
| | | List<MemberCoinChargeEntity> list = new ArrayList<MemberCoinChargeEntity>();
|
| | |
| | | package com.xcong.excoin;/** |
| | | * |
| | | * @author wzy |
| | | * @date 2020-11-05 |
| | | **/ |
| | | package com.xcong.excoin; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.coin.dao.TrcAddressDao; |
| | | import com.xcong.excoin.modules.coin.entity.TrcAddressEntity; |
| | | import com.xcong.excoin.utils.TRC20ApiUtils; |
| | | import org.apache.catalina.security.SecurityUtil; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-11-05 |
| | | **/ |
| | | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| | | public class SRCTest { |
| | | |
| | | private static final String SRC_API = "http://27.50.59.35:5002/"; |
| | | |
| | | private static final String SIGN_STR = "w@a!llokmet"; |
| | | |
| | | public static void main(String[] args) { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | String orderNo = "123445"; |
| | | String userid = "11"; |
| | | String symbol = "USDT"; |
| | | String amount = "1"; |
| | | String toAddress = "Ox"; |
| | | param.put("orderno", orderNo); |
| | | param.put("userid", userid); |
| | | param.put("symbol", symbol); |
| | | param.put("toAddress", toAddress); |
| | | param.put("amount", new BigDecimal(amount)); |
| | | param.put("sign", SecureUtil.md5(orderNo + userid + symbol + amount + toAddress + SIGN_STR)); |
| | | HttpRequest request = HttpRequest.post(SRC_API + "transout/created"); |
| | | String body = request.body(JSONObject.toJSONString(param)).execute().body(); |
| | | System.out.println(body); |
| | | } |
| | | |
| | | private static void sign() { |
| | | |
| | | } |
| | | |
| | | @Autowired |
| | | private TrcAddressDao srcAddressDao; |
| | | |
| | | @Test |
| | | public void addressInsertTest() throws IOException { |
| | | File file = new File("/Users/helius/Desktop/src20.xls"); |
| | | FileInputStream input = new FileInputStream(file); |
| | | |
| | | Workbook wb = null; |
| | | if (file.getName().endsWith(".xls")) { |
| | | wb = new HSSFWorkbook(input); |
| | | } else if (file.getName().endsWith(".xlsx")) { |
| | | wb = new XSSFWorkbook(input); |
| | | } |
| | | |
| | | Sheet sheet = wb.getSheetAt(0); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | for (int i = 0; i < lastRowNum; i++) { |
| | | Row row = sheet.getRow(i); |
| | | Cell cell = row.getCell(0); |
| | | TrcAddressEntity addressEntity = new TrcAddressEntity(); |
| | | addressEntity.setAddress(cell.getStringCellValue().trim()); |
| | | addressEntity.setIsUse(2); |
| | | srcAddressDao.insert(addressEntity); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void createTest() { |
| | | System.out.println(System.currentTimeMillis()); |
| | | TRC20ApiUtils.createWallet(1L, "111111", "USDT", "111111111"); |
| | | System.out.println(System.currentTimeMillis()); |
| | | } |
| | | } |