Skip to content

Commit 7436509

Browse files
committed
[2.0.0-SNAPSHOT]
Merge branch 'dev' of https://github.com/GoodforGod/java-etherscan-api into dev # Conflicts: # src/main/java/io/api/etherscan/core/impl/EtherScanApi.java # src/main/java/io/goodforgod/api/etherscan/AccountAPIProvider.java # src/main/java/io/goodforgod/api/etherscan/GasTrackerApiProvider.java # src/main/java/io/goodforgod/api/etherscan/IGasTrackerApi.java # src/main/java/io/goodforgod/api/etherscan/model/response/GasOracleResponseTO.java
2 parents f3d6858 + 9e4d21a commit 7436509

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.api.etherscan.model;
2+
3+
import java.math.BigInteger;
4+
import java.util.Objects;
5+
6+
/**
7+
* ! NO DESCRIPTION !
8+
*
9+
* @author Abhay Gupta
10+
* @since 14.11.2022
11+
*/
12+
public class GasOracle {
13+
private Long LastBlock;
14+
private Integer SafeGasPrice;
15+
private Integer ProposeGasPrice;
16+
private Integer FastGasPrice;
17+
private Double suggestBaseFee;
18+
private String gasUsedRatio;
19+
20+
public Long getLastBlock() {
21+
return LastBlock;
22+
}
23+
24+
public BigInteger getSafeGasPriceInWei() {
25+
return BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9));
26+
}
27+
28+
public BigInteger getProposeGasPriceInWei() {
29+
return BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9));
30+
}
31+
32+
public BigInteger getFastGasPriceInWei() {
33+
return BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9));
34+
}
35+
36+
public Double getSuggestBaseFee() {
37+
return suggestBaseFee;
38+
}
39+
40+
public String getGasUsedRatio() {
41+
return gasUsedRatio;
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
GasOracle gasOracle = (GasOracle) o;
49+
return LastBlock.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+
public int hashCode() {
54+
return Objects.hash(LastBlock, SafeGasPrice, ProposeGasPrice, FastGasPrice, suggestBaseFee, gasUsedRatio);
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return "GasOracle{" +
60+
"LastBlock=" + LastBlock +
61+
", SafeGasPrice=" + SafeGasPrice +
62+
", ProposeGasPrice=" + ProposeGasPrice +
63+
", FastGasPrice=" + FastGasPrice +
64+
", suggestBaseFee=" + suggestBaseFee +
65+
", gasUsedRatio='" + gasUsedRatio + '\'' +
66+
'}';
67+
}
68+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ public interface AccountAPI {
109109
@NotNull
110110
List<TxERC20> txsERC20(String address) throws EtherScanException;
111111

112+
/**
113+
* All ERC-20 token txs for given address and contract address
114+
*
115+
* @param address get txs for
116+
* @param contractAddress contract address to get txs for
117+
* @param startBlock tx from this blockNumber
118+
* @param endBlock tx to this blockNumber
119+
* @return txs for address
120+
* @throws ApiException parent exception class
121+
*/
122+
@NotNull
123+
List<TxToken> txsToken(String address, String contractAddress, long startBlock, long endBlock) throws ApiException;
124+
125+
@NotNull
126+
List<TxToken> txsToken(String address, String contractAddress, long startBlock) throws ApiException;
127+
128+
@NotNull
129+
List<TxToken> txsToken(String address, String contractAddress) throws ApiException;
130+
112131
/**
113132
* All ERC-721 (NFT) token txs for given address
114133
*

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,32 @@ public List<TxERC20> txsERC20(String address, long startBlock, long endBlock) th
232232
return getRequestUsingOffset(urlParams, TxERC20ResponseTO.class);
233233
}
234234

235+
@NotNull
236+
@Override
237+
public List<TxToken> txsToken(final String address, final String contractAddress) throws ApiException {
238+
return txsToken(address, contractAddress, MIN_START_BLOCK);
239+
}
240+
241+
@NotNull
242+
@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);
245+
}
246+
247+
@NotNull
248+
@Override
249+
public List<TxToken> txsToken(final String address, final String contractAddress, final long startBlock, final long endBlock) throws ApiException {
250+
BasicUtils.validateAddress(address);
251+
final BlockParam blocks = BasicUtils.compensateBlocks(startBlock, endBlock);
252+
253+
final String offsetParam = PAGE_PARAM + "%s" + OFFSET_PARAM + OFFSET_MAX;
254+
final String blockParam = START_BLOCK_PARAM + blocks.start() + END_BLOCK_PARAM + blocks.end();
255+
final String urlParams = ACT_TX_TOKEN_ACTION + offsetParam + ADDRESS_PARAM + address
256+
+ CONTRACT_PARAM + contractAddress + blockParam + SORT_ASC_PARAM;
257+
258+
return getRequestUsingOffset(urlParams, TxTokenResponseTO.class);
259+
}
260+
235261
@NotNull
236262
@Override
237263
public List<TxERC721> txsERC721(String address) throws EtherScanException {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.api.etherscan.core.impl;
2+
3+
import io.api.etherscan.core.IGasTrackerApi;
4+
import io.api.etherscan.error.ApiException;
5+
import io.api.etherscan.error.EtherScanException;
6+
import io.api.etherscan.executor.IHttpExecutor;
7+
import io.api.etherscan.manager.IQueueManager;
8+
import io.api.etherscan.model.GasOracle;
9+
import io.api.etherscan.model.utility.GasOracleResponseTO;
10+
import org.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+
public class GasTrackerApiProvider extends BasicProvider implements IGasTrackerApi {
21+
22+
private static final String ACT_GAS_ORACLE_PARAM = ACT_PREFIX + "gasoracle";
23+
24+
GasTrackerApiProvider(final IQueueManager queue,
25+
final String baseUrl,
26+
final IHttpExecutor executor) {
27+
super(queue, "gastracker", baseUrl, executor);
28+
}
29+
30+
@NotNull
31+
@Override
32+
public GasOracle gasoracle() throws ApiException {
33+
final GasOracleResponseTO response = getRequest(ACT_GAS_ORACLE_PARAM, GasOracleResponseTO.class);
34+
if (response.getStatus() != 1)
35+
throw new EtherScanException(response);
36+
37+
return response.getResult();
38+
}
39+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.api.etherscan.core;
2+
3+
import io.api.etherscan.error.ApiException;
4+
import io.api.etherscan.model.GasOracle;
5+
import org.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+
public interface IGasTrackerApi {
14+
15+
/**
16+
* GasOracle details
17+
*
18+
* @return fast, suggested gas price
19+
* @throws ApiException parent exception class
20+
*/
21+
@NotNull
22+
GasOracle gasoracle() throws ApiException;
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.api.etherscan.model.utility;
2+
3+
import io.api.etherscan.model.GasOracle;
4+
5+
/**
6+
* ! NO DESCRIPTION !
7+
*
8+
* @author Abhay Gupta
9+
* @since 14.11.2022
10+
*/
11+
public class GasOracleResponseTO extends BaseResponseTO {
12+
13+
private GasOracle result;
14+
15+
public GasOracle getResult() {
16+
return result;
17+
}
18+
}

0 commit comments

Comments
 (0)