xiaoyong931011
2022-12-13 13f4391da611f0be3d08981479d38f79fd6e75d4
src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java
@@ -1,5 +1,15 @@
package cc.mrbird.febs.dapp.contract;
import cc.mrbird.febs.dapp.entity.DappFundFlowEntity;
import cc.mrbird.febs.dapp.entity.DappMemberEntity;
import cc.mrbird.febs.dapp.entity.DappSystemProfit;
import cc.mrbird.febs.dapp.mapper.DappFundFlowDao;
import cc.mrbird.febs.dapp.mapper.DappMemberDao;
import cc.mrbird.febs.dapp.mapper.DappSystemProfitDao;
import cc.mrbird.febs.rabbit.producer.ChainProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
@@ -105,8 +115,8 @@
                            //发送转币消息
                            chainProducer.sendBnbTransferMsg(dappFundFlowEntity.getId());
                            DappMemberEntity dappMember = dappMemberDao.selectById(dappFundFlowEntity.getMemberId());
                            trans(new BigInteger(dappFundFlowEntity.getAmount().toString()),dappMember.getAddress());
//                            DappMemberEntity dappMember = dappMemberDao.selectById(dappFundFlowEntity.getMemberId());
//                            trans(new BigInteger(dappFundFlowEntity.getAmount().toString()),dappMember.getAddress());
                        }
                    }
                }
@@ -118,13 +128,16 @@
    /**
     * 从合约内转币到制定地址
     */
    public void trans(BigInteger amount, String to1){
    public String trans(BigInteger amount, String to1){
        String transactionHash = null;
        Credentials credentials = Credentials.create(privateKey);
        Abi contract = Abi.load(contractAddr, getInstance(), credentials, getStaticGasProvider());
        try {
            TransactionReceipt send = contract.trans(amount, to1).send();
            transactionHash = send.getTransactionHash();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return transactionHash;
    }
}