| | |
| | | */ |
| | | @Getter |
| | | public enum ChainEnum { |
| | | /** |
| | | * 以太坊 USDT合约 |
| | | */ |
| | | ETH_USDT("ETH", "0x6c5640c572504a75121e57760909a9dd0E672f2D", |
| | | "77f650768ff50a4243c008fbae1be9ffe74c52908ee9081e2e15f3d3411690bb", |
| | | "https://mainnet.infura.io/v3/f54a5887a3894ebb9425920701a97fe0", |
| | | "0xdac17f958d2ee523a2206206994597c13d831ec7", |
| | | ""), |
| | | |
| | | TRX_USDT("TRX", "TUFzqZRpLwLWJU4jcdf77RKS3Ts2uEhmWL", |
| | | "e08dce7a4626f97b790e791bcdec31cffab46233744bb1aa133f69f98623d3fb", |
| | | "", |
| | | "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", |
| | | "9d461be6-9796-47b9-85d8-b150cbabbb54"), |
| | | |
| | | |
| | | /** |
| | | * 币安 usdt合约 |
| | |
| | | * 币安链 代币合约 |
| | | * 测试链 0xdd92ea2f41d807a60b29004bf7db807d8ac09212 |
| | | * 正式 0x6c6835e60e7dBaD7a60112a6371271e8eb79ee68 https://bsc-dataseed1.ninicoin.io |
| | | * |
| | | */ |
| | | BSC_TFC("BSC", "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25", |
| | | "0xefe98e00cd227b6322e892c82fcbd8eadf119c3188b7e574bc624f65405d61bf", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x46ac4921e58773ca22826df1640672b91b1db2b3", |
| | | BSC_TFC("", "", |
| | | "", |
| | | "", |
| | | "", |
| | | ""), |
| | | |
| | | /** |
| | | * 源池币 |
| | | */ |
| | | BSC_TFC_SOURCE("BSC", "0x4EbDCA102623b46a47042D580dddAdE2a53D057F", |
| | | "0x81c2c02d0c106c1e32ab060a37f6eb279c0649c30ea5cc1c4951e6a8dd4e963c", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x46ac4921e58773ca22826df1640672b91b1db2b3", |
| | | BSC_TFC_SOURCE("", "", |
| | | "", |
| | | "", |
| | | "", |
| | | ""), |
| | | |
| | | /** |
| | | * 源池U |
| | | */ |
| | | BSC_USDT_SOURCE("BSC", "0x4EbDCA102623b46a47042D580dddAdE2a53D057F", |
| | | "0x81c2c02d0c106c1e32ab060a37f6eb279c0649c30ea5cc1c4951e6a8dd4e963c", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x6c6835e60e7dBaD7a60112a6371271e8eb79ee68", |
| | | BSC_USDT_SOURCE("", "", |
| | | "", |
| | | "", |
| | | "", |
| | | ""), |
| | | |
| | | /** |
| | | * 铸池币 |
| | | */ |
| | | BSC_TFC_MAKE("BSC", "0xBae24dAa3aB94cfF8114a16A4267D769b3a651F8", |
| | | "0xc0cabaf5f1fce227e5f1b8a7f83a5dc28972389ffc59559d7852ce8d27c3bec4", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x46ac4921e58773ca22826df1640672b91b1db2b3", |
| | | BSC_TFC_MAKE("", "", |
| | | "", |
| | | "", |
| | | "", |
| | | ""), |
| | | |
| | | /** |
| | | * 技术池 |
| | | */ |
| | | BSC_TFC_TECH("BSC", "0xD998DA7362360eFC6daDFEd6E9a32E70640d7600", |
| | | BSC_TFC_TECH("", "", |
| | | "", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x46ac4921e58773ca22826df1640672b91b1db2b3", |
| | | "", |
| | | "", |
| | | ""), |
| | | |
| | | /** |
| | | * 奖励池 |
| | | */ |
| | | BSC_TFC_REWARD("BSC", "0xf6b06a30196aa5e318232a3b61319eab0fd4a3bf", |
| | | "9378c6a5becdcade151e98b2ee30239bcb11642e362a068a5bc7667f3d17b1fc", |
| | | "https://bsc-dataseed1.ninicoin.io", |
| | | "0x46ac4921e58773ca22826df1640672b91b1db2b3", |
| | | BSC_TFC_REWARD("", "", |
| | | "", |
| | | "", |
| | | "", |
| | | ""); |
| | | |
| | | private String chain; |
| | |
| | | |
| | | private final DappMemberService dappMemberService; |
| | | private final DappSystemService dappSystemService; |
| | | private final DappSimulateDataService dappSimulateDataService; |
| | | |
| | | // @ApiOperation(value = "授权接口", notes = "授权接口") |
| | | // @PostMapping(value = "/approve") |
| | | // public FebsResponse approve(@RequestBody ApproveDto approveDto) { |
| | | // dappMemberService.approve(approveDto); |
| | | // return new FebsResponse().success().message("授权成功"); |
| | | // } |
| | | // |
| | | // @ApiOperation(value = "是否授权接口", notes = "是否授权接口") |
| | | // @GetMapping(value = "/isApprove/{chain}/{address}") |
| | | // public FebsResponse isApprove(@PathVariable("address") String address,@PathVariable("chain") String chain) { |
| | | // return new FebsResponse().success().message("获取成功").data(dappMemberService.isApprove(address, chain)); |
| | | // } |
| | | |
| | | @ApiOperation(value = "链接接口", notes = "链接接口") |
| | | @PostMapping(value = "/connect") |
| | |
| | | return new FebsResponse().success().data(dappWalletService.transfer(transferDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "记录列表", notes = "记录列表") |
| | | @PostMapping(value = "/recordInPage") |
| | | public FebsResponse recordInPage(@RequestBody RecordInPageDto recordInPageDto) { |
| | | return new FebsResponse().success().data(dappWalletService.recordInPage(recordInPageDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "计算最新价", notes = "计算最新价") |
| | | @PostMapping(value = "/calPrice") |
| | | public FebsResponse calPrice(@RequestBody PriceDto priceDto) { |
| | | return new FebsResponse().success().data(dappWalletService.calPrice(priceDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "系统参数", notes = "系统参数") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = SystemDto.class) |
| | | }) |
| | | @GetMapping(value = "/system") |
| | | public FebsResponse system() { |
| | | return new FebsResponse().success().data(dappSystemService.system()); |
| | | } |
| | | |
| | | @ApiOperation(value = "我的团队", notes = "我的团队") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = TeamListVo.class) |
| | | }) |
| | | @PostMapping(value = "/team") |
| | | public FebsResponse team(@RequestBody TeamListDto teamListDto) { |
| | | return new FebsResponse().success().data(dappMemberService.findTeamList(teamListDto)); |
| | | } |
| | | // @ApiOperation(value = "记录列表", notes = "记录列表") |
| | | // @PostMapping(value = "/recordInPage") |
| | | // public FebsResponse recordInPage(@RequestBody RecordInPageDto recordInPageDto) { |
| | | // return new FebsResponse().success().data(dappWalletService.recordInPage(recordInPageDto)); |
| | | // } |
| | | // |
| | | // @ApiOperation(value = "计算最新价", notes = "计算最新价") |
| | | // @PostMapping(value = "/calPrice") |
| | | // public FebsResponse calPrice(@RequestBody PriceDto priceDto) { |
| | | // return new FebsResponse().success().data(dappWalletService.calPrice(priceDto)); |
| | | // } |
| | | // |
| | | // @ApiOperation(value = "系统参数", notes = "系统参数") |
| | | // @ApiResponses({ |
| | | // @ApiResponse(code = 200, message = "success", response = SystemDto.class) |
| | | // }) |
| | | // @GetMapping(value = "/system") |
| | | // public FebsResponse system() { |
| | | // return new FebsResponse().success().data(dappSystemService.system()); |
| | | // } |
| | | // |
| | | // @ApiOperation(value = "我的团队", notes = "我的团队") |
| | | // @ApiResponses({ |
| | | // @ApiResponse(code = 200, message = "success", response = TeamListVo.class) |
| | | // }) |
| | | // @PostMapping(value = "/team") |
| | | // public FebsResponse team(@RequestBody TeamListDto teamListDto) { |
| | | // return new FebsResponse().success().data(dappMemberService.findTeamList(teamListDto)); |
| | | // } |
| | | |
| | | @PostMapping(value = "/logout") |
| | | public FebsResponse logout() { |
| | |
| | | @ApiModelProperty(value = "签名", example = "123") |
| | | private String sign; |
| | | |
| | | // @ApiModelProperty(value = "邀请码", example = "12345678") |
| | | // private String inviteId; |
| | | @ApiModelProperty(value = "邀请码", example = "12345678") |
| | | private String inviteId; |
| | | } |
| | |
| | | } |
| | | |
| | | DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | // 如果此时fromMember为null,则说明该用户未经过转账绑定关系,而是直接注册并购买币,则将关系绑定到顶级账户 |
| | | if (fromMember == null) { |
| | | DappMemberEntity toAddress = dappMemberService.findByAddress(e.to, null); |
| | | fromMember = dappMemberService.insertMember(e.from, toAddress.getInviteId()); |
| | | return; |
| | | } |
| | | |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | |
| | | |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_APPLICATION, "USDT"); |
| | | |
| | | |
| | | // 这个方法主要是处理,tp钱包在调用transfer时,交易详情中的金额可能因为网速慢而显示晚,从而导致实际转账比记录中的少,顾做此处理 |
| | | BigDecimal realCoin = amount.divide(fundFlow.getNewestPrice(), decimals, RoundingMode.HALF_UP); |
| | | if (fundFlow.getAmount().subtract(new BigDecimal("0.1")).compareTo(realCoin) > 0) { |
| | | fundFlow.setAmount(realCoin); |
| | | |
| | | BigDecimal subtract = fundFlow.getAmount().subtract(realCoin); |
| | | BigDecimal poolRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN); |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, poolRemain.add(subtract)); |
| | | } |
| | | |
| | | // 更改状态为已同步 |
| | | fundFlow.setStatus(2); |
| | | fundFlow.setTargetAmount(amount); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | // 如果系统会开启,则使用自动打款 |
| | | if (!"start".equals(hasStart)) { |
| | | OnlineTransferUtil.addTransfer(e.from, fundFlow.getAmount(), 1, 1, ChainEnum.BSC_TFC_MAKE.name(), "BSC", fundFlow.getId().toString()); |
| | | // 查找直推,并判断自身是否大于50,若大于50则,上级推荐则+1 |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", fundFlow.getId().toString()); |
| | | map.put("type", "flow"); |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | |
| | | fromMember.setMakerType(1); |
| | | dappMemberService.updateById(fromMember); |
| | | } else { |
| | | OnlineTransferUtil.addTransfer(e.from, fundFlow.getAmount(), 1, 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, fundFlow.getId().toString()); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", fundFlow.getId().toString()); |
| | | map.put("type", "flow"); |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | |
| | | // 发送购买奖励消息 |
| | | chainProducer.sendUserBuyReward(fundFlow.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf("0x9DDE1834683D642D4D077498DC7fbdb8CF70E8FE")); |
| | | } |
| | | } |
| | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author |
| | | * @author |
| | | * @date 2022-03-17 |
| | | **/ |
| | | @Service |
| | |
| | | |
| | | member.setInviteId(ShareCodeUtil.toSerialCode(member.getId())); |
| | | member.setRefererId(approveDto.getRefererId()); |
| | | if (StrUtil.isNotBlank(approveDto.getRefererId())){ |
| | | if (StrUtil.isNotBlank(approveDto.getRefererId())) { |
| | | boolean flag = false; |
| | | String parentId = approveDto.getRefererId(); |
| | | String ids = ""; |
| | |
| | | break; |
| | | } |
| | | parentId = parentMember.getRefererId(); |
| | | if(StringUtils.isBlank(parentId)){ |
| | | if (StringUtils.isBlank(parentId)) { |
| | | break; |
| | | } |
| | | if (parentMember.getRefererId().equals(parentMember.getInviteId())) { |
| | |
| | | DappMemberEntity member = dappMemberDao.selectByAddress(connectDto.getAddress(), null); |
| | | |
| | | if (member == null) { |
| | | // DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); |
| | | // if (parent == null) { |
| | | // throw new FebsException("邀请人不存在"); |
| | | // } |
| | | DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); |
| | | if (parent == null) { |
| | | throw new FebsException("邀请人不存在"); |
| | | } |
| | | |
| | | member = insertMember(connectDto.getAddress(), null); |
| | | } |
| | | |
| | | // if (member.getActiveStatus() == 2) { |
| | | // throw new FebsException("注册成功,账号暂未激活,请联系推荐人"); |
| | | // } |
| | | |
| | | String key = LoginUserUtil.getLoginKey(connectDto.getAddress(), connectDto.getNonce(), connectDto.getSign()); |
| | | redisUtils.set(connectDto.getAddress(), member); |
| | |
| | | @Override |
| | | public IPage<DappTransferRecordEntity> selectTransferInPage(DappTransferRecordEntity transfer, QueryRequest request) { |
| | | Page<DappTransferRecordEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappTransferRecordDao.selectInPage(transfer,page); |
| | | return dappTransferRecordDao.selectInPage(transfer, page); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | member.setInviteId(ShareCodeUtil.toSerialCode(member.getId())); |
| | | member.setRefererId(refererId); |
| | | if (StrUtil.isNotBlank(refererId)){ |
| | | if (StrUtil.isNotBlank(refererId)) { |
| | | boolean flag = false; |
| | | String parentId = refererId; |
| | | String ids = ""; |
| | |
| | | break; |
| | | } |
| | | parentId = parentMember.getRefererId(); |
| | | if(StringUtils.isBlank(parentId) || "0".equals(parentId)){ |
| | | if (StringUtils.isBlank(parentId) || "0".equals(parentId)) { |
| | | break; |
| | | } |
| | | if (parentMember.getRefererId().equals(parentMember.getInviteId())) { |
| | |
| | | public Long transfer(TransferDto transferDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | if (member.getActiveStatus() == 2) { |
| | | throw new FebsException("请联系邀请人转币激活"); |
| | | } |
| | | |
| | | // 每日出U剩余量(卖币) |
| | | BigDecimal usdtRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN); |
| | | // 用户24小时可出售量 |
| | | BigDecimal saleCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress()); |
| | | BigDecimal buyCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN); |
| | | // 铸池中的币的剩余量 |
| | | BigDecimal makeCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_MAKE_POOL_CNT); |
| | | |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | if (transferDto.getId() == null) { |
| | | if (DappFundFlowEntity.TYPE_SALE == transferDto.getType()) { |
| | | if (!"start".equals(hasStart)) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_001")); |
| | | } |
| | | |
| | | if (transferDto.getAmount().multiply(transferDto.getPrice()).compareTo(usdtRemain) > 0) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_002")); |
| | | } |
| | | |
| | | if (transferDto.getAmount().compareTo(saleCoinRemain) > 0) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_003")); |
| | | } |
| | | |
| | | usdtRemain = usdtRemain.subtract(transferDto.getAmount().multiply(transferDto.getPrice())); |
| | | saleCoinRemain = saleCoinRemain.subtract(transferDto.getAmount()); |
| | | |
| | | // 修改当日U剩余量 |
| | | redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, usdtRemain); |
| | | // 修改用户24小时可售量 |
| | | redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), saleCoinRemain); |
| | | } else if (DappFundFlowEntity.TYPE_BUY == transferDto.getType()) { |
| | | if ("start".equals(hasStart)) { |
| | | if (transferDto.getAmount().compareTo(buyCoinRemain) > 0) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_004")); |
| | | } |
| | | buyCoinRemain = buyCoinRemain.subtract(transferDto.getAmount()); |
| | | |
| | | // 修改当日可购买量 |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, buyCoinRemain); |
| | | // 如果系统还没有启动,则判断铸池中的剩余量 |
| | | } else { |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MAKER_MIN_LIMIT); |
| | | if (transferDto.getAmount().compareTo(new BigDecimal(dic.getValue())) < 0) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_005")); |
| | | } |
| | | |
| | | if (transferDto.getAmount().compareTo(makeCoinRemain) > 0) { |
| | | throw new FebsException(MessageSourceUtils.getString("transfer_msg_006")); |
| | | } |
| | | makeCoinRemain = makeCoinRemain.subtract(transferDto.getAmount()); |
| | | |
| | | // 修改铸池量 |
| | | redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, makeCoinRemain); |
| | | } |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), transferDto.getType(), 1, transferDto.getFee(), transferDto.getTxHash()); |
| | | fundFlow.setNewestPrice(transferDto.getPrice()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | |
| | | } else { |
| | | DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId()); |
| | | if (flow.getStatus() == 1) { |
| | | if (DappFundFlowEntity.TYPE_BUY == flow.getType()) { |
| | | if ("start".equals(hasStart)) { |
| | | buyCoinRemain = buyCoinRemain.add(flow.getAmount()); |
| | | |
| | | // 修改当日可购买量 |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, buyCoinRemain); |
| | | } else { |
| | | makeCoinRemain = makeCoinRemain.add(flow.getAmount()); |
| | | |
| | | // 修改铸池量 |
| | | redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, makeCoinRemain); |
| | | } |
| | | } else { |
| | | usdtRemain = usdtRemain.add(transferDto.getAmount().multiply(transferDto.getPrice())); |
| | | saleCoinRemain = saleCoinRemain.add(transferDto.getAmount()); |
| | | |
| | | // 修改当日U剩余量 |
| | | redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, usdtRemain); |
| | | // 修改用户24小时可售量 |
| | | redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), saleCoinRemain); |
| | | } |
| | | dappFundFlowDao.deleteById(transferDto.getId()); |
| | | } |
| | | } |
| | |
| | | BigInteger end = block.add(section); |
| | | log.info("监听:[{} - {}]", block, end); |
| | | ChainService.contractEventListener(block, end, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | ChainService.contractEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); |
| | | // ChainService.contractEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); |
| | | |
| | | block = block.add(section); |
| | | if (block.compareTo(newest) > 0) { |
| | |
| | | } |
| | | } |
| | | ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); |
| | | // ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); |
| | | |
| | | long end = System.currentTimeMillis(); |
| | | log.info("区块链监听启动完成, 消耗时间{}", end - start); |