Skip to content

Commit 47e04a8

Browse files
committed
[2.0.0-SNAPSHOT]
EthSupply for StatisticAPI#supplyTotal added Javadoc fixed
1 parent 25751ab commit 47e04a8

21 files changed

+250
-73
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77

88
/**
9-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#accounts">...</a>
9+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/accounts">...</a>
1010
*
1111
* @author GoodforGod
1212
* @since 28.10.2018

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Balance balance(String address) throws EtherScanException {
6464
if (response.getStatus() != 1)
6565
throw new EtherScanResponseException(response);
6666

67-
return new Balance(address, new Wei(new BigInteger(response.getResult())));
67+
return new Balance(address, Wei.ofWei(new BigInteger(response.getResult())));
6868
}
6969

7070
@NotNull
@@ -78,7 +78,7 @@ public TokenBalance balance(String address, String contract) throws EtherScanExc
7878
if (response.getStatus() != 1)
7979
throw new EtherScanResponseException(response);
8080

81-
return new TokenBalance(address, new Wei(new BigInteger(response.getResult())), contract);
81+
return new TokenBalance(address, Wei.ofWei(new BigInteger(response.getResult())), contract);
8282
}
8383

8484
@NotNull
@@ -101,7 +101,7 @@ public List<Balance> balances(List<String> addresses) throws EtherScanException
101101

102102
if (!BasicUtils.isEmpty(response.getResult()))
103103
balances.addAll(response.getResult().stream()
104-
.map(r -> new Balance(r.getAccount(), new Wei(new BigInteger(r.getBalance()))))
104+
.map(r -> new Balance(r.getAccount(), Wei.ofWei(new BigInteger(r.getBalance()))))
105105
.collect(Collectors.toList()));
106106
}
107107

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77

88
/**
9-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#blocks">...</a>
9+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/blocks">...</a>
1010
*
1111
* @author GoodforGod
1212
* @since 30.10.2018

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.jetbrains.annotations.NotNull;
66

77
/**
8-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#contracts">...</a>
8+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/contracts">...</a>
99
*
1010
* @author GoodforGod
1111
* @since 28.10.2018

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.jetbrains.annotations.NotNull;
88

99
/**
10-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#logs">...</a>
10+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/logs">...</a>
1111
*
1212
* @author GoodforGod
1313
* @since 30.10.2018

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import org.jetbrains.annotations.NotNull;
1111

1212
/**
13-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#proxy">...</a>
13+
* EtherScan - API Descriptions
14+
* <a href="https://docs.etherscan.io/api-endpoints/geth-parity-proxy">...</a>
1415
*
1516
* @author GoodforGod
1617
* @since 30.10.2018

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public Optional<String> storageAt(String address, long position) throws EtherSca
208208
public Wei gasPrice() throws EtherScanException {
209209
final StringProxyTO response = getRequest(ACT_GASPRICE_PARAM, StringProxyTO.class);
210210
return (BasicUtils.isEmpty(response.getResult()))
211-
? new Wei(0)
212-
: new Wei(BasicUtils.parseHex(response.getResult()));
211+
? Wei.ofWei(0)
212+
: Wei.ofWei(BasicUtils.parseHex(response.getResult()));
213213
}
214214

215215
@NotNull
@@ -227,7 +227,7 @@ public Wei gasEstimated(String hexData) throws EtherScanException {
227227
final String urlParams = ACT_ESTIMATEGAS_PARAM + DATA_PARAM + hexData + GAS_PARAM + "2000000000000000";
228228
final StringProxyTO response = getRequest(urlParams, StringProxyTO.class);
229229
return (BasicUtils.isEmpty(response.getResult()))
230-
? new Wei(0)
231-
: new Wei(BasicUtils.parseHex(response.getResult()));
230+
? Wei.ofWei(0)
231+
: Wei.ofWei(BasicUtils.parseHex(response.getResult()));
232232
}
233233
}
+21-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.goodforgod.api.etherscan;
22

33
import io.goodforgod.api.etherscan.error.EtherScanException;
4+
import io.goodforgod.api.etherscan.model.EthSupply;
45
import io.goodforgod.api.etherscan.model.Price;
5-
import io.goodforgod.api.etherscan.model.Supply;
6-
import java.math.BigInteger;
6+
import io.goodforgod.api.etherscan.model.Wei;
77
import org.jetbrains.annotations.NotNull;
88

99
/**
10-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#stats">...</a>
10+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/stats-1">...</a>
1111
*
1212
* @author GoodforGod
1313
* @since 30.10.2018
@@ -16,22 +16,35 @@ public interface StatisticAPI {
1616

1717
/**
1818
* ERC20 token total Supply
19-
*
19+
* <a href=
20+
* "https://docs.etherscan.io/api-endpoints/tokens#get-erc20-token-totalsupply-by-contractaddress">EtherScan<a>
21+
*
2022
* @param contract contract address
2123
* @return token supply for specified contract
2224
* @throws EtherScanException parent exception class
2325
*/
2426
@NotNull
25-
BigInteger supply(String contract) throws EtherScanException;
27+
Wei supply(String contract) throws EtherScanException;
2628

