Skip to content

Commit 420c68f

Browse files
committed
[2.0.0-SNAPSHOT]
GasTrackerAPI refactored to new API EthHttpClient package refactoring
1 parent 7436509 commit 420c68f

14 files changed

Lines changed: 113 additions & 104 deletions

src/main/java/io/goodforgod/api/etherscan/AccountAPI.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,21 @@ public interface AccountAPI {
112112
/**
113113
* All ERC-20 token txs for given address and contract address
114114
*
115-
* @param address get txs for
115+
* @param address get txs for
116116
* @param contractAddress contract address to get txs for
117-
* @param startBlock tx from this blockNumber
118-
* @param endBlock tx to this blockNumber
117+
* @param startBlock tx from this blockNumber
118+
* @param endBlock tx to this blockNumber
119119
* @return txs for address
120-
* @throws ApiException parent exception class
120+
* @throws EtherScanException parent exception class
121121
*/
122122
@NotNull
123-
List<TxToken> txsToken(String address, String contractAddress, long startBlock, long endBlock) throws ApiException;
123+
List<TxERC20> txsERC20(String address, String contractAddress, long startBlock, long endBlock) throws EtherScanException;
124124

125125
@NotNull
126-
List<TxToken> txsToken(String address, String contractAddress, long startBlock) throws ApiException;
126+
List<TxERC20> txsERC20(String address, String contractAddress, long startBlock) throws EtherScanException;
127127

128128
@NotNull
129-
List<TxToken> txsToken(String address, String contractAddress) throws ApiException;
129+
List<TxERC20> txsERC20(String address, String contractAddress) throws EtherScanException;
130130

131131
/**
132132
* All ERC-721 (NFT) token txs for given address

src/main/java/io/goodforgod/api/etherscan/AccountAPIProvider.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,20 @@ public List<TxERC20> txsERC20(String address, long startBlock, long endBlock) th
234234

235235
@NotNull
236236
@Override
237-
public List<TxToken> txsToken(final String address, final String contractAddress) throws ApiException {
238-
return txsToken(address, contractAddress, MIN_START_BLOCK);
237+
public List<TxERC20> txsERC20(String address, String contractAddress) throws EtherScanException {
238+
return txsERC20(address, contractAddress, MIN_START_BLOCK);
239239
}
240240

241241
@NotNull
242242
@Override
243-
public List<TxToken> txsToken(final String address, final String contractAddress, final long startBlock) throws ApiException {
244-
return txsToken(address, contractAddress, startBlock, MAX_END_BLOCK);
243+
public List<TxERC20> txsERC20(String address, String contractAddress, long startBlock) throws EtherScanException {
244+
return txsERC20(address, contractAddress, startBlock, MAX_END_BLOCK);
245245
}
246246

247247
@NotNull
248248
@Override
249-
public List<TxToken> txsToken(final String address, final String contractAddress, final long startBlock, final long endBlock) throws ApiException {
249+
public List<TxERC20> txsERC20(String address, String contractAddress, long startBlock, long endBlock)
250+
throws EtherScanException {
250251
BasicUtils.validateAddress(address);
251252
final BlockParam blocks = BasicUtils.compensateBlocks(startBlock, endBlock);
252253

@@ -255,7 +256,7 @@ public List<TxToken> txsToken(final String address, final String contractAddress
255256
final String urlParams = ACT_TX_TOKEN_ACTION + offsetParam + ADDRESS_PARAM + address
256257
+ CONTRACT_PARAM + contractAddress + blockParam + SORT_ASC_PARAM;
257258

258-
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
259+
return getRequestUsingOffset(urlParams, TxERC20ResponseTO.class);
259260
}
260261

261262
@NotNull

src/main/java/io/goodforgod/api/etherscan/BasicProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ abstract class BasicProvider {
3232
private final RequestQueueManager queue;
3333
private final Gson gson;
3434

35-
BasicProvider(RequestQueueManager queue,
35+
BasicProvider(RequestQueueManager requestQueueManager,
3636
String module,
3737
String baseUrl,
38-
EthHttpClient executor) {
39-
this.queue = queue;
38+
EthHttpClient ethHttpClient) {
39+
this.queue = requestQueueManager;
4040
this.module = "&module=" + module;
4141
this.baseUrl = baseUrl;
42-
this.executor = executor;
42+
this.executor = ethHttpClient;
4343
this.gson = new GsonConfiguration().builder().create();
4444
}
4545

src/main/java/io/goodforgod/api/etherscan/EtherScanAPI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public interface EtherScanAPI extends AutoCloseable {
3434
@NotNull
3535
StatisticAPI stats();
3636

37+
@NotNull
38+
GasTrackerAPI gasTracker();
39+
40+
@NotNull
3741
static Builder builder() {
3842
return new EthScanAPIBuilder();
3943
}

src/main/java/io/goodforgod/api/etherscan/EtherScanAPIProvider.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ final class EtherScanAPIProvider implements EtherScanAPI {
2121
private final ProxyAPI proxy;
2222
private final StatisticAPI stats;
2323
private final TransactionAPI txs;
24+
private final GasTrackerAPI gasTracker;
2425

2526
EtherScanAPIProvider(String apiKey,
2627
EthNetwork network,
2728
Supplier<EthHttpClient> executorSupplier,
2829
RequestQueueManager queue) {
2930
// EtherScan 1request\5sec limit support by queue manager
30-
final EthHttpClient executor = executorSupplier.get();
31+
final EthHttpClient ethHttpClient = executorSupplier.get();
3132
final String baseUrl = network.domain() + "?apikey=" + apiKey;
3233

3334
this.requestQueueManager = queue;
34-
this.account = new AccountAPIProvider(queue, baseUrl, executor);
35-
this.block = new BlockAPIProvider(queue, baseUrl, executor);
36-
this.contract = new ContractAPIProvider(queue, baseUrl, executor);
37-
this.logs = new LogsAPIProvider(queue, baseUrl, executor);
38-
this.proxy = new ProxyAPIProvider(queue, baseUrl, executor);
39-
this.stats = new StatisticAPIProvider(queue, baseUrl, executor);
40-
this.txs = new TransactionAPIProvider(queue, baseUrl, executor);
35+
this.account = new AccountAPIProvider(queue, baseUrl, ethHttpClient);
36+
this.block = new BlockAPIProvider(queue, baseUrl, ethHttpClient);
37+
this.contract = new ContractAPIProvider(queue, baseUrl, ethHttpClient);
38+
this.logs = new LogsAPIProvider(queue, baseUrl, ethHttpClient);
39+
this.proxy = new ProxyAPIProvider(queue, baseUrl, ethHttpClient);
40+
this.stats = new StatisticAPIProvider(queue, baseUrl, ethHttpClient);
41+
this.txs = new TransactionAPIProvider(queue, baseUrl, ethHttpClient);
42+
this.gasTracker = new GasTrackerAPIProvider(queue, baseUrl, ethHttpClient);
4143
}
4244

4345
@NotNull
@@ -82,6 +84,11 @@ public StatisticAPI stats() {
8284
return stats;
8385
}
8486

87+
@Override
88+
public @NotNull GasTrackerAPI gasTracker() {
89+
return gasTracker;
90+
}
91+
8592
@Override
8693
public void close() throws Exception {
8794
requestQueueManager.close();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.goodforgod.api.etherscan;
2+
3+
import io.goodforgod.api.etherscan.error.EtherScanException;
4+
import io.goodforgod.api.etherscan.model.GasOracle;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
/**
8+
* EtherScan - API Descriptions
9+
* <a href="https://docs.etherscan.io/api-endpoints/gas-tracker">...</a>
10+
*
11+
* @author Abhay Gupta
12+
* @since 14.11.2022
13+
*/
14+
public interface GasTrackerAPI {
15+
16+
/**
17+
* GasOracle details
18+
*
19+
* @return fast, suggested gas price
20+
* @throws EtherScanException parent exception class
21+
*/
22+
@NotNull
23+
GasOracle oracle() throws EtherScanException;
24+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.goodforgod.api.etherscan;
2+
3+
import io.goodforgod.api.etherscan.error.EtherScanException;
4+
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
5+
import io.goodforgod.api.etherscan.executor.EthHttpClient;
6+
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
7+
import io.goodforgod.api.etherscan.model.GasOracle;
8+
import io.goodforgod.api.etherscan.model.response.GasOracleResponseTO;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
/**
12+
* GasTracker API Implementation
13+
*
14+
* @see GasTrackerAPI
15+
* @author Abhay Gupta
16+
* @since 14.11.2022
17+
*/
18+
final class GasTrackerAPIProvider extends BasicProvider implements GasTrackerAPI {
19+
20+
private static final String ACT_GAS_ORACLE_PARAM = ACT_PREFIX + "gasoracle";
21+
22+
GasTrackerAPIProvider(RequestQueueManager queue,
23+
String baseUrl,
24+
EthHttpClient ethHttpClient) {
25+
super(queue, "gastracker", baseUrl, ethHttpClient);
26+
}
27+
28+
@NotNull
29+
@Override
30+
public GasOracle oracle() throws EtherScanException {
31+
final GasOracleResponseTO response = getRequest(ACT_GAS_ORACLE_PARAM, GasOracleResponseTO.class);
32+
if (response.getStatus() != 1)
33+
throw new EtherScanResponseException(response);
34+
35+
return response.getResult();
36+
}
37+
}

src/main/java/io/goodforgod/api/etherscan/GasTrackerApiProvider.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/java/io/goodforgod/api/etherscan/IGasTrackerApi.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/io/goodforgod/api/etherscan/model/BlockUncle.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.goodforgod.api.etherscan.model;
22

33
import io.goodforgod.api.etherscan.util.BasicUtils;
4-
54
import java.math.BigInteger;
65
import java.util.List;
76

0 commit comments

Comments
 (0)