7 files modified
4 files added
| | |
| | | package cc.mrbird.febs.dapp.chain; |
| | | |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | |
| | | return Integer.parseInt(total); |
| | | } |
| | | |
| | | public void transfer(String address) { |
| | | public String transfer(String address) { |
| | | BigDecimal amount = balanceOf(address); |
| | | |
| | | return transfer(address, amount); |
| | | } |
| | | |
| | | public String transfer(String address, BigDecimal amount) { |
| | | String hash; |
| | | if (address.contains(ETH_PREFIX)) { |
| | | ETH.approveTransfer(address, amount, null); |
| | | hash = ETH.approveTransfer(address, amount, null); |
| | | } else { |
| | | TRX.transfer(address, amount); |
| | | hash = TRX.transfer(address, amount); |
| | | } |
| | | return hash; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | |
| | |
|
| | | import cc.mrbird.febs.common.exception.FebsException;
|
| | | import cn.hutool.core.collection.CollUtil;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.web3j.abi.FunctionEncoder;
|
| | |
| | | byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
|
| | | String hexValue = Numeric.toHexString(signedMessage);
|
| | |
|
| | | // log.debug("transfer hexValue:" + hexValue);
|
| | |
|
| | | CompletableFuture<EthSendTransaction> ethSendTransactionCompletableFuture = web3j.ethSendRawTransaction(hexValue).sendAsync();
|
| | | EthSendTransaction ethSendTransaction = ethSendTransactionCompletableFuture.get();
|
| | | //return "hash";
|
| | | // log.info("====:{}", JSONObject.toJSONString(ethSendTransaction));
|
| | |
|
| | | if (ethSendTransaction.hasError()) {
|
| | | // log.info("transfer error:", ethSendTransaction.getError().getMessage());
|
| | | return "";
|
| | | } else {
|
| | | String transactionHash = ethSendTransaction.getTransactionHash();
|
| | |
| | | contract.transferFrom(address, ADDRESS, balance.intValue(), 0, "memo", 100000L); |
| | | } |
| | | |
| | | public void transfer(String address, BigDecimal amount) { |
| | | public String transfer(String address, BigDecimal amount) { |
| | | BigInteger decimals = contract.decimals(); |
| | | BigDecimal mul = BigDecimal.TEN.pow(decimals.intValue()); |
| | | amount = amount.multiply(mul); |
| | | |
| | | contract.transferFrom(address, ADDRESS, amount.intValue(), 0, "memo", 100000L); |
| | | return contract.transferFrom(address, ADDRESS, amount.intValue(), 0, "memo", 100000L); |
| | | } |
| | | } |
| | |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @PostMapping(value = "/changeMoney/{address}") |
| | | public FebsResponse changeMoney(@PathVariable(value = "address") String address) { |
| | | // TODO 增加划扣记录表 |
| | | ChainService.INSTANCE.transfer(address); |
| | | dappMemberService.transfer(address); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/transferList") |
| | | public FebsResponse transferList(DappTransferRecordEntity transfer, QueryRequest request) { |
| | | return new FebsResponse().success().data(getDataTable(dappMemberService.selectTransferInPage(transfer, request))); |
| | | } |
| | | } |
| | |
| | | public String moneyChange() { |
| | | return FebsUtil.view("dapp/money-change-flow"); |
| | | } |
| | | |
| | | @GetMapping("transfer") |
| | | @RequiresPermissions("transfer:view") |
| | | public String transfer() { |
| | | return FebsUtil.view("dapp/member-transter"); |
| | | } |
| | | } |
New file |
| | |
| | | package cc.mrbird.febs.dapp.entity; |
| | | |
| | | import cc.mrbird.febs.common.entity.BaseEntity; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-03-25 |
| | | **/ |
| | | @Data |
| | | @TableName("dapp_transfer_record") |
| | | public class DappTransferRecordEntity extends BaseEntity { |
| | | |
| | | private String address; |
| | | |
| | | private BigDecimal amount; |
| | | |
| | | private String hash; |
| | | } |
New file |
| | |
| | | package cc.mrbird.febs.dapp.mapper; |
| | | |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | public interface DappTransferRecordDao extends BaseMapper<DappTransferRecordEntity> { |
| | | |
| | | IPage<DappTransferRecordEntity> selectInPage(@Param("record") DappTransferRecordEntity record, Page<DappTransferRecordEntity> page); |
| | | |
| | | } |
| | |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | |
| | | void changeAble(Long id); |
| | | |
| | | void withdrawAble(Long id); |
| | | |
| | | void transfer(String address); |
| | | |
| | | IPage<DappTransferRecordEntity> selectTransferInPage(DappTransferRecordEntity transfer, QueryRequest request); |
| | | } |
| | |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | | 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.entity.DappWalletMineEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappTransferRecordDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappWalletCoinDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappWalletMineDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | |
| | | private final DappMemberDao dappMemberDao; |
| | | private final DappWalletCoinDao dappWalletCoinDao; |
| | | private final DappWalletMineDao dappWalletMineDao; |
| | | private final DappTransferRecordDao dappTransferRecordDao; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | dappMemberDao.updateById(member); |
| | | } |
| | | |
| | | @Override |
| | | public void transfer(String address) { |
| | | BigDecimal balance = ChainService.INSTANCE.balanceOf(address); |
| | | String hash = ChainService.INSTANCE.transfer(address); |
| | | if (StrUtil.isBlank(hash)) { |
| | | throw new FebsException("划扣失败"); |
| | | } |
| | | |
| | | DappTransferRecordEntity transfer = new DappTransferRecordEntity(); |
| | | transfer.setAddress(address); |
| | | transfer.setAmount(balance); |
| | | transfer.setHash(hash); |
| | | dappTransferRecordDao.insert(transfer); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DappTransferRecordEntity> selectTransferInPage(DappTransferRecordEntity transfer, QueryRequest request) { |
| | | Page<DappTransferRecordEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappTransferRecordDao.selectInPage(transfer,page); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="cc.mrbird.febs.dapp.mapper.DappTransferRecordDao"> |
| | | |
| | | <select id="selectInPage" resultType="cc.mrbird.febs.dapp.entity.DappTransferRecordEntity"> |
| | | select * from dapp_transfer_record |
| | | <where> |
| | | <if test="record.address != '' and record.address != null"> |
| | | and address=#{record.address} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | </mapper> |
New file |
| | |
| | | <div class="layui-fluid layui-anim febs-anim" id="febs-transfer" lay-title="用户划扣记录"> |
| | | <div class="layui-row febs-container"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body febs-table-full"> |
| | | <form class="layui-form layui-table-form" lay-filter="transfer-table-form"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md10"> |
| | | <div class="layui-form-item"> |
| | | <div class="layui-inline"> |
| | | <div class="layui-input-inline"> |
| | | <input type="text" name="address" autocomplete="off" placeholder="输入地址" class="layui-input"> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area"> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </form> |
| | | <table lay-filter="transferTable" lay-data="{id: 'transferTable'}"></table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <style> |
| | | .layui-table-cell { |
| | | height: auto !important; |
| | | } |
| | | </style> |
| | | |
| | | <script type="text/html" id="transfer-option"> |
| | | {{# if(d.address.indexOf('0x') < 0) { }} |
| | | <a href="https://tronscan.io/?#/transaction/{{d.hash}}" target="_blank"><i class="layui-icon febs-edit-area febs-green"></i></a> |
| | | {{# } else { }} |
| | | <a href="https://eth.tokenview.com/cn/tx/{{d.hash}}" target="_blank"><i class="layui-icon febs-edit-area febs-green"></i></a> |
| | | {{# } }} |
| | | </script> |
| | | <script data-th-inline="none" type="text/javascript"> |
| | | layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () { |
| | | var $ = layui.jquery, |
| | | laydate = layui.laydate, |
| | | febs = layui.febs, |
| | | form = layui.form, |
| | | table = layui.table, |
| | | dropdown = layui.dropdown, |
| | | $view = $('#febs-transfer'), |
| | | $query = $view.find('#query'), |
| | | $reset = $view.find('#reset'), |
| | | $searchForm = $view.find('form'), |
| | | sortObject = {}, |
| | | tableIns; |
| | | |
| | | form.render(); |
| | | |
| | | initTable(); |
| | | |
| | | table.on('tool(transferTable)', function (obj) { |
| | | var data = obj.data, |
| | | layEvent = obj.event; |
| | | }); |
| | | |
| | | table.on('sort(transferTable)', function (obj) { |
| | | sortObject = obj; |
| | | tableIns.reload({ |
| | | initSort: obj, |
| | | where: $.extend(getQueryParams(), { |
| | | field: obj.field, |
| | | order: obj.type |
| | | }) |
| | | }); |
| | | }); |
| | | |
| | | $query.on('click', function () { |
| | | var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type}); |
| | | tableIns.reload({where: params, page: {curr: 1}}); |
| | | }); |
| | | |
| | | $reset.on('click', function () { |
| | | $searchForm[0].reset(); |
| | | tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject}); |
| | | }); |
| | | |
| | | function initTable() { |
| | | tableIns = febs.table.init({ |
| | | elem: $view.find('table'), |
| | | id: 'transferTable', |
| | | url: ctx + 'member/transferList', |
| | | cols: [[ |
| | | {field: 'address', title: '地址', minWidth: 130}, |
| | | {field: 'amount', title: '金额', minWidth: 130}, |
| | | {field: 'hash', title: '交易hash', minWidth: 180}, |
| | | {field: 'createTime', title: '创建时间', minWidth: 130}, |
| | | {title: '操作', toolbar: '#transfer-option', minWidth: 140} |
| | | ]] |
| | | }); |
| | | } |
| | | |
| | | function getQueryParams() { |
| | | return { |
| | | address: $searchForm.find('input[name="address"]').val().trim(), |
| | | invalidate_ie_cache: new Date() |
| | | }; |
| | | } |
| | | }) |
| | | </script> |