2729
/**
28-
* Eth total supply
30+
* Returns the current amount of Ether in circulation excluding ETH2 Staking rewards and EIP1559
31+
* burnt fees.
2932
*
3033
* @return total ETH supply for moment
3134
* @throws EtherScanException parent exception class
3235
*/
3336
@NotNull
34-
Supply supply() throws EtherScanException;
37+
Wei supply() throws EtherScanException;
38+
39+
/**
40+
* Returns the current amount of Ether in circulation, ETH2 Staking rewards, EIP1559 burnt fees, and
41+
* total withdrawn ETH from the beacon chain.
42+
*
43+
* @return total ETH supply for moment
44+
* @throws EtherScanException parent exception class
45+
*/
46+
@NotNull
47+
EthSupply supplyTotal() throws EtherScanException;
3548

3649
/**
3750
* Eth last USD and BTC price
@@ -40,5 +53,5 @@ public interface StatisticAPI {
4053
* @throws EtherScanException parent exception class
4154
*/
4255
@NotNull
43-
Price lastPrice() throws EtherScanException;
56+
Price priceLast() throws EtherScanException;
4457
}

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
55
import io.goodforgod.api.etherscan.http.EthHttpClient;
66
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
7+
import io.goodforgod.api.etherscan.model.EthSupply;
78
import io.goodforgod.api.etherscan.model.Price;
8-
import io.goodforgod.api.etherscan.model.Supply;
9+
import io.goodforgod.api.etherscan.model.Wei;
10+
import io.goodforgod.api.etherscan.model.response.EthSupplyResponseTO;
911
import io.goodforgod.api.etherscan.model.response.PriceResponseTO;
1012
import io.goodforgod.api.etherscan.model.response.StringResponseTO;
1113
import io.goodforgod.api.etherscan.util.BasicUtils;
@@ -22,6 +24,7 @@
2224
final class StatisticAPIProvider extends BasicProvider implements StatisticAPI {
2325

2426
private static final String ACT_SUPPLY_PARAM = ACT_PREFIX + "ethsupply";
27+
private static final String ACT_SUPPLY2_PARAM = ACT_PREFIX + "ethsupply2";
2528
private static final String ACT_TOKEN_SUPPLY_PARAM = ACT_PREFIX + "tokensupply";
2629
private static final String ACT_LASTPRICE_PARAM = ACT_PREFIX + "ethprice";
2730

@@ -36,30 +39,39 @@ final class StatisticAPIProvider extends BasicProvider implements StatisticAPI {
3639

3740
@NotNull
3841
@Override
39-
public Supply supply() throws EtherScanException {
42+
public Wei supply() throws EtherScanException {
4043
final StringResponseTO response = getRequest(ACT_SUPPLY_PARAM, StringResponseTO.class);
4144
if (response.getStatus() != 1)
4245
throw new EtherScanResponseException(response);
4346

44-
return new Supply(new BigInteger(response.getResult()));
47+
return Wei.ofWei(new BigInteger(response.getResult()));
48+
}
49+
50+
@Override
51+
public @NotNull EthSupply supplyTotal() throws EtherScanException {
52+
final EthSupplyResponseTO response = getRequest(ACT_SUPPLY2_PARAM, EthSupplyResponseTO.class);
53+
if (response.getStatus() != 1)
54+
throw new EtherScanResponseException(response);
55+
56+
return response.getResult();
4557
}
4658

4759
@NotNull
4860
@Override
49-
public BigInteger supply(String contract) throws EtherScanException {
61+
public Wei supply(String contract) throws EtherScanException {
5062
BasicUtils.validateAddress(contract);
5163

5264
final String urlParams = ACT_TOKEN_SUPPLY_PARAM + CONTRACT_ADDRESS_PARAM + contract;
5365
final StringResponseTO response = getRequest(urlParams, StringResponseTO.class);
5466
if (response.getStatus() != 1)
5567
throw new EtherScanResponseException(response);
5668

57-
return new BigInteger(response.getResult());
69+
return Wei.ofWei(new BigInteger(response.getResult()));
5870
}
5971

6072
@NotNull
6173
@Override
62-
public Price lastPrice() throws EtherScanException {
74+
public Price priceLast() throws EtherScanException {
6375
final PriceResponseTO response = getRequest(ACT_LASTPRICE_PARAM, PriceResponseTO.class);
6476
if (response.getStatus() != 1)
6577
throw new EtherScanResponseException(response);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jetbrains.annotations.NotNull;
77

88
/**
9-
* EtherScan - API Descriptions <a href="https://etherscan.io/apis#transactions">...</a>
9+
* EtherScan - API Descriptions <a href="https://docs.etherscan.io/api-endpoints/stats">...</a>
1010
*
1111
* @author GoodforGod
1212
* @since 30.10.2018
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package io.goodforgod.api.etherscan.model;
2+
3+
import java.math.BigInteger;
4+
import java.util.Objects;
5+
6+
/**
7+
* Please Add Description Here.
8+
*
9+
* @author Anton Kurako (GoodforGod)
10+
* @since 14.05.2023
11+
*/
12+
public class EthSupply {
13+
14+
private String EthSupply;
15+
private String Eth2Staking;
16+
private String BurntFees;
17+
private String WithdrawnTotal;
18+
19+
public Wei getEthSupply() {
20+
return Wei.ofWei(new BigInteger(EthSupply));
21+
}
22+
23+
public Wei getEth2Staking() {
24+
return Wei.ofWei(new BigInteger(Eth2Staking));
25+
}
26+
27+
public Wei getBurntFees() {
28+
return Wei.ofWei(new BigInteger(BurntFees));
29+
}
30+
31+
public Wei getTotal() {
32+
final BigInteger total = getEthSupply().asWei()
33+
.add(getEth2Staking().asWei())
34+
.min(getBurntFees().asWei());
35+
return Wei.ofWei(total);
36+
}
37+
38+
public Wei getWithdrawnTotal() {
39+
return Wei.ofWei(new BigInteger(WithdrawnTotal));
40+
}
41+
42+
@Override
43+
public boolean equals(Object o) {
44+
if (this == o)
45+
return true;
46+
if (!(o instanceof EthSupply))
47+
return false;
48+
EthSupply ethSupply = (EthSupply) o;
49+
return Objects.equals(EthSupply, ethSupply.EthSupply) && Objects.equals(Eth2Staking, ethSupply.Eth2Staking)
50+
&& Objects.equals(BurntFees, ethSupply.BurntFees) && Objects.equals(WithdrawnTotal, ethSupply.WithdrawnTotal);
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(EthSupply, Eth2Staking, BurntFees, WithdrawnTotal);
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return "EthSupply{" +
61+
"EthSupply='" + EthSupply + '\'' +
62+
", Eth2Staking='" + Eth2Staking + '\'' +
63+
", BurntFees='" + BurntFees + '\'' +
64+
", WithdrawnTotal='" + WithdrawnTotal + '\'' +
65+
'}';
66+
}
67+
68+
public static EthSupplyBuilder builder() {
69+
return new EthSupplyBuilder();
70+
}
71+
72+
public static final class EthSupplyBuilder {
73+
74+
private Wei ethSupply;
75+
private Wei eth2Staking;
76+
private Wei burntFees;
77+
private Wei withdrawnTotal;
78+
79+
private EthSupplyBuilder() {}
80+
81+
public EthSupplyBuilder withEthSupply(Wei ethSupply) {
82+
this.ethSupply = ethSupply;
83+
return this;
84+
}
85+
86+
public EthSupplyBuilder withEth2Staking(Wei eth2Staking) {
87+
this.eth2Staking = eth2Staking;
88+
return this;
89+
}
90+
91+
public EthSupplyBuilder withBurntFees(Wei burntFees) {
92+
this.burntFees = burntFees;
93+
return this;
94+
}
95+
96+
public EthSupplyBuilder withWithdrawnTotal(Wei withdrawnTotal) {
97+
this.withdrawnTotal = withdrawnTotal;
98+
return this;
99+
}
100+
101+
public EthSupply build() {
102+
EthSupply ethSupply = new EthSupply();
103+
ethSupply.BurntFees = this.burntFees.toString();
104+
ethSupply.Eth2Staking = this.eth2Staking.toString();
105+
ethSupply.EthSupply = this.ethSupply.toString();
106+
ethSupply.WithdrawnTotal = this.withdrawnTotal.toString();
107+
return ethSupply;
108+
}
109+
}
110+
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public Long getLastBlock() {
2727
}
2828

2929
public Wei getSafeGasPriceInWei() {
30-
return new Wei(BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9)));
30+
return Wei.ofWei(BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9)));
3131
}
3232

3333
public Wei getProposeGasPriceInWei() {
34-
return new Wei(BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9)));
34+
return Wei.ofWei(BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9)));
3535
}
3636

3737
public Wei getFastGasPriceInWei() {
38-
return new Wei(BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9)));
38+
return Wei.ofWei(BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9)));
3939
}
4040

4141
public Double getSuggestBaseFee() {

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

-18
This file was deleted.

0 commit comments

Comments
 (0)