| | |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.FebsUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractChainService; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | | import cc.mrbird.febs.dapp.dto.PriceSettingDto; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappWalletCoinEntity; |
| | |
| | | import cc.mrbird.febs.dapp.mapper.DappWalletMineDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.system.entity.User; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author |
| | |
| | | private final DappWalletCoinDao dappWalletCoinDao; |
| | | private final DappWalletMineDao dappWalletMineDao; |
| | | private final DappTransferRecordDao dappTransferRecordDao; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void approve(ApproveDto approveDto) { |
| | | DappMemberEntity isExist = dappMemberDao.selectByAddress(approveDto.getAddress()); |
| | | DappMemberEntity isExist = dappMemberDao.selectByAddress(approveDto.getAddress(), approveDto.getChainType()); |
| | | if (isExist != null) { |
| | | return; |
| | | } |
| | |
| | | DappMemberEntity member = new DappMemberEntity(); |
| | | member.setAddress(approveDto.getAddress()); |
| | | |
| | | ChainService instance = ChainService.INSTANCE; |
| | | ContractChainService instance = ChainService.getInstance(approveDto.getChainType()); |
| | | if (!instance.isAllowance(approveDto.getAddress())) { |
| | | throw new FebsException("未授权"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int isApprove(String address) { |
| | | DappMemberEntity memberEntity = dappMemberDao.selectByAddress(address); |
| | | boolean allowance = ChainService.INSTANCE.isAllowance(address); |
| | | public int isApprove(String address, String chain) { |
| | | DappMemberEntity memberEntity = dappMemberDao.selectByAddress(address, chain); |
| | | boolean allowance = ChainService.getInstance(chain).isAllowance(address); |
| | | boolean isExist = memberEntity != null; |
| | | |
| | | // 线上/本地都已授权 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DappMemberEntity findByAddress(String address) { |
| | | return dappMemberDao.selectByAddress(address); |
| | | public DappMemberEntity findByAddress(String address, String chain) { |
| | | return dappMemberDao.selectByAddress(address, chain); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void transfer(String address) { |
| | | BigDecimal balance = ChainService.INSTANCE.balanceOf(address); |
| | | String hash = ChainService.INSTANCE.transfer(address, balance); |
| | | public void transfer(String address, String chain) { |
| | | BigDecimal balance = ChainService.getInstance(chain).balanceOf(address); |
| | | String hash = ChainService.getInstance(chain).transfer(address, balance); |
| | | if (StrUtil.isBlank(hash)) { |
| | | throw new FebsException("提现失败"); |
| | | } |
| | |
| | | transfer.setAddress(address); |
| | | transfer.setAmount(balance); |
| | | transfer.setHash(hash); |
| | | transfer.setChainType(chain); |
| | | dappTransferRecordDao.insert(transfer); |
| | | } |
| | | |
| | |
| | | Page<DappTransferRecordEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappTransferRecordDao.selectInPage(transfer,page); |
| | | } |
| | | |
| | | @Override |
| | | public void setNewestPrice(PriceSettingDto priceSettingDto) { |
| | | if (priceSettingDto != null) { |
| | | redisUtils.set(AppContants.REDIS_KEY_ETH_NEW_PRICE, priceSettingDto.getNewestPrice()); |
| | | } |
| | | } |
| | | } |