-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathGasTrackerAPIProvider.java
54 lines (45 loc) · 2.09 KB
/
GasTrackerAPIProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
import io.goodforgod.api.etherscan.http.EthHttpClient;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.model.GasEstimate;
import io.goodforgod.api.etherscan.model.GasOracle;
import io.goodforgod.api.etherscan.model.Wei;
import io.goodforgod.api.etherscan.model.response.GasEstimateResponseTO;
import io.goodforgod.api.etherscan.model.response.GasOracleResponseTO;
import org.jetbrains.annotations.NotNull;
/**
* GasTracker API Implementation
*
* @see GasTrackerAPI
* @author Abhay Gupta
* @since 14.11.2022
*/
final class GasTrackerAPIProvider extends BasicProvider implements GasTrackerAPI {
private static final String ACT_GAS_ORACLE_PARAM = ACT_PREFIX + "gasoracle";
private static final String ACT_GAS_ESTIMATE_PARAM = ACT_PREFIX + "gasestimate";
private static final String GASPRICE_PARAM = "&gasprice=";
GasTrackerAPIProvider(RequestQueueManager queue,
String baseUrl,
EthHttpClient ethHttpClient,
Converter converter) {
super(queue, "gastracker", baseUrl, ethHttpClient, converter);
}
@Override
public @NotNull GasEstimate estimate(@NotNull Wei wei) throws EtherScanException {
final String urlParams = ACT_GAS_ESTIMATE_PARAM + GASPRICE_PARAM + wei.asWei().toString();
final GasEstimateResponseTO response = getRequest(urlParams, GasEstimateResponseTO.class);
if (response.getStatus() != 1)
throw new EtherScanResponseException(response);
return new GasEstimate(Long.parseLong(response.getResult()));
}
@NotNull
@Override
public GasOracle oracle() throws EtherScanException {
final GasOracleResponseTO response = getRequest(ACT_GAS_ORACLE_PARAM, GasOracleResponseTO.class);
if (response.getStatus() != 1)
throw new EtherScanResponseException(response);
return response.getResult();
}
}