| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractEventService; |
| | | import cc.mrbird.febs.dapp.chain.EthUsdtContract; |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class BscUsdtContractEvent implements ContractEventService { |
| | | |
| | | @Resource |
| | | private DappMemberService dappMemberService; |
| | | |
| | | @Resource |
| | | private DappFundFlowDao dappFundFlowDao; |
| | | |
| | | private final String ADDRESS = "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25"; |
| | | |
| | | @Override |
| | | public void compile(EthUsdtContract.TransferEventResponse e) { |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_USDT.name()).decimals(); |
| | | int tfcDecimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals(); |
| | | if (ADDRESS.equals(e.to)) { |
| | | DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | if (fromMember == null) { |
| | | fromMember = dappMemberService.insertMember(e.from, null); |
| | | } |
| | | |
| | | BigInteger tokens = e.tokens; |
| | | BigDecimal amount = BigDecimal.valueOf(tokens.intValue()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectByFromHash(e.log.getTransactionHash(), 1); |
| | | |
| | | BigDecimal newPrice = fundFlow.getNewestPrice(); |
| | | BigDecimal transferAmount = amount.divide(newPrice, tfcDecimals, RoundingMode.HALF_DOWN); |
| | | |
| | | // 更改状态为已同步 |
| | | fundFlow.setStatus(2); |
| | | fundFlow.setTargetAmount(transferAmount); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | // BigDecimal transferAmount = amount.multiply(newPrice); |
| | | // String hash = ChainService.getInstance(ChainEnum.BSC_TFC.name()).transfer(e.from, transferAmount); |
| | | // fundFlow.setToHash(hash); |
| | | // dappFundFlowDao.updateById(fundFlow); |
| | | } |
| | | } |
| | | } |