22 files modified
1 files added
| | |
| | | public static final String DIC_VALUE_SYSTEM_START_TARGET = "SYSTEM_START_TARGET";
|
| | | public static final String DIC_VALUE_SYSTEM_SOURCE_POOL_VOL = "SYSTEM_SOURCE_POOL_VOL";
|
| | | public static final String DIC_VALUE_SYSTEM_NODE_CNT_LIMIT = "SYSTEM_NODE_CNT_LIMIT";
|
| | | // 用户购买奖励比例(给上级)
|
| | | public static final String DIC_VALUE_USER_BUY_REWARD = "USER_BUY_REWARD";
|
| | |
|
| | | public static final String DESTROY_ADDRESS = "0x0000000000000000000000000000000000000001";
|
| | |
|
| | |
| | | */ |
| | | BSC_USDT("BSC", "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25", |
| | | "0xefe98e00cd227b6322e892c82fcbd8eadf119c3188b7e574bc624f65405d61bf", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0x337610d27c682E347C9cD60BD4b3b107C9d34dDd", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_TFC("BSC", "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25", |
| | | "0xefe98e00cd227b6322e892c82fcbd8eadf119c3188b7e574bc624f65405d61bf", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0xdd92ea2f41d807a60b29004bf7db807d8ac09212", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_TFC_SOURCE("BSC", "0x4EbDCA102623b46a47042D580dddAdE2a53D057F", |
| | | "0x81c2c02d0c106c1e32ab060a37f6eb279c0649c30ea5cc1c4951e6a8dd4e963c", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0xdd92ea2f41d807a60b29004bf7db807d8ac09212", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_USDT_SOURCE("BSC", "0x4EbDCA102623b46a47042D580dddAdE2a53D057F", |
| | | "0x81c2c02d0c106c1e32ab060a37f6eb279c0649c30ea5cc1c4951e6a8dd4e963c", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0x337610d27c682E347C9cD60BD4b3b107C9d34dDd", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_TFC_MAKE("BSC", "0xBae24dAa3aB94cfF8114a16A4267D769b3a651F8", |
| | | "0xc0cabaf5f1fce227e5f1b8a7f83a5dc28972389ffc59559d7852ce8d27c3bec4", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0xdd92ea2f41d807a60b29004bf7db807d8ac09212", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_TFC_TECH("BSC", "0xD998DA7362360eFC6daDFEd6E9a32E70640d7600", |
| | | "", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0xdd92ea2f41d807a60b29004bf7db807d8ac09212", |
| | | ""), |
| | | |
| | |
| | | */ |
| | | BSC_TFC_REWARD("BSC", "0xBae24dAa3aB94cfF8114a16A4267D769b3a651F8", |
| | | "0xc0cabaf5f1fce227e5f1b8a7f83a5dc28972389ffc59559d7852ce8d27c3bec4", |
| | | "https://data-seed-prebsc-2-s2.binance.org:8545", |
| | | "https://data-seed-prebsc-2-s1.binance.org:8545", |
| | | "0xdd92ea2f41d807a60b29004bf7db807d8ac09212", |
| | | ""); |
| | | |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | ChainEnum chain = ChainEnum.getValueByName(ChainEnum.BSC_TFC.name()); |
| | | assert chain != null; |
| | | // ChainEnum chain = ChainEnum.getValueByName(ChainEnum.BSC_TFC.name()); |
| | | // assert chain != null; |
| | | // |
| | | // EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl()); |
| | | // EthFilter filter = getFilter(new BigInteger("18097238"), chain.getContractAddress()); |
| | | // |
| | | // contract.transferEventFlowable(filter).subscribe(e -> { |
| | | // System.out.println(1); |
| | | // }, error -> { |
| | | // log.error("--->", error); |
| | | // }); |
| | | |
| | | EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl()); |
| | | EthFilter filter = getFilter(new BigInteger("18097238"), chain.getContractAddress()); |
| | | |
| | | contract.transferEventFlowable(filter).subscribe(e -> { |
| | | System.out.println(1); |
| | | }, error -> { |
| | | log.error("--->", error); |
| | | }); |
| | | System.out.println(ChainService.getInstance(ChainEnum.BSC_TFC.name()).totalSupply()); |
| | | } |
| | | |
| | | } |
| | |
| | | int decimals(); |
| | | |
| | | BigInteger blockNumber(); |
| | | |
| | | BigInteger totalSupply(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BigInteger totalSupply() { |
| | | try { |
| | | String methodName = "totalSupply"; |
| | | List<Type> inputParameters = new ArrayList<>(); |
| | | List<TypeReference<?>> outputParameters = new ArrayList<>(); |
| | | TypeReference<Uint256> typeReference = new TypeReference<Uint256>() { |
| | | }; |
| | | outputParameters.add(typeReference); |
| | | Function function = new Function(methodName, inputParameters, outputParameters); |
| | | String data = FunctionEncoder.encode(function); |
| | | Transaction transaction = Transaction.createEthCallTransaction(null, contractAddress, data); |
| | | |
| | | EthCall ethCall; |
| | | BigInteger totalSupply = BigInteger.ZERO; |
| | | try { |
| | | ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).send(); |
| | | List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters()); |
| | | totalSupply = (BigInteger) results.get(0).getValue(); |
| | | return totalSupply.divide(BigInteger.TEN.pow(decimals())); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return BigInteger.ZERO; |
| | | } |
| | | } |
| | |
| | | public BigInteger blockNumber() { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public BigInteger totalSupply() { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | public DappFundFlowEntity() {} |
| | | |
| | | public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, BigDecimal fee) { |
| | | new DappFundFlowEntity(memberId, amount, type, status, fee, null); |
| | | this.memberId = memberId; |
| | | this.amount = amount; |
| | | this.type = type; |
| | | this.status = status; |
| | | this.fee = fee; |
| | | } |
| | | |
| | | public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, BigDecimal fee, String fromHash) { |
| | |
| | | List<DappMemberEntity> selectParentsList(@Param("list") List<String> inviteIds, @Param("size") Integer size); |
| | | |
| | | BigDecimal selectAllBalance(@Param("accountType") String accountType); |
| | | |
| | | List<DappMemberEntity> selectMemberByAccountType(@Param("accountType") String accountType); |
| | | } |
| | |
| | | void mining(); |
| | | |
| | | void onlineTransfer(String batchNo); |
| | | |
| | | /** |
| | | * 用户购买奖励 |
| | | * |
| | | * @param id |
| | | */ |
| | | void userBuyReward(Long id); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | // DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | // if (fromMember == null) { |
| | | // DappMemberEntity sourceAddress = dappMemberDao.selectByAddress(ChainEnum.BSC_TFC.getAddress(), null); |
| | | // fromMember = dappMemberService.insertMember(e.from, sourceAddress.getInviteId()); |
| | | // return; |
| | | // } |
| | | // 更新余额 |
| | | DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | if (fromMember != null) { |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.from); |
| | | fromMember.setBalance(balance); |
| | | dappMemberService.updateById(fromMember); |
| | | } |
| | | |
| | | BigInteger tokens = e.tokens; |
| | | BigDecimal amount = BigDecimal.valueOf(tokens.intValue()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | |
| | | |
| | | if (toMember.getActiveStatus() == 2) { |
| | | toMember.setActiveStatus(1); |
| | | dappMemberService.updateById(toMember); |
| | | } |
| | | // 更新余额 |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.to); |
| | | toMember.setBalance(balance); |
| | | dappMemberService.updateById(toMember); |
| | | |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | } |
| | |
| | | |
| | | // 如果得到触发,则休眠10秒。 因为此处监听器触发可能优先于前端调用transfer接口 |
| | | try { |
| | | Thread.sleep(5000); |
| | | Thread.sleep(10000); |
| | | } catch (InterruptedException ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | |
| | | ContractChainService sourceUsdtInstance = ChainService.getInstance(ChainEnum.BSC_USDT.name()); |
| | | int decimals = sourceUsdtInstance.decimals(); |
| | | int tfcDecimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals(); |
| | | |
| | | if (e.from.equals("0xaa25aa7a19f9c426e07dee59b12f944f4d9f1dd3")) { |
| | | return; |
| | | } |
| | |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | |
| | | // 发送购买奖励消息 |
| | | chainProducer.sendUserBuyReward(fundFlow.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | |
| | | @Override |
| | | public void mining() { |
| | | log.info("挖矿"); |
| | | ContractChainService contract = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | // 发行量 |
| | | BigInteger totalSupply = contract.totalSupply(); |
| | | |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_MINE_ALL_INTERNET_CNT); |
| | | if (o == null) { |
| | | return; |
| | | BigDecimal totalUnHold = contract.balanceOf(AppContants.DESTROY_ADDRESS); |
| | | List<DappMemberEntity> admin = dappMemberDao.selectMemberByAccountType("admin"); |
| | | for (DappMemberEntity member : admin) { |
| | | totalUnHold = totalUnHold.add(contract.balanceOf(member.getAddress())); |
| | | } |
| | | |
| | | Object transferPoolObj = redisUtils.get(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT); |
| | | |
| | | BigDecimal allInternet = (BigDecimal) o; |
| | | // 全网持币量 |
| | | BigDecimal allInternet = new BigDecimal(totalSupply).subtract(totalUnHold); |
| | | // 中转池交易量 |
| | | BigDecimal transferPoll = (BigDecimal) transferPoolObj; |
| | | |
| | | List<DappMemberEntity> allMembers = dappMemberDao.selectList(null); |
| | |
| | | continue; |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), mine, 3, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | OnlineTransferUtil.addTransfer(member.getAddress(), mine, 3, 1, ChainEnum.BSC_TFC.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | member.setBalance(balance); |
| | | dappMemberDao.updateById(member); |
| | | } |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void userBuyReward(Long id) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id); |
| | | |
| | | DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId()); |
| | | DappMemberEntity referer = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if (referer == null || "admin".equals(referer.getAccountType())) { |
| | | return; |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_USER_BUY_REWARD); |
| | | BigDecimal prop = new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP); |
| | | BigDecimal reward = fundFlow.getAmount().multiply(prop); |
| | | |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC_REWARD.name()).balanceOf(ChainEnum.BSC_TFC_REWARD.getAddress()); |
| | | if (balance.compareTo(reward) < 1) { |
| | | return; |
| | | } |
| | | |
| | | DappFundFlowEntity rewardFlow = new DappFundFlowEntity(referer.getId(), reward, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(rewardFlow); |
| | | |
| | | OnlineTransferUtil.addTransfer(referer.getAddress(), reward, 4, 1, ChainEnum.BSC_TFC_REWARD.name(), AppContants.SYMBOL_COIN, rewardFlow.getId().toString()); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", rewardFlow.getId().toString()); |
| | | map.put("type", "batch"); |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | } |
| | |
| | | package cc.mrbird.febs.dapp.utils; |
| | | |
| | | import cc.mrbird.febs.common.utils.SpringContextUtil; |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappOnlineTransferEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappOnlineTransferDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappTransferRecordDao; |
| | | |
| | |
| | | public static void addTransferRecord(String fromAddress, String toAddress, BigDecimal amount, String hash, String sourceFlag, String symbol) { |
| | | addTransferRecord(fromAddress, toAddress, amount, hash, "BSC", sourceFlag, symbol); |
| | | } |
| | | |
| | | } |
| | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Scheduled(cron = "0 0 2 * * ? ") |
| | | // @Scheduled(cron = "0 0 2 * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void start() { |
| | | log.info("返利执行"); |
New file |
| | |
| | | package cc.mrbird.febs.job; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-06-09 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | public class SystemInit { |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | log.info("系统参数初始化"); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Scheduled(cron = "0 0 2 * * ?") |
| | | public void mineJob() { |
| | | log.info("挖矿"); |
| | | systemService.mining(); |
| | | } |
| | | } |
| | |
| | | |
| | | public static final String ONLINE_TRANSFER = "queue_online_transfer"; |
| | | public static final String DISTRIB_PROFIT = "queue_distrib_profit"; |
| | | public static final String USER_BUY_REWARD = "queue_user_buy_reward"; |
| | | } |
| | |
| | | public enum QueueEnum { |
| | | |
| | | ONLINE_TRANSFER("exchange_online_transfer", "route_key_online_transfer", "queue_online_transfer"), |
| | | DISTRIB_PROFIT("exchange_distrib_profit", "route_key_distrib_profit", "queue_distrib_profit"); |
| | | DISTRIB_PROFIT("exchange_distrib_profit", "route_key_distrib_profit", "queue_distrib_profit"), |
| | | USER_BUY_REWARD("exchange_user_buy_reward", "route_key_user_buy_reward", "queue_user_buy_reward"); |
| | | |
| | | private String exchange; |
| | | |
| | |
| | | public Binding distribProfitBind() { |
| | | return BindingBuilder.bind(distribProfitQueue()).to(distribProfitExchange()).with(QueueEnum.DISTRIB_PROFIT.getRoute()); |
| | | } |
| | | |
| | | // === 用户购买奖励 start === |
| | | @Bean |
| | | public DirectExchange userBuyRewardExchange() { |
| | | return new DirectExchange(QueueEnum.USER_BUY_REWARD.getExchange()); |
| | | } |
| | | |
| | | @Bean |
| | | public Queue userBuyRewardQueue() { |
| | | return new Queue(QueueEnum.USER_BUY_REWARD.getQueue()); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding userBuyRewardBind() { |
| | | return BindingBuilder.bind(userBuyRewardQueue()).to(userBuyRewardExchange()).with(QueueEnum.USER_BUY_REWARD.getRoute()); |
| | | } |
| | | // === 用户购买奖励 end === |
| | | } |
| | |
| | | log.info("收到滑点分配消息:{}", id); |
| | | dappSystemService.tradeProfitDistribute(Long.parseLong(id)); |
| | | } |
| | | |
| | | @RabbitListener(queues = QueueConstants.USER_BUY_REWARD) |
| | | public void userBuyReward(String id) { |
| | | log.info("收到用户购买奖励消息:{}", id); |
| | | dappSystemService.userBuyReward(Long.parseLong(id)); |
| | | } |
| | | } |
| | |
| | | CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); |
| | | rabbitTemplate.convertAndSend(QueueEnum.DISTRIB_PROFIT.getExchange(), QueueEnum.DISTRIB_PROFIT.getRoute(), id, correlationData); |
| | | } |
| | | |
| | | public void sendUserBuyReward(Long id) { |
| | | log.info("发送用户购买奖励消息:{}", id); |
| | | CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); |
| | | rabbitTemplate.convertAndSend(QueueEnum.USER_BUY_REWARD.getExchange(), QueueEnum.USER_BUY_REWARD.getRoute(), id, correlationData); |
| | | } |
| | | } |
| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectMemberByAccountType" resultType="cc.mrbird.febs.dapp.entity.DappMemberEntity"> |
| | | select * from dapp_member |
| | | <where> |
| | | account_type=#{accountType} |
| | | </where> |
| | | </select> |
| | | </mapper> |
| | |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractChainService; |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappOnlineTransferEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappOnlineTransferDao; |
| | | import cc.mrbird.febs.job.SystemTradeJob; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | @Test |
| | | public void totalSupplyTest() { |
| | | System.out.println(ChainService.getInstance(ChainEnum.BSC_TFC.getChain()).totalSupply()); |
| | | } |
| | | |
| | | @Test |
| | | public void mineTest() { |
| | | systemTradeJob.mineJob(); |
| | | } |
| | | |
| | | @Autowired |
| | | private DappFundFlowDao dappFundFlowDao; |
| | | |
| | | @Test |
| | | public void fundFlowInsertTest() { |
| | | DappFundFlowEntity rewardFlow = new DappFundFlowEntity(11L, BigDecimal.valueOf(1L), 4, 2, BigDecimal.ZERO); |
| | | rewardFlow.setFromHash("1"); |
| | | dappFundFlowDao.insert(rewardFlow); |
| | | } |
| | | |
| | | @Test |
| | | public void userBuyRewardTest() { |
| | | chainProducer.sendUserBuyReward(56L); |
| | | } |
| | | } |