|
| 1 | +package org.web3j.generated; |
| 2 | + |
| 3 | +import java.math.BigInteger; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Collections; |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.List; |
| 9 | +import org.web3j.abi.EventEncoder; |
| 10 | +import org.web3j.abi.EventValues; |
| 11 | +import org.web3j.abi.TypeReference; |
| 12 | +import org.web3j.abi.datatypes.Address; |
| 13 | +import org.web3j.abi.datatypes.Event; |
| 14 | +import org.web3j.abi.datatypes.Function; |
| 15 | +import org.web3j.abi.datatypes.Type; |
| 16 | +import org.web3j.abi.datatypes.generated.Uint256; |
| 17 | +import org.web3j.crypto.Credentials; |
| 18 | +import org.web3j.protocol.Web3j; |
| 19 | +import org.web3j.protocol.core.DefaultBlockParameter; |
| 20 | +import org.web3j.protocol.core.RemoteCall; |
| 21 | +import org.web3j.protocol.core.methods.request.EthFilter; |
| 22 | +import org.web3j.protocol.core.methods.response.Log; |
| 23 | +import org.web3j.protocol.core.methods.response.TransactionReceipt; |
| 24 | +import org.web3j.tx.Contract; |
| 25 | +import org.web3j.tx.TransactionManager; |
| 26 | +import rx.Observable; |
| 27 | +import rx.functions.Func1; |
| 28 | + |
| 29 | +/** |
| 30 | + * <p>Auto generated code. |
| 31 | + * <p><strong>Do not modify!</strong> |
| 32 | + * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>, |
| 33 | + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the |
| 34 | + * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update. |
| 35 | + * |
| 36 | + * <p>Generated with web3j version 3.1.0. |
| 37 | + */ |
| 38 | +public final class MetaCoin extends Contract { |
| 39 | + private static final String BINARY = "0x6060604052341561000f57600080fd5b6127106000803273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506103c5806100636000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680637bd703e81461005c57806390b98a11146100a9578063f8b2cb4f14610103575b600080fd5b341561006757600080fd5b610093600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610150565b6040518082815260200191505060405180910390f35b34156100b457600080fd5b6100e9600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506101f8565b604051808215151515815260200191505060405180910390f35b341561010e57600080fd5b61013a600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610351565b6040518082815260200191505060405180910390f35b600073__ConvertLib____________________________6396e4ee3d61017584610351565b60026000604051602001526040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808381526020018281526020019250505060206040518083038186803b15156101d657600080fd5b6102c65a03f415156101e757600080fd5b505050604051805190509050919050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610249576000905061034b565b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190505b92915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509190505600a165627a7a72305820f791829bf0c920a6d43123cac9b9894757ddc838c17efbad6d56773d6e3dcf4c0029"; |
| 40 | + |
| 41 | + protected static final HashMap<String, String> _addresses; |
| 42 | + |
| 43 | + static { |
| 44 | + _addresses = new HashMap<>(); |
| 45 | + _addresses.put("4", "0xaea9d31a4aeda9e510f7d85559261c16ea0b6b8b"); |
| 46 | + _addresses.put("4447", "0x254dffcd3277c0b1660f6d42efbb754edababc2b"); |
| 47 | + } |
| 48 | + |
| 49 | + private MetaCoin(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { |
| 50 | + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); |
| 51 | + } |
| 52 | + |
| 53 | + private MetaCoin(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { |
| 54 | + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); |
| 55 | + } |
| 56 | + |
| 57 | + public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) { |
| 58 | + final Event event = new Event("Transfer", |
| 59 | + Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}), |
| 60 | + Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); |
| 61 | + List<EventValues> valueList = extractEventParameters(event, transactionReceipt); |
| 62 | + ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size()); |
| 63 | + for (EventValues eventValues : valueList) { |
| 64 | + TransferEventResponse typedResponse = new TransferEventResponse(); |
| 65 | + typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue(); |
| 66 | + typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue(); |
| 67 | + typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); |
| 68 | + responses.add(typedResponse); |
| 69 | + } |
| 70 | + return responses; |
| 71 | + } |
| 72 | + |
| 73 | + public Observable<TransferEventResponse> transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { |
| 74 | + final Event event = new Event("Transfer", |
| 75 | + Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}), |
| 76 | + Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); |
| 77 | + EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); |
| 78 | + filter.addSingleTopic(EventEncoder.encode(event)); |
| 79 | + return web3j.ethLogObservable(filter).map(new Func1<Log, TransferEventResponse>() { |
| 80 | + @Override |
| 81 | + public TransferEventResponse call(Log log) { |
| 82 | + EventValues eventValues = extractEventParameters(event, log); |
| 83 | + TransferEventResponse typedResponse = new TransferEventResponse(); |
| 84 | + typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue(); |
| 85 | + typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue(); |
| 86 | + typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); |
| 87 | + return typedResponse; |
| 88 | + } |
| 89 | + }); |
| 90 | + } |
| 91 | + |
| 92 | + public RemoteCall<BigInteger> getBalanceInEth(String addr) { |
| 93 | + Function function = new Function("getBalanceInEth", |
| 94 | + Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)), |
| 95 | + Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); |
| 96 | + return executeRemoteCallSingleValueReturn(function, BigInteger.class); |
| 97 | + } |
| 98 | + |
| 99 | + public RemoteCall<TransactionReceipt> sendCoin(String receiver, BigInteger amount) { |
| 100 | + Function function = new Function( |
| 101 | + "sendCoin", |
| 102 | + Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(receiver), |
| 103 | + new org.web3j.abi.datatypes.generated.Uint256(amount)), |
| 104 | + Collections.<TypeReference<?>>emptyList()); |
| 105 | + return executeRemoteCallTransaction(function); |
| 106 | + } |
| 107 | + |
| 108 | + public RemoteCall<BigInteger> getBalance(String addr) { |
| 109 | + Function function = new Function("getBalance", |
| 110 | + Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(addr)), |
| 111 | + Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); |
| 112 | + return executeRemoteCallSingleValueReturn(function, BigInteger.class); |
| 113 | + } |
| 114 | + |
| 115 | + public static RemoteCall<MetaCoin> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { |
| 116 | + return deployRemoteCall(MetaCoin.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); |
| 117 | + } |
| 118 | + |
| 119 | + public static RemoteCall<MetaCoin> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { |
| 120 | + return deployRemoteCall(MetaCoin.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); |
| 121 | + } |
| 122 | + |
| 123 | + public static MetaCoin load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { |
| 124 | + return new MetaCoin(contractAddress, web3j, credentials, gasPrice, gasLimit); |
| 125 | + } |
| 126 | + |
| 127 | + public static MetaCoin load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { |
| 128 | + return new MetaCoin(contractAddress, web3j, transactionManager, gasPrice, gasLimit); |
| 129 | + } |
| 130 | + |
| 131 | + protected String getStaticDeployedAddress(String networkId) { |
| 132 | + return _addresses.get(networkId); |
| 133 | + } |
| 134 | + |
| 135 | + public static class TransferEventResponse { |
| 136 | + public String _from; |
| 137 | + |
| 138 | + public String _to; |
| 139 | + |
| 140 | + public BigInteger _value; |
| 141 | + } |
| 142 | +} |
0 commit comments