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

Commitfe444f4

Browse files
committed
[2.0.0-SNAPSHOT]
GasEstimate added to GasTrackerAPI#estimate
1 parentb9a8dda commitfe444f4

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

‎src/main/java/io/goodforgod/api/etherscan/GasTrackerAPI.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
packageio.goodforgod.api.etherscan;
22

33
importio.goodforgod.api.etherscan.error.EtherScanException;
4+
importio.goodforgod.api.etherscan.model.GasEstimate;
45
importio.goodforgod.api.etherscan.model.GasOracle;
6+
importio.goodforgod.api.etherscan.model.Wei;
57
importorg.jetbrains.annotations.NotNull;
68

79
/**
@@ -14,7 +16,16 @@
1416
publicinterfaceGasTrackerAPI {
1517

1618
/**
17-
* GasOracle details
19+
* Returns the estimated time, in seconds, for a transaction to be confirmed on the blockchain.
20+
*
21+
* @return fast, suggested gas price
22+
* @throws EtherScanException parent exception class
23+
*/
24+
@NotNull
25+
GasEstimateestimate(@NotNullWeiwei)throwsEtherScanException;
26+
27+
/**
28+
* Returns the current Safe, Proposed and Fast gas prices.
1829
*
1930
* @return fast, suggested gas price
2031
* @throws EtherScanException parent exception class

‎src/main/java/io/goodforgod/api/etherscan/GasTrackerAPIProvider.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
importio.goodforgod.api.etherscan.error.EtherScanResponseException;
55
importio.goodforgod.api.etherscan.executor.EthHttpClient;
66
importio.goodforgod.api.etherscan.manager.RequestQueueManager;
7+
importio.goodforgod.api.etherscan.model.GasEstimate;
78
importio.goodforgod.api.etherscan.model.GasOracle;
9+
importio.goodforgod.api.etherscan.model.Wei;
10+
importio.goodforgod.api.etherscan.model.response.GasEstimateResponseTO;
811
importio.goodforgod.api.etherscan.model.response.GasOracleResponseTO;
912
importorg.jetbrains.annotations.NotNull;
1013

@@ -18,13 +21,26 @@
1821
finalclassGasTrackerAPIProviderextendsBasicProviderimplementsGasTrackerAPI {
1922

2023
privatestaticfinalStringACT_GAS_ORACLE_PARAM =ACT_PREFIX +"gasoracle";
24+
privatestaticfinalStringACT_GAS_ESTIMATE_PARAM =ACT_PREFIX +"gasestimate";
25+
26+
privatestaticfinalStringGASPRICE_PARAM ="&gasprice=";
2127

2228
GasTrackerAPIProvider(RequestQueueManagerqueue,
2329
StringbaseUrl,
2430
EthHttpClientethHttpClient) {
2531
super(queue,"gastracker",baseUrl,ethHttpClient);
2632
}
2733

34+
@Override
35+
public@NotNullGasEstimateestimate(@NotNullWeiwei)throwsEtherScanException {
36+
finalStringurlParams =ACT_GAS_ESTIMATE_PARAM +GASPRICE_PARAM +wei.getValue().toString();
37+
finalGasEstimateResponseTOresponse =getRequest(urlParams,GasEstimateResponseTO.class);
38+
if (response.getStatus() !=1)
39+
thrownewEtherScanResponseException(response);
40+
41+
returnnewGasEstimate(Long.parseLong(response.getResult()));
42+
}
43+
2844
@NotNull
2945
@Override
3046
publicGasOracleoracle()throwsEtherScanException {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
packageio.goodforgod.api.etherscan.model;
2+
3+
importjava.time.Duration;
4+
importjava.util.Objects;
5+
6+
/**
7+
* @author GoodforGod
8+
* @since 14.05.2023
9+
*/
10+
publicclassGasEstimate {
11+
12+
privatefinalDurationduration;
13+
14+
publicGasEstimate(longdurationInSeconds) {
15+
this.duration =Duration.ofSeconds(durationInSeconds);
16+
}
17+
18+
publicGasEstimate(Durationduration) {
19+
this.duration =duration;
20+
}
21+
22+
publicDurationgetDuration() {
23+
returnduration;
24+
}
25+
26+
@Override
27+
publicbooleanequals(Objecto) {
28+
if (this ==o)
29+
returntrue;
30+
if (!(oinstanceofGasEstimate))
31+
returnfalse;
32+
GasEstimatethat = (GasEstimate)o;
33+
returnObjects.equals(duration,that.duration);
34+
}
35+
36+
@Override
37+
publicinthashCode() {
38+
returnObjects.hash(duration);
39+
}
40+
41+
@Override
42+
publicStringtoString() {
43+
return"GasEstimate{" +
44+
"duration=" +duration +
45+
'}';
46+
}
47+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packageio.goodforgod.api.etherscan.model.response;
2+
3+
/**
4+
* @author Abhay Gupta
5+
* @since 14.11.2022
6+
*/
7+
publicclassGasEstimateResponseTOextendsBaseResponseTO {
8+
9+
privateStringresult;
10+
11+
publicStringgetResult() {
12+
returnresult;
13+
}
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp