result) {
92 | super.onPostExecute(result);
93 | if (result != null){
94 | cbLoadSmartContract.backLoadSmartContract(result);
95 | }
96 | }
97 | }
98 |
99 | public void registerCallBack(CBLoadSmartContract cbLoadSmartContract){
100 | this.cbLoadSmartContract = cbLoadSmartContract;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/librarysdkew/src/main/java/info/bcdev/librarysdkew/smartcontract/TokenERC20.java:
--------------------------------------------------------------------------------
1 | package info.bcdev.librarysdkew.smartcontract;
2 |
3 | import org.web3j.abi.EventEncoder;
4 | import org.web3j.abi.EventValues;
5 | import org.web3j.abi.FunctionEncoder;
6 | import org.web3j.abi.TypeReference;
7 | import org.web3j.abi.datatypes.Address;
8 | import org.web3j.abi.datatypes.Event;
9 | import org.web3j.abi.datatypes.Function;
10 | import org.web3j.abi.datatypes.Type;
11 | import org.web3j.abi.datatypes.Utf8String;
12 | import org.web3j.abi.datatypes.generated.Uint256;
13 | import org.web3j.abi.datatypes.generated.Uint8;
14 | import org.web3j.crypto.Credentials;
15 | import org.web3j.protocol.Web3j;
16 | import org.web3j.protocol.core.DefaultBlockParameter;
17 | import org.web3j.protocol.core.RemoteCall;
18 | import org.web3j.protocol.core.methods.request.EthFilter;
19 | import org.web3j.protocol.core.methods.response.Log;
20 | import org.web3j.protocol.core.methods.response.TransactionReceipt;
21 | import org.web3j.tx.Contract;
22 | import org.web3j.tx.TransactionManager;
23 |
24 | import java.math.BigInteger;
25 | import java.util.ArrayList;
26 | import java.util.Arrays;
27 | import java.util.Collections;
28 | import java.util.List;
29 |
30 | import rx.Observable;
31 | import rx.functions.Func1;
32 |
33 | /**
34 | * Auto generated code.
35 | *
Do not modify!
36 | *
Please use the web3j command line tools,
37 | * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
38 | * codegen module to update.
39 | *
40 | *
Generated with web3j version 3.2.0.
41 | */
42 | public class TokenERC20 extends Contract {
43 | private static final String BINARY = "608060405234801561001057600080fd5b50604051610741380380610741833981016040908152815160208084015183850151606086015160025460ff16600a0a850260038190553360009081526006865296872055918601805194969095910193919261007092908601906100a2565b5081516100849060019060208501906100a2565b506002805460ff191660ff929092169190911790555061013d915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100e357805160ff1916838001178555610110565b82800160010185558215610110579182015b828111156101105782518255916020019190600101906100f5565b5061011c929150610120565b5090565b61013a91905b8082111561011c5760008155600101610126565b90565b6105f58061014c6000396000f3006080604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be57806318160ddd1461014857806323b872dd1461016f578063313ce567146101ad5780634b750334146101d857806370a08231146101ed5780638620410b1461020e57806395d89b4114610223578063a6f2ae3a14610238578063a9059cbb14610242578063dd62ed3e14610266578063e4849b321461028d575b600080fd5b3480156100ca57600080fd5b506100d36102a5565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561010d5781810151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015457600080fd5b5061015d610333565b60408051918252519081900360200190f35b34801561017b57600080fd5b50610199600160a060020a0360043581169060243516604435610339565b604080519115158252519081900360200190f35b3480156101b957600080fd5b506101c26103a8565b6040805160ff9092168252519081900360200190f35b3480156101e457600080fd5b5061015d6103b1565b3480156101f957600080fd5b5061015d600160a060020a03600435166103b7565b34801561021a57600080fd5b5061015d6103c9565b34801561022f57600080fd5b506100d36103cf565b610240610429565b005b34801561024e57600080fd5b50610240600160a060020a0360043516602435610449565b34801561027257600080fd5b5061015d600160a060020a0360043581169060243516610458565b34801561029957600080fd5b50610240600435610475565b6000805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561032b5780601f106103005761010080835404028352916020019161032b565b820191906000526020600020905b81548152906001019060200180831161030e57829003601f168201915b505050505081565b60035481565b600160a060020a038316600090815260076020908152604080832033845290915281205482111561036957600080fd5b600160a060020a038416600090815260076020908152604080832033845290915290208054839003905561039e8484846104c2565b5060019392505050565b60025460ff1681565b60045481565b60066020526000908152604090205481565b60055481565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561032b5780601f106103005761010080835404028352916020019161032b565b60006005543481151561043857fe5b0490506104463033836104c2565b50565b6104543383836104c2565b5050565b600760209081526000928352604080842090915290825290205481565b60045481023031101561048757600080fd5b6104923330836104c2565b6004546040513391830280156108fc02916000818181858888f19350505050158015610454573d6000803e3d6000fd5b6000600160a060020a03831615156104d957600080fd5b600160a060020a0384166000908152600660205260409020548211156104fe57600080fd5b600160a060020a0383166000908152600660205260409020548281011161052457600080fd5b50600160a060020a038083166000818152600660209081526040808320805495891680855282852080548981039091559486905281548801909155815187815291519390950194927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3600160a060020a038084166000908152600660205260408082205492871682529020540181146105c357fe5b505050505600a165627a7a7230582004f06b47cfeb82a6e46077c88d3f69d0ba96b68eb5ddcd12c4747e97858a71160029";
44 |
45 | protected TokenERC20(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
46 | super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
47 | }
48 |
49 | protected TokenERC20(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
50 | super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
51 | }
52 |
53 | public List getTransferEvents(TransactionReceipt transactionReceipt) {
54 | final Event event = new Event("Transfer",
55 | Arrays.>asList(new TypeReference() {}, new TypeReference() {}),
56 | Arrays.>asList(new TypeReference() {}));
57 | List valueList = extractEventParameters(event, transactionReceipt);
58 | ArrayList responses = new ArrayList(valueList.size());
59 | for (EventValues eventValues : valueList) {
60 | TransferEventResponse typedResponse = new TransferEventResponse();
61 | typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
62 | typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
63 | typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
64 | responses.add(typedResponse);
65 | }
66 | return responses;
67 | }
68 |
69 | public Observable transferEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
70 | final Event event = new Event("Transfer",
71 | Arrays.>asList(new TypeReference() {}, new TypeReference() {}),
72 | Arrays.>asList(new TypeReference() {}));
73 | EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
74 | filter.addSingleTopic(EventEncoder.encode(event));
75 | return web3j.ethLogObservable(filter).map(new Func1() {
76 | @Override
77 | public TransferEventResponse call(Log log) {
78 | EventValues eventValues = extractEventParameters(event, log);
79 | TransferEventResponse typedResponse = new TransferEventResponse();
80 | typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
81 | typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
82 | typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
83 | return typedResponse;
84 | }
85 | });
86 | }
87 |
88 | public List getBurnEvents(TransactionReceipt transactionReceipt) {
89 | final Event event = new Event("Burn",
90 | Arrays.>asList(new TypeReference() {}),
91 | Arrays.>asList(new TypeReference() {}));
92 | List valueList = extractEventParameters(event, transactionReceipt);
93 | ArrayList responses = new ArrayList(valueList.size());
94 | for (EventValues eventValues : valueList) {
95 | BurnEventResponse typedResponse = new BurnEventResponse();
96 | typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
97 | typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
98 | responses.add(typedResponse);
99 | }
100 | return responses;
101 | }
102 |
103 | public Observable burnEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
104 | final Event event = new Event("Burn",
105 | Arrays.>asList(new TypeReference() {}),
106 | Arrays.>asList(new TypeReference() {}));
107 | EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
108 | filter.addSingleTopic(EventEncoder.encode(event));
109 | return web3j.ethLogObservable(filter).map(new Func1() {
110 | @Override
111 | public BurnEventResponse call(Log log) {
112 | EventValues eventValues = extractEventParameters(event, log);
113 | BurnEventResponse typedResponse = new BurnEventResponse();
114 | typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
115 | typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
116 | return typedResponse;
117 | }
118 | });
119 | }
120 |
121 | public RemoteCall name() {
122 | Function function = new Function("name",
123 | Arrays.asList(),
124 | Arrays.>asList(new TypeReference() {}));
125 | return executeRemoteCallSingleValueReturn(function, String.class);
126 | }
127 |
128 | public RemoteCall totalSupply() {
129 | Function function = new Function("totalSupply",
130 | Arrays.asList(),
131 | Arrays.>asList(new TypeReference() {}));
132 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
133 | }
134 |
135 | public RemoteCall transferFrom(String _from, String _to, BigInteger _value) {
136 | Function function = new Function(
137 | "transferFrom",
138 | Arrays.asList(new Address(_from),
139 | new Address(_to),
140 | new Uint256(_value)),
141 | Collections.>emptyList());
142 | return executeRemoteCallTransaction(function);
143 | }
144 |
145 | public RemoteCall decimals() {
146 | Function function = new Function("decimals",
147 | Arrays.asList(),
148 | Arrays.>asList(new TypeReference() {}));
149 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
150 | }
151 |
152 | public RemoteCall sellPrice() {
153 | Function function = new Function("sellPrice",
154 | Arrays.asList(),
155 | Arrays.>asList(new TypeReference() {}));
156 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
157 | }
158 |
159 | public RemoteCall balanceOf(String param0) {
160 | Function function = new Function("balanceOf",
161 | Arrays.asList(new Address(param0)),
162 | Arrays.>asList(new TypeReference() {}));
163 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
164 | }
165 |
166 | public RemoteCall buyPrice() {
167 | Function function = new Function("buyPrice",
168 | Arrays.asList(),
169 | Arrays.>asList(new TypeReference() {}));
170 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
171 | }
172 |
173 | public RemoteCall symbol() {
174 | Function function = new Function("symbol",
175 | Arrays.asList(),
176 | Arrays.>asList(new TypeReference() {}));
177 | return executeRemoteCallSingleValueReturn(function, String.class);
178 | }
179 |
180 | public RemoteCall buy(BigInteger weiValue) {
181 | Function function = new Function(
182 | "buy",
183 | Arrays.asList(),
184 | Collections.>emptyList());
185 | return executeRemoteCallTransaction(function, weiValue);
186 | }
187 |
188 | public RemoteCall transfer(String _to, BigInteger _value) {
189 | Function function = new Function(
190 | "transfer",
191 | Arrays.asList(new Address(_to),
192 | new Uint256(_value)),
193 | Collections.>emptyList());
194 | return executeRemoteCallTransaction(function);
195 | }
196 |
197 | public RemoteCall allowance(String param0, String param1) {
198 | Function function = new Function("allowance",
199 | Arrays.asList(new Address(param0),
200 | new Address(param1)),
201 | Arrays.>asList(new TypeReference() {}));
202 | return executeRemoteCallSingleValueReturn(function, BigInteger.class);
203 | }
204 |
205 | public RemoteCall sell(BigInteger amount) {
206 | Function function = new Function(
207 | "sell",
208 | Arrays.asList(new Uint256(amount)),
209 | Collections.>emptyList());
210 | return executeRemoteCallTransaction(function);
211 | }
212 |
213 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialSupply, String tokenName, String tokenSymbol, BigInteger tokendecimals) {
214 | String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.asList(new Uint256(initialSupply),
215 | new Utf8String(tokenName),
216 | new Utf8String(tokenSymbol),
217 | new Uint8(tokendecimals)));
218 | return deployRemoteCall(TokenERC20.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);
219 | }
220 |
221 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialSupply, String tokenName, String tokenSymbol, BigInteger tokendecimals) {
222 | String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.asList(new Uint256(initialSupply),
223 | new Utf8String(tokenName),
224 | new Utf8String(tokenSymbol),
225 | new Uint8(tokendecimals)));
226 | return deployRemoteCall(TokenERC20.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor);
227 | }
228 |
229 | public static TokenERC20 load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
230 | return new TokenERC20(contractAddress, web3j, credentials, gasPrice, gasLimit);
231 | }
232 |
233 | public static TokenERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
234 | return new TokenERC20(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
235 | }
236 |
237 | public static class TransferEventResponse {
238 | public String from;
239 |
240 | public String to;
241 |
242 | public BigInteger value;
243 | }
244 |
245 | public static class BurnEventResponse {
246 | public String from;
247 |
248 | public BigInteger value;
249 | }
250 | }
251 |
--------------------------------------------------------------------------------
/librarysdkew/src/main/java/info/bcdev/librarysdkew/utils/EtherScan.java:
--------------------------------------------------------------------------------
1 | package info.bcdev.librarysdkew.utils;
2 |
3 | import android.os.AsyncTask;
4 |
5 | import com.google.gson.JsonParser;
6 |
7 | import java.io.InputStreamReader;
8 | import java.net.HttpURLConnection;
9 | import java.net.URL;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import info.bcdev.librarysdkew.interfaces.callback.CBEtherScan;
14 |
15 | public class EtherScan {
16 |
17 | CBEtherScan cbEtherScan;
18 | private String mUrl = "https://api.etherscan.io/api";
19 | private String mApiKey;
20 | Map actionparams;
21 | String action;
22 |
23 | public EtherScan(String apikey){
24 | mApiKey = apikey;
25 | }
26 |
27 | public void getBalance(String address){
28 | action = "balance";
29 | Map params = new HashMap<>();
30 | params.put("module","account");
31 | params.put("action","balance");
32 | params.put("address",address);
33 | params.put("tag","latest");
34 | params.put("apikey",mApiKey);
35 | new RequestES().execute(params);
36 | }
37 |
38 | private class RequestES extends AsyncTask