Helius
2022-05-30 79b15889217d9f6d2ef86ccba0c3ace5055a4b66
add transfer
8 files modified
82 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/dto/TransferDto.java 9 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java 10 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java 27 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 5 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/dapp/DappFundFlowDao.xml 4 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java
@@ -55,7 +55,8 @@
    @ApiOperation(value = "转账", notes = "转账")
    @PostMapping(value = "/transfer")
    public FebsResponse transfer(@RequestBody TransferDto transferDto) {
        return null;
        dappWalletService.transfer(transferDto);
        return new FebsResponse().success();
    }
    @ApiOperation(value = "记录列表", notes = "记录列表")
src/main/java/cc/mrbird/febs/dapp/dto/TransferDto.java
@@ -4,6 +4,8 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @author wzy
 * @date 2022-05-27
@@ -18,6 +20,9 @@
    @ApiModelProperty(value = "交易hash", example = "123")
    private String txHash;
    @ApiModelProperty(value = "地址", example = "0x123")
    private String address;
    @ApiModelProperty(value = "金额", example = "1")
    private BigDecimal amount;
    @ApiModelProperty(value = "手续费", example = "1")
    private BigDecimal fee;
}
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java
@@ -21,11 +21,11 @@
    public DappFundFlowEntity() {}
    public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, Integer fee) {
    public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, BigDecimal fee) {
        new DappFundFlowEntity(memberId, amount, type, status, fee, null);
    }
    public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, Integer fee, String fromHash) {
    public DappFundFlowEntity(Long memberId, BigDecimal amount, Integer type, Integer status, BigDecimal fee, String fromHash) {
        this.memberId = memberId;
        this.amount = amount;
        this.type = type;
@@ -51,9 +51,13 @@
    @TableField(exist = false)
    private String address;
    private Integer fee;
    private BigDecimal fee;
    private String toHash;
    private String fromHash;
    private BigDecimal newestPrice;
    private BigDecimal targetAmount;
}
src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java
@@ -16,4 +16,6 @@
    List<DappFundFlowEntity> selectListForMemberAndDay(@Param("memberId") Long memberId, @Param("type") int type);
    DappFundFlowEntity selectMineFundFlowByMemberIdAndTime(@Param("time") Long memberId, @Param("time") Date time);
    DappFundFlowEntity selectByFromHash(@Param("txHash") String txHash, @Param("status") Integer status);
}
src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java
@@ -34,11 +34,11 @@
    private DappFundFlowDao dappFundFlowDao;
    private final String ADDRESS = "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25";
    int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals();
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void compile(EthUsdtContract.TransferEventResponse e) {
        int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals();
        if (e.to != null) {
            if ("0x0000000000000000000000000000000000000000".equals(e.from)) {
                return;
@@ -49,6 +49,7 @@
                fromMember = dappMemberService.insertMember(e.from, null);
            }
            // 如果转账对象地址不为源池地址,则创建用户
            if (!e.to.equals(ADDRESS)) {
                DappMemberEntity toMember = dappMemberDao.selectByAddress(e.to, null);
                if (toMember == null) {
@@ -56,23 +57,26 @@
                }
            }
            //
            // 卖币
            if (e.to.equals(ADDRESS)) {
                BigInteger tokens = e.tokens;
                BigDecimal amount = BigDecimal.valueOf(tokens.intValue()).divide(BigDecimal.TEN.pow(4), decimals, RoundingMode.HALF_DOWN);
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(fromMember.getId(), amount, 2, null, null, e.log.getTransactionHash());
                dappFundFlowDao.insert(fundFlow);
                BigDecimal amount = BigDecimal.valueOf(tokens.intValue()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
                DappFundFlowEntity fundFlow = dappFundFlowDao.selectByFromHash(e.log.getTransactionHash(), 1);
                // TODO price
                BigDecimal newPrice = BigDecimal.valueOf(1);
                BigDecimal transferAmount = amount.multiply(newPrice);
                String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(e.from, transferAmount);
                fundFlow.setToHash(hash);
                fundFlow.setNewestPrice(newPrice);
                // 更改状态为已同步
                fundFlow.setStatus(2);
                fundFlow.setTargetAmount(transferAmount);
                dappFundFlowDao.updateById(fundFlow);
                //TODO 自动转账
//                String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(e.from, transferAmount);
//                fundFlow.setToHash(hash);
//                dappFundFlowDao.updateById(fundFlow);
            }
        }
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java
@@ -32,26 +32,31 @@
    private DappFundFlowDao dappFundFlowDao;
    private final String ADDRESS = "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25";
    int decimals = ChainService.getInstance(ChainEnum.BSC_USDT.name()).decimals();
    int tfcDecimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals();
    @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 = new DappFundFlowEntity(fromMember.getId(), amount, 2, null, null, e.log.getTransactionHash());
//            dappFundFlowDao.insert(fundFlow);
//
//            // TODO price
//            BigDecimal newPrice = BigDecimal.valueOf(1);
//
            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);
            // TODO price
            BigDecimal newPrice = BigDecimal.valueOf(1);
            BigDecimal transferAmount = amount.divide(newPrice, tfcDecimals, RoundingMode.HALF_DOWN);
            fundFlow.setNewestPrice(newPrice);
            // 更改状态为已同步
            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);
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -117,7 +117,7 @@
        walletCoin.setFrozenAmount(walletCoin.getFrozenAmount().add(walletOperateDto.getAmount()));
        dappWalletCoinDao.updateById(walletCoin);
        DappFundFlowEntity fund = new DappFundFlowEntity(member.getId(), walletOperateDto.getAmount(), AppContants.MONEY_TYPE_WITHDRAWAL, 1, fee);
        DappFundFlowEntity fund = new DappFundFlowEntity(member.getId(), walletOperateDto.getAmount(), AppContants.MONEY_TYPE_WITHDRAWAL, 1, new BigDecimal(fee));
        dappFundFlowDao.insert(fund);
        DappAccountMoneyChangeEntity usdtChange = new DappAccountMoneyChangeEntity(member.getId(), preAmount, walletOperateDto.getAmount(), walletCoin.getAvailableAmount(), "USDT申请提现", AppContants.MONEY_TYPE_WITHDRAWAL);
@@ -193,6 +193,9 @@
    @Override
    public void transfer(TransferDto transferDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), transferDto.getType(), 1, transferDto.getFee(), transferDto.getTxHash());
        dappFundFlowDao.insert(fundFlow);
    }
}
src/main/resources/mapper/dapp/DappFundFlowDao.xml
@@ -34,4 +34,8 @@
          </if>
    </select>
    <select id="selectByFromHash" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where from_hash=#{txHash} and status=#{status}
    </select>
</mapper>