Skip to content

Commit 1beaafd

Browse files
committed
[2.0.0-SNAPSHOT]
Balance contract improved Wei contract improved Supply constructor added ProxyAPI contract refactored to Wei
1 parent 873f582 commit 1beaafd

File tree

10 files changed

+33
-49
lines changed

10 files changed

+33
-49
lines changed

Diff for: src/main/java/io/goodforgod/api/etherscan/GasTrackerAPIProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class GasTrackerAPIProvider extends BasicProvider implements GasTrackerAPI
3434

3535
@Override
3636
public @NotNull GasEstimate estimate(@NotNull Wei wei) throws EtherScanException {
37-
final String urlParams = ACT_GAS_ESTIMATE_PARAM + GASPRICE_PARAM + wei.getValue().toString();
37+
final String urlParams = ACT_GAS_ESTIMATE_PARAM + GASPRICE_PARAM + wei.asWei().toString();
3838
final GasEstimateResponseTO response = getRequest(urlParams, GasEstimateResponseTO.class);
3939
if (response.getStatus() != 1)
4040
throw new EtherScanResponseException(response);

Diff for: src/main/java/io/goodforgod/api/etherscan/ProxyAPI.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.goodforgod.api.etherscan;
22

33
import io.goodforgod.api.etherscan.error.EtherScanException;
4+
import io.goodforgod.api.etherscan.model.Wei;
45
import io.goodforgod.api.etherscan.model.proxy.BlockProxy;
56
import io.goodforgod.api.etherscan.model.proxy.ReceiptProxy;
67
import io.goodforgod.api.etherscan.model.proxy.TxProxy;
7-
import java.math.BigInteger;
88
import java.util.Optional;
99
import org.jetbrains.annotations.ApiStatus.Experimental;
1010
import org.jetbrains.annotations.NotNull;
@@ -150,7 +150,7 @@ public interface ProxyAPI {
150150
* @throws EtherScanException parent exception class
151151
*/
152152
@NotNull
153-
BigInteger gasPrice() throws EtherScanException;
153+
Wei gasPrice() throws EtherScanException;
154154

155155
/**
156156
* Makes a call or transaction, which won't be added to the blockchain and returns the used gas,
@@ -161,8 +161,8 @@ public interface ProxyAPI {
161161
* @throws EtherScanException parent exception class
162162
*/
163163
@NotNull
164-
BigInteger gasEstimated(String hexData) throws EtherScanException;
164+
Wei gasEstimated(String hexData) throws EtherScanException;
165165

166166
@NotNull
167-
BigInteger gasEstimated() throws EtherScanException;
167+
Wei gasEstimated() throws EtherScanException;
168168
}

Diff for: src/main/java/io/goodforgod/api/etherscan/ProxyAPIProvider.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
66
import io.goodforgod.api.etherscan.http.EthHttpClient;
77
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
8+
import io.goodforgod.api.etherscan.model.Wei;
89
import io.goodforgod.api.etherscan.model.proxy.BlockProxy;
910
import io.goodforgod.api.etherscan.model.proxy.ReceiptProxy;
1011
import io.goodforgod.api.etherscan.model.proxy.TxProxy;
@@ -13,7 +14,6 @@
1314
import io.goodforgod.api.etherscan.model.proxy.utility.TxInfoProxyTO;
1415
import io.goodforgod.api.etherscan.model.proxy.utility.TxProxyTO;
1516
import io.goodforgod.api.etherscan.util.BasicUtils;
16-
import java.math.BigInteger;
1717
import java.util.Optional;
1818
import java.util.regex.Pattern;
1919
import org.jetbrains.annotations.NotNull;
@@ -197,29 +197,29 @@ public Optional<String> storageAt(String address, long position) throws EtherSca
197197

198198
@NotNull
199199
@Override
200-
public BigInteger gasPrice() throws EtherScanException {
200+
public Wei gasPrice() throws EtherScanException {
201201
final StringProxyTO response = getRequest(ACT_GASPRICE_PARAM, StringProxyTO.class);
202202
return (BasicUtils.isEmpty(response.getResult()))
203-
? BigInteger.valueOf(-1)
204-
: BasicUtils.parseHex(response.getResult());
203+
? new Wei(0)
204+
: new Wei(BasicUtils.parseHex(response.getResult()));
205205
}
206206

207207
@NotNull
208208
@Override
209-
public BigInteger gasEstimated() throws EtherScanException {
209+
public Wei gasEstimated() throws EtherScanException {
210210
return gasEstimated("606060405260728060106000396000f360606040526000");
211211
}
212212

213213
@NotNull
214214
@Override
215-
public BigInteger gasEstimated(String hexData) throws EtherScanException {
215+
public Wei gasEstimated(String hexData) throws EtherScanException {
216216
if (!BasicUtils.isEmpty(hexData) && BasicUtils.isNotHex(hexData))
217217
throw new EtherScanInvalidDataHexException("Data is not in hex format.");
218218

219219
final String urlParams = ACT_ESTIMATEGAS_PARAM + DATA_PARAM + hexData + GAS_PARAM + "2000000000000000";
220220
final StringProxyTO response = getRequest(urlParams, StringProxyTO.class);
221221
return (BasicUtils.isEmpty(response.getResult()))
222-
? BigInteger.valueOf(-1)
223-
: BasicUtils.parseHex(response.getResult());
222+
? new Wei(0)
223+
: new Wei(BasicUtils.parseHex(response.getResult()));
224224
}
225225
}

Diff for: src/main/java/io/goodforgod/api/etherscan/manager/RequestQueueManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public interface RequestQueueManager extends AutoCloseable {
1616
/**
1717
* Is used by default when no API KEY is provided
1818
*/
19-
RequestQueueManager ANONYMOUS = new SemaphoreRequestQueueManager(1, Duration.ofMillis(5005L));
19+
RequestQueueManager ANONYMOUS = new SemaphoreRequestQueueManager(1, Duration.ofMillis(5010L));
2020

2121
/**
2222
* Is available for all registered free API KEYs
2323
* <a href="https://docs.etherscan.io/getting-started/viewing-api-usage-statistics">Free API KEY</a>
2424
*/
25-
RequestQueueManager FREE_PLAN = new SemaphoreRequestQueueManager(5, Duration.ofMillis(1005L));
25+
RequestQueueManager FREE_PLAN = new SemaphoreRequestQueueManager(5, Duration.ofMillis(1010L));
2626

2727
RequestQueueManager UNLIMITED = new FakeRequestQueueManager();
2828

Diff for: src/main/java/io/goodforgod/api/etherscan/model/Balance.java

+2-18
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,8 @@ public String getAddress() {
2323
return address;
2424
}
2525

26-
public BigInteger getWei() {
27-
return balance.getValue();
28-
}
29-
30-
public BigInteger getKwei() {
31-
return balance.asKwei();
32-
}
33-
34-
public BigInteger getMwei() {
35-
return balance.asMwei();
36-
}
37-
38-
public BigInteger getGwei() {
39-
return balance.asGwei();
40-
}
41-
42-
public BigInteger getEther() {
43-
return balance.asEther();
26+
public Wei getBalanceInWei() {
27+
return balance;
4428
}
4529
// </editor-fold>
4630

Diff for: src/main/java/io/goodforgod/api/etherscan/model/Supply.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99
public class Supply extends Wei {
1010

11+
public Supply(long value) {
12+
super(value);
13+
}
14+
1115
public Supply(BigInteger value) {
1216
super(value);
1317
}

Diff for: src/main/java/io/goodforgod/api/etherscan/model/Wei.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Wei(BigInteger value) {
2020
}
2121

2222
// <editor-fold desc="Getters">
23-
public BigInteger getValue() {
23+
public BigInteger asWei() {
2424
return result;
2525
}
2626

Diff for: src/test/java/io/goodforgod/api/etherscan/account/AccountBalanceListTests.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ void correct() {
2929
assertNotEquals(balances.get(0).hashCode(), balances.get(1).hashCode());
3030
for (Balance balance : balances) {
3131
assertNotNull(balance.getAddress());
32-
assertNotNull(balance.getGwei());
33-
assertNotNull(balance.getKwei());
34-
assertNotNull(balance.getMwei());
35-
assertNotNull(balance.getEther());
36-
assertNotNull(balance.getGwei());
32+
assertNotNull(balance.getBalanceInWei());
3733
assertNotNull(balance.getAddress());
38-
assertNotEquals(BigInteger.ZERO, balance.getWei());
34+
assertNotEquals(BigInteger.ZERO, balance.getBalanceInWei().asWei());
3935
assertNotNull(balance.toString());
4036
}
4137
}
@@ -84,7 +80,7 @@ void correctParamWithEmptyExpectedResult() {
8480
assertEquals(2, balances.size());
8581
for (Balance balance : balances) {
8682
assertNotNull(balance.getAddress());
87-
assertEquals(0, balance.getWei().intValue());
83+
assertEquals(0, balance.getBalanceInWei().asWei().intValue());
8884
}
8985
}
9086
}

Diff for: src/test/java/io/goodforgod/api/etherscan/proxy/ProxyGasApiTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.goodforgod.api.etherscan.ApiRunner;
44
import io.goodforgod.api.etherscan.error.EtherScanInvalidDataHexException;
5-
import java.math.BigInteger;
5+
import io.goodforgod.api.etherscan.model.Wei;
66
import org.junit.jupiter.api.Test;
77

88
/**
@@ -13,23 +13,23 @@ class ProxyGasApiTests extends ApiRunner {
1313

1414
@Test
1515
void correctPrice() {
16-
BigInteger price = getApi().proxy().gasPrice();
16+
Wei price = getApi().proxy().gasPrice();
1717
assertNotNull(price);
18-
assertNotEquals(0, price.intValue());
18+
assertNotEquals(0, price.asWei().intValue());
1919
}
2020

2121
@Test
2222
void correctEstimated() {
23-
BigInteger price = getApi().proxy().gasEstimated();
23+
Wei price = getApi().proxy().gasEstimated();
2424
assertNotNull(price);
25-
assertNotEquals(0, price.intValue());
25+
assertNotEquals(0, price.asWei().intValue());
2626
}
2727

2828
@Test
2929
void correctEstimatedWithData() {
3030
String dataCustom = "606060405260728060106000396000f360606040526000606060405260728060106000396000f360606040526000";
31-
BigInteger price = getApi().proxy().gasEstimated();
32-
BigInteger priceCustom = getApi().proxy().gasEstimated(dataCustom);
31+
Wei price = getApi().proxy().gasEstimated();
32+
Wei priceCustom = getApi().proxy().gasEstimated(dataCustom);
3333
assertNotNull(price);
3434
assertNotNull(priceCustom);
3535
assertNotEquals(price, priceCustom);

Diff for: src/test/java/io/goodforgod/api/etherscan/statistic/StatisticSupplyApiTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class StatisticSupplyApiTests extends ApiRunner {
1515
void correct() {
1616
Supply supply = getApi().stats().supply();
1717
assertNotNull(supply);
18-
assertNotNull(supply.getValue());
18+
assertNotNull(supply.asWei());
1919
assertNotNull(supply.asGwei());
2020
assertNotNull(supply.asKwei());
2121
assertNotNull(supply.asMwei());

0 commit comments

Comments
 (0)