|
1 | 1 | package io.api.etherscan.core.impl;
|
2 | 2 |
|
3 |
| -import io.api.etherscan.core.*; |
4 |
| -import io.api.etherscan.error.ApiException; |
5 |
| -import io.api.etherscan.error.ApiKeyException; |
6 | 3 | import io.api.etherscan.executor.IHttpExecutor;
|
7 |
| -import io.api.etherscan.executor.impl.HttpExecutor; |
8 | 4 | import io.api.etherscan.manager.IQueueManager;
|
9 |
| -import io.api.etherscan.manager.impl.FakeQueueManager; |
10 |
| -import io.api.etherscan.manager.impl.QueueManager; |
11 | 5 | import io.api.etherscan.model.EthNetwork;
|
12 |
| -import io.api.etherscan.util.BasicUtils; |
13 |
| -import org.jetbrains.annotations.NotNull; |
14 | 6 |
|
15 | 7 | import java.util.function.Supplier;
|
16 | 8 |
|
|
20 | 12 | * @author GoodforGod
|
21 | 13 | * @since 28.10.2018
|
22 | 14 | */
|
23 |
| -public class EtherScanApi implements AutoCloseable { |
24 |
| - |
25 |
| - private static final Supplier<IHttpExecutor> DEFAULT_SUPPLIER = HttpExecutor::new; |
26 |
| - |
27 |
| - public static final String DEFAULT_KEY = "YourApiKeyToken"; |
28 |
| - |
29 |
| - private final IQueueManager queueManager; |
30 |
| - private final IAccountApi account; |
31 |
| - private final IBlockApi block; |
32 |
| - private final IContractApi contract; |
33 |
| - private final ILogsApi logs; |
34 |
| - private final IProxyApi proxy; |
35 |
| - private final IStatisticApi stats; |
36 |
| - private final ITransactionApi txs; |
| 15 | +public class EtherScanApi extends BaseApi { |
37 | 16 |
|
38 | 17 | public EtherScanApi() {
|
39 |
| - this(DEFAULT_KEY, EthNetwork.MAINNET); |
40 |
| - } |
41 |
| - |
42 |
| - public EtherScanApi(final EthNetwork network) { |
43 |
| - this(DEFAULT_KEY, network); |
44 |
| - } |
45 |
| - |
46 |
| - public EtherScanApi(final String apiKey) { |
47 |
| - this(apiKey, EthNetwork.MAINNET); |
48 |
| - } |
49 |
| - |
50 |
| - public EtherScanApi(final EthNetwork network, |
51 |
| - final Supplier<IHttpExecutor> executorSupplier) { |
52 |
| - this(DEFAULT_KEY, network, executorSupplier); |
53 |
| - } |
54 |
| - |
55 |
| - public EtherScanApi(final String apiKey, |
56 |
| - final EthNetwork network, |
57 |
| - final IQueueManager queue) { |
58 |
| - this(apiKey, network, DEFAULT_SUPPLIER, queue); |
59 |
| - } |
60 |
| - |
61 |
| - public EtherScanApi(final String apiKey, |
62 |
| - final EthNetwork network) { |
63 |
| - this(apiKey, network, DEFAULT_SUPPLIER); |
64 |
| - } |
65 |
| - |
66 |
| - public EtherScanApi(final String apiKey, |
67 |
| - final EthNetwork network, |
68 |
| - final Supplier<IHttpExecutor> executorSupplier) { |
69 |
| - this(apiKey, network, executorSupplier, |
70 |
| - DEFAULT_KEY.equals(apiKey) |
71 |
| - ? QueueManager.DEFAULT_KEY_QUEUE |
72 |
| - : new FakeQueueManager()); |
73 |
| - } |
74 |
| - |
75 |
| - public EtherScanApi(final String apiKey, |
76 |
| - final EthNetwork network, |
77 |
| - final Supplier<IHttpExecutor> executorSupplier, |
78 |
| - final IQueueManager queue) { |
79 |
| - if (BasicUtils.isBlank(apiKey)) |
80 |
| - throw new ApiKeyException("API key can not be null or empty"); |
81 |
| - |
82 |
| - if (network == null) |
83 |
| - throw new ApiException("Ethereum Network is set to NULL value"); |
84 |
| - |
85 |
| - // EtherScan 1request\5sec limit support by queue manager |
86 |
| - final IHttpExecutor executor = executorSupplier.get(); |
87 |
| - |
88 |
| - final String ending = EthNetwork.TOBALABA.equals(network) ? "com" : "io"; |
89 |
| - final String baseUrl = "https://" + network.getDomain() + ".etherscan." + ending + "/api" + "?apikey=" + apiKey; |
90 |
| - |
91 |
| - this.queueManager = queue; |
92 |
| - this.account = new AccountApiProvider(queue, baseUrl, executor); |
93 |
| - this.block = new BlockApiProvider(queue, baseUrl, executor); |
94 |
| - this.contract = new ContractApiProvider(queue, baseUrl, executor); |
95 |
| - this.logs = new LogsApiProvider(queue, baseUrl, executor); |
96 |
| - this.proxy = new ProxyApiProvider(queue, baseUrl, executor); |
97 |
| - this.stats = new StatisticApiProvider(queue, baseUrl, executor); |
98 |
| - this.txs = new TransactionApiProvider(queue, baseUrl, executor); |
99 |
| - } |
100 |
| - |
101 |
| - @NotNull |
102 |
| - public IAccountApi account() { |
103 |
| - return account; |
| 18 | + super(); |
104 | 19 | }
|
105 | 20 |
|
106 |
| - @NotNull |
107 |
| - public IContractApi contract() { |
108 |
| - return contract; |
| 21 | + public EtherScanApi(EthNetwork network) { |
| 22 | + super(network); |
109 | 23 | }
|
110 | 24 |
|
111 |
| - @NotNull |
112 |
| - public ITransactionApi txs() { |
113 |
| - return txs; |
| 25 | + public EtherScanApi(String apiKey) { |
| 26 | + super(apiKey); |
114 | 27 | }
|
115 | 28 |
|
116 |
| - @NotNull |
117 |
| - public IBlockApi block() { |
118 |
| - return block; |
| 29 | + public EtherScanApi(EthNetwork network, Supplier<IHttpExecutor> executorSupplier) { |
| 30 | + super(network, executorSupplier); |
119 | 31 | }
|
120 | 32 |
|
121 |
| - @NotNull |
122 |
| - public ILogsApi logs() { |
123 |
| - return logs; |
| 33 | + public EtherScanApi(String apiKey, EthNetwork network, IQueueManager queue) { |
| 34 | + super(apiKey, network, queue); |
124 | 35 | }
|
125 | 36 |
|
126 |
| - @NotNull |
127 |
| - public IProxyApi proxy() { |
128 |
| - return proxy; |
| 37 | + public EtherScanApi(String apiKey, EthNetwork network) { |
| 38 | + super(apiKey, network); |
129 | 39 | }
|
130 | 40 |
|
131 |
| - @NotNull |
132 |
| - public IStatisticApi stats() { |
133 |
| - return stats; |
| 41 | + public EtherScanApi(String apiKey, EthNetwork network, Supplier<IHttpExecutor> executorSupplier) { |
| 42 | + super(apiKey, network, executorSupplier); |
134 | 43 | }
|
135 | 44 |
|
136 |
| - @Override |
137 |
| - public void close() throws Exception { |
138 |
| - queueManager.close(); |
| 45 | + public EtherScanApi(String apiKey, EthNetwork network, Supplier<IHttpExecutor> executorSupplier, IQueueManager queue) { |
| 46 | + super(apiKey, network, executorSupplier, queue); |
139 | 47 | }
|
140 | 48 | }
|
0 commit comments