| | |
| | | @ApiOperation(value = "转账", notes = "转账") |
| | | @PostMapping(value = "/transfer") |
| | | public FebsResponse transfer(@RequestBody TransferDto transferDto) { |
| | | return null; |
| | | dappWalletService.transfer(transferDto); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "记录列表", notes = "记录列表") |
| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-05-27 |
| | |
| | | @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; |
| | | } |
| | |
| | | |
| | | 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; |
| | |
| | | @TableField(exist = false) |
| | | private String address; |
| | | |
| | | private Integer fee; |
| | | private BigDecimal fee; |
| | | |
| | | private String toHash; |
| | | |
| | | private String fromHash; |
| | | |
| | | private BigDecimal newestPrice; |
| | | |
| | | private BigDecimal targetAmount; |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | 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; |
| | |
| | | fromMember = dappMemberService.insertMember(e.from, null); |
| | | } |
| | | |
| | | // 如果转账对象地址不为源池地址,则创建用户 |
| | | if (!e.to.equals(ADDRESS)) { |
| | | DappMemberEntity toMember = dappMemberDao.selectByAddress(e.to, null); |
| | | if (toMember == null) { |
| | |
| | | } |
| | | } |
| | | |
| | | // |
| | | // 卖币 |
| | | 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); |
| | | } |
| | | |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | |
| | | @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); |
| | | } |
| | | } |
| | |
| | | </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> |