Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fb7d91

Browse files
gas tracker API implementation
1 parent1559a3f commit9fb7d91

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packageio.api.etherscan.core;
2+
3+
importio.api.etherscan.error.ApiException;
4+
importio.api.etherscan.model.GasOracle;
5+
importorg.jetbrains.annotations.NotNull;
6+
7+
/**
8+
* EtherScan - API Descriptions https://docs.etherscan.io/api-endpoints/gas-tracker
9+
*
10+
* @author Abhay Gupta
11+
* @since 14.11.2022
12+
*/
13+
publicinterfaceIGasTrackerApi {
14+
15+
/**
16+
* GasOracle details
17+
*
18+
* @return fast, suggested gas price
19+
* @throws ApiException parent exception class
20+
*/
21+
@NotNull
22+
GasOraclegasoracle()throwsApiException;
23+
}

‎src/main/java/io/api/etherscan/core/impl/EtherScanApi.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class EtherScanApi implements AutoCloseable {
3434
privatefinalIProxyApiproxy;
3535
privatefinalIStatisticApistats;
3636
privatefinalITransactionApitxs;
37+
privatefinalIGasTrackerApigastracker;
3738

3839
publicEtherScanApi() {
3940
this(DEFAULT_KEY,EthNetwork.MAINNET);
@@ -96,6 +97,7 @@ public EtherScanApi(final String apiKey,
9697
this.proxy =newProxyApiProvider(queue,baseUrl,executor);
9798
this.stats =newStatisticApiProvider(queue,baseUrl,executor);
9899
this.txs =newTransactionApiProvider(queue,baseUrl,executor);
100+
this.gastracker =newGasTrackerApiProvider(queue,baseUrl,executor);
99101
}
100102

101103
@NotNull
@@ -133,6 +135,11 @@ public IStatisticApi stats() {
133135
returnstats;
134136
}
135137

138+
@NotNull
139+
publicIGasTrackerApigastracker() {
140+
returngastracker;
141+
}
142+
136143
@Override
137144
publicvoidclose()throwsException {
138145
queueManager.close();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packageio.api.etherscan.core.impl;
2+
3+
importio.api.etherscan.core.IGasTrackerApi;
4+
importio.api.etherscan.error.ApiException;
5+
importio.api.etherscan.error.EtherScanException;
6+
importio.api.etherscan.executor.IHttpExecutor;
7+
importio.api.etherscan.manager.IQueueManager;
8+
importio.api.etherscan.model.GasOracle;
9+
importio.api.etherscan.model.utility.GasOracleResponseTO;
10+
importorg.jetbrains.annotations.NotNull;
11+
12+
/**
13+
* GasTracker API Implementation
14+
*
15+
* @see IGasTrackerApi
16+
*
17+
* @author Abhay Gupta
18+
* @since 14.11.2022
19+
*/
20+
publicclassGasTrackerApiProviderextendsBasicProviderimplementsIGasTrackerApi {
21+
22+
privatestaticfinalStringACT_GAS_ORACLE_PARAM =ACT_PREFIX +"gasoracle";
23+
24+
GasTrackerApiProvider(finalIQueueManagerqueue,
25+
finalStringbaseUrl,
26+
finalIHttpExecutorexecutor) {
27+
super(queue,"gastracker",baseUrl,executor);
28+
}
29+
30+
@NotNull
31+
@Override
32+
publicGasOraclegasoracle()throwsApiException {
33+
finalGasOracleResponseTOresponse =getRequest(ACT_GAS_ORACLE_PARAM,GasOracleResponseTO.class);
34+
if (response.getStatus() !=1)
35+
thrownewEtherScanException(response);
36+
37+
returnresponse.getResult();
38+
}
39+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
packageio.api.etherscan.model;
2+
3+
importjava.math.BigInteger;
4+
importjava.util.Objects;
5+
6+
/**
7+
* ! NO DESCRIPTION !
8+
*
9+
* @author Abhay Gupta
10+
* @since 14.11.2022
11+
*/
12+
publicclassGasOracle {
13+
privateLongLastBlock;
14+
privateIntegerSafeGasPrice;
15+
privateIntegerProposeGasPrice;
16+
privateIntegerFastGasPrice;
17+
privateDoublesuggestBaseFee;
18+
privateStringgasUsedRatio;
19+
20+
publicLonggetLastBlock() {
21+
returnLastBlock;
22+
}
23+
24+
publicBigIntegergetSafeGasPriceInWei() {
25+
returnBigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9));
26+
}
27+
28+
publicBigIntegergetProposeGasPriceInWei() {
29+
returnBigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9));
30+
}
31+
32+
publicBigIntegergetFastGasPriceInWei() {
33+
returnBigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9));
34+
}
35+
36+
publicDoublegetSuggestBaseFee() {
37+
returnsuggestBaseFee;
38+
}
39+
40+
publicStringgetGasUsedRatio() {
41+
returngasUsedRatio;
42+
}
43+
44+
@Override
45+
publicbooleanequals(Objecto) {
46+
if (this ==o)returntrue;
47+
if (o ==null ||getClass() !=o.getClass())returnfalse;
48+
GasOraclegasOracle = (GasOracle)o;
49+
returnLastBlock.equals(gasOracle.LastBlock) &&SafeGasPrice.equals(gasOracle.SafeGasPrice) &&ProposeGasPrice.equals(gasOracle.ProposeGasPrice) &&FastGasPrice.equals(gasOracle.FastGasPrice) &&suggestBaseFee.equals(gasOracle.suggestBaseFee) &&gasUsedRatio.equals(gasOracle.gasUsedRatio);
50+
}
51+
52+
@Override
53+
publicinthashCode() {
54+
returnObjects.hash(LastBlock,SafeGasPrice,ProposeGasPrice,FastGasPrice,suggestBaseFee,gasUsedRatio);
55+
}
56+
57+
@Override
58+
publicStringtoString() {
59+
return"GasOracle{" +
60+
"LastBlock=" +LastBlock +
61+
", SafeGasPrice=" +SafeGasPrice +
62+
", ProposeGasPrice=" +ProposeGasPrice +
63+
", FastGasPrice=" +FastGasPrice +
64+
", suggestBaseFee=" +suggestBaseFee +
65+
", gasUsedRatio='" +gasUsedRatio +'\'' +
66+
'}';
67+
}
68+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packageio.api.etherscan.model.utility;
2+
3+
importio.api.etherscan.model.GasOracle;
4+
5+
/**
6+
* ! NO DESCRIPTION !
7+
*
8+
* @author Abhay Gupta
9+
* @since 14.11.2022
10+
*/
11+
publicclassGasOracleResponseTOextendsBaseResponseTO {
12+
13+
privateGasOracleresult;
14+
15+
publicGasOraclegetResult() {
16+
returnresult;
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp