Skip to content

Commit 225b211

Browse files
committed
[2.0.0-SNAPSHOT]
Tx Responses restored GasOracle refactored and improved ModelBuilderTests added
1 parent a9dd8e0 commit 225b211

24 files changed

+407
-63
lines changed

src/main/java/io/goodforgod/api/etherscan/model/Block.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class Block {
1818
@Expose(deserialize = false, serialize = false)
1919
LocalDateTime _timeStamp;
2020

21+
protected Block() {}
22+
2123
// <editor-fold desc="Getter">
2224
public long getBlockNumber() {
2325
return blockNumber;

src/main/java/io/goodforgod/api/etherscan/model/BlockUncle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public static class Uncle {
1818
private BigInteger blockreward;
1919
private int unclePosition;
2020

21+
private Uncle() {}
22+
2123
// <editor-fold desc="Getters">
2224
public String getMiner() {
2325
return miner;
@@ -113,6 +115,10 @@ public Uncle build() {
113115
private List<Uncle> uncles;
114116
private String uncleInclusionReward;
115117

118+
protected BlockUncle() {
119+
super();
120+
}
121+
116122
// <editor-fold desc="Getters">
117123
public boolean isEmpty() {
118124
return getBlockNumber() == 0 && getBlockReward() == null

src/main/java/io/goodforgod/api/etherscan/model/GasOracle.java

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package io.goodforgod.api.etherscan.model;
22

3+
import java.math.BigDecimal;
34
import java.math.BigInteger;
5+
import java.util.Arrays;
6+
import java.util.List;
47
import java.util.Objects;
8+
import java.util.stream.Collectors;
59

610
/**
711
* @author Abhay Gupta
@@ -16,28 +20,32 @@ public class GasOracle {
1620
private Double suggestBaseFee;
1721
private String gasUsedRatio;
1822

23+
protected GasOracle() {}
24+
1925
public Long getLastBlock() {
2026
return LastBlock;
2127
}
2228

23-
public BigInteger getSafeGasPriceInWei() {
24-
return BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9));
29+
public Wei getSafeGasPriceInWei() {
30+
return new Wei(BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9)));
2531
}
2632

27-
public BigInteger getProposeGasPriceInWei() {
28-
return BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9));
33+
public Wei getProposeGasPriceInWei() {
34+
return new Wei(BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9)));
2935
}
3036

31-
public BigInteger getFastGasPriceInWei() {
32-
return BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9));
37+
public Wei getFastGasPriceInWei() {
38+
return new Wei(BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9)));
3339
}
3440

3541
public Double getSuggestBaseFee() {
3642
return suggestBaseFee;
3743
}
3844

39-
public String getGasUsedRatio() {
40-
return gasUsedRatio;
45+
public List<BigDecimal> getGasUsedRatio() {
46+
return Arrays.stream(gasUsedRatio.split(","))
47+
.map(BigDecimal::new)
48+
.collect(Collectors.toList());
4149
}
4250

4351
@Override
@@ -75,32 +83,32 @@ public static GasOracleBuilder builder() {
7583

7684
public static final class GasOracleBuilder {
7785

78-
private Long LastBlock;
79-
private Integer SafeGasPrice;
80-
private Integer ProposeGasPrice;
81-
private Integer FastGasPrice;
86+
private Long lastBlock;
87+
private Wei safeGasPrice;
88+
private Wei proposeGasPrice;
89+
private Wei fastGasPrice;
8290
private Double suggestBaseFee;
83-
private String gasUsedRatio;
91+
private List<BigDecimal> gasUsedRatio;
8492

8593
private GasOracleBuilder() {}
8694

87-
public GasOracleBuilder withLastBlock(Long LastBlock) {
88-
this.LastBlock = LastBlock;
95+
public GasOracleBuilder withLastBlock(Long lastBlock) {
96+
this.lastBlock = lastBlock;
8997
return this;
9098
}
9199

92-
public GasOracleBuilder withSafeGasPrice(Integer SafeGasPrice) {
93-
this.SafeGasPrice = SafeGasPrice;
100+
public GasOracleBuilder withSafeGasPrice(Wei safeGasPrice) {
101+
this.safeGasPrice = safeGasPrice;
94102
return this;
95103
}
96104

97-
public GasOracleBuilder withProposeGasPrice(Integer ProposeGasPrice) {
98-
this.ProposeGasPrice = ProposeGasPrice;
105+
public GasOracleBuilder withProposeGasPrice(Wei proposeGasPrice) {
106+
this.proposeGasPrice = proposeGasPrice;
99107
return this;
100108
}
101109

102-
public GasOracleBuilder withFastGasPrice(Integer FastGasPrice) {
103-
this.FastGasPrice = FastGasPrice;
110+
public GasOracleBuilder withFastGasPrice(Wei fastGasPrice) {
111+
this.fastGasPrice = fastGasPrice;
104112
return this;
105113
}
106114

@@ -109,19 +117,29 @@ public GasOracleBuilder withSuggestBaseFee(Double suggestBaseFee) {
109117
return this;
110118
}
111119

112-
public GasOracleBuilder withGasUsedRatio(String gasUsedRatio) {
120+
public GasOracleBuilder withGasUsedRatio(List<BigDecimal> gasUsedRatio) {
113121
this.gasUsedRatio = gasUsedRatio;
114122
return this;
115123
}
116124

117125
public GasOracle build() {
118126
GasOracle gasOracle = new GasOracle();
119-
gasOracle.ProposeGasPrice = this.ProposeGasPrice;
120-
gasOracle.LastBlock = this.LastBlock;
127+
gasOracle.LastBlock = this.lastBlock;
121128
gasOracle.suggestBaseFee = this.suggestBaseFee;
122-
gasOracle.SafeGasPrice = this.SafeGasPrice;
123-
gasOracle.FastGasPrice = this.FastGasPrice;
124-
gasOracle.gasUsedRatio = this.gasUsedRatio;
129+
if (this.proposeGasPrice != null) {
130+
gasOracle.ProposeGasPrice = this.proposeGasPrice.asGwei().intValue();
131+
}
132+
if (this.safeGasPrice != null) {
133+
gasOracle.SafeGasPrice = this.safeGasPrice.asGwei().intValue();
134+
}
135+
if (this.fastGasPrice != null) {
136+
gasOracle.FastGasPrice = this.fastGasPrice.asGwei().intValue();
137+
}
138+
if (this.gasUsedRatio != null) {
139+
gasOracle.gasUsedRatio = this.gasUsedRatio.stream()
140+
.map(BigDecimal::toString)
141+
.collect(Collectors.joining(", "));
142+
}
125143
return gasOracle;
126144
}
127145
}

src/main/java/io/goodforgod/api/etherscan/model/Log.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class Log {
3737
@Expose(deserialize = false, serialize = false)
3838
private Long _logIndex;
3939

40+
protected Log() {}
41+
4042
// <editor-fold desc="Getters">
4143
public Long getBlockNumber() {
4244
if (_blockNumber == null && !BasicUtils.isEmpty(blockNumber)) {

src/main/java/io/goodforgod/api/etherscan/model/Price.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class Price {
1919
@Expose(deserialize = false, serialize = false)
2020
private LocalDateTime _ethbtc_timestamp;
2121

22+
protected Price() {}
23+
2224
public double inUsd() {
2325
return ethusd;
2426
}
@@ -101,22 +103,22 @@ public static final class PriceBuilder {
101103

102104
private PriceBuilder() {}
103105

104-
public PriceBuilder withEthusd(double ethusd) {
106+
public PriceBuilder withEthUsd(double ethusd) {
105107
this.ethusd = ethusd;
106108
return this;
107109
}
108110

109-
public PriceBuilder withEthbtc(double ethbtc) {
111+
public PriceBuilder withEthBtc(double ethbtc) {
110112
this.ethbtc = ethbtc;
111113
return this;
112114
}
113115

114-
public PriceBuilder withEthusdTimestamp(LocalDateTime ethusdTimestamp) {
116+
public PriceBuilder withEthUsdTimestamp(LocalDateTime ethusdTimestamp) {
115117
this.ethusdTimestamp = ethusdTimestamp;
116118
return this;
117119
}
118120

119-
public PriceBuilder withEthbtcTimestamp(LocalDateTime ethbtcTimestamp) {
121+
public PriceBuilder withEthBtcTimestamp(LocalDateTime ethbtcTimestamp) {
120122
this.ethbtcTimestamp = ethbtcTimestamp;
121123
return this;
122124
}

src/main/java/io/goodforgod/api/etherscan/model/Status.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class Status {
1616
private int isError;
1717
private String errDescription;
1818

19+
protected Status() {}
20+
1921
public boolean haveError() {
2022
return isError == 1;
2123
}

src/main/java/io/goodforgod/api/etherscan/model/Tx.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Tx extends BaseTx {
2222
private String isError;
2323
private String txreceipt_status;
2424

25+
protected Tx() {}
26+
2527
// <editor-fold desc="Getters">
2628
public BigInteger getValue() {
2729
return value;

src/main/java/io/goodforgod/api/etherscan/model/TxErc1155.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public class TxErc1155 extends BaseTx {
1818
private String tokenSymbol;
1919
private String tokenValue;
2020
private int transactionIndex;
21-
private long gasPrice;
22-
private long cumulativeGasUsed;
21+
private BigInteger gasPrice;
22+
private BigInteger cumulativeGasUsed;
2323
private long confirmations;
2424

25+
protected TxErc1155() {}
26+
2527
// <editor-fold desc="Getters">
2628
public long getNonce() {
2729
return nonce;
@@ -51,11 +53,11 @@ public int getTransactionIndex() {
5153
return transactionIndex;
5254
}
5355

54-
public long getGasPrice() {
56+
public BigInteger getGasPrice() {
5557
return gasPrice;
5658
}
5759

58-
public long getCumulativeGasUsed() {
60+
public BigInteger getCumulativeGasUsed() {
5961
return cumulativeGasUsed;
6062
}
6163

@@ -120,8 +122,8 @@ public static final class TxErc1155Builder {
120122
private String tokenSymbol;
121123
private String tokenValue;
122124
private int transactionIndex;
123-
private long gasPrice;
124-
private long cumulativeGasUsed;
125+
private BigInteger gasPrice;
126+
private BigInteger cumulativeGasUsed;
125127
private long confirmations;
126128

127129
private TxErc1155Builder() {}
@@ -206,12 +208,12 @@ public TxErc1155Builder withTransactionIndex(int transactionIndex) {
206208
return this;
207209
}
208210

209-
public TxErc1155Builder withGasPrice(long gasPrice) {
211+
public TxErc1155Builder withGasPrice(BigInteger gasPrice) {
210212
this.gasPrice = gasPrice;
211213
return this;
212214
}
213215

214-
public TxErc1155Builder withCumulativeGasUsed(long cumulativeGasUsed) {
216+
public TxErc1155Builder withCumulativeGasUsed(BigInteger cumulativeGasUsed) {
215217
this.cumulativeGasUsed = cumulativeGasUsed;
216218
return this;
217219
}

src/main/java/io/goodforgod/api/etherscan/model/TxErc20.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public class TxErc20 extends BaseTx {
1818
private String tokenSymbol;
1919
private String tokenDecimal;
2020
private int transactionIndex;
21-
private long gasPrice;
22-
private long cumulativeGasUsed;
21+
private BigInteger gasPrice;
22+
private BigInteger cumulativeGasUsed;
2323
private long confirmations;
2424

25+
protected TxErc20() {}
26+
2527
// <editor-fold desc="Getters">
2628
public long getNonce() {
2729
return nonce;
@@ -51,11 +53,11 @@ public int getTransactionIndex() {
5153
return transactionIndex;
5254
}
5355

54-
public long getGasPrice() {
56+
public BigInteger getGasPrice() {
5557
return gasPrice;
5658
}
5759

58-
public long getCumulativeGasUsed() {
60+
public BigInteger getCumulativeGasUsed() {
5961
return cumulativeGasUsed;
6062
}
6163

@@ -120,8 +122,8 @@ public static final class TxERC20Builder {
120122
private String tokenSymbol;
121123
private String tokenDecimal;
122124
private int transactionIndex;
123-
private long gasPrice;
124-
private long cumulativeGasUsed;
125+
private BigInteger gasPrice;
126+
private BigInteger cumulativeGasUsed;
125127
private long confirmations;
126128

127129
private TxERC20Builder() {}
@@ -206,12 +208,12 @@ public TxERC20Builder withTransactionIndex(int transactionIndex) {
206208
return this;
207209
}
208210

209-
public TxERC20Builder withGasPrice(long gasPrice) {
211+
public TxERC20Builder withGasPrice(BigInteger gasPrice) {
210212
this.gasPrice = gasPrice;
211213
return this;
212214
}
213215

214-
public TxERC20Builder withCumulativeGasUsed(long cumulativeGasUsed) {
216+
public TxERC20Builder withCumulativeGasUsed(BigInteger cumulativeGasUsed) {
215217
this.cumulativeGasUsed = cumulativeGasUsed;
216218
return this;
217219
}

src/main/java/io/goodforgod/api/etherscan/model/TxErc721.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public class TxErc721 extends BaseTx {
1818
private String tokenSymbol;
1919
private String tokenDecimal;
2020
private int transactionIndex;
21-
private long gasPrice;
22-
private long cumulativeGasUsed;
21+
private BigInteger gasPrice;
22+
private BigInteger cumulativeGasUsed;
2323
private long confirmations;
2424

25+
protected TxErc721() {}
26+
2527
// <editor-fold desc="Getters">
2628
public long getNonce() {
2729
return nonce;
@@ -51,11 +53,11 @@ public int getTransactionIndex() {
5153
return transactionIndex;
5254
}
5355

54-
public long getGasPrice() {
56+
public BigInteger getGasPrice() {
5557
return gasPrice;
5658
}
5759

58-
public long getCumulativeGasUsed() {
60+
public BigInteger getCumulativeGasUsed() {
5961
return cumulativeGasUsed;
6062
}
6163

@@ -120,8 +122,8 @@ public static final class TxERC721Builder {
120122
private String tokenSymbol;
121123
private String tokenDecimal;
122124
private int transactionIndex;
123-
private long gasPrice;
124-
private long cumulativeGasUsed;
125+
private BigInteger gasPrice;
126+
private BigInteger cumulativeGasUsed;
125127
private long confirmations;
126128

127129
private TxERC721Builder() {}
@@ -206,12 +208,12 @@ public TxERC721Builder withTransactionIndex(int transactionIndex) {
206208
return this;
207209
}
208210

209-
public TxERC721Builder withGasPrice(long gasPrice) {
211+
public TxERC721Builder withGasPrice(BigInteger gasPrice) {
210212
this.gasPrice = gasPrice;
211213
return this;
212214
}
213215

214-
public TxERC721Builder withCumulativeGasUsed(long cumulativeGasUsed) {
216+
public TxERC721Builder withCumulativeGasUsed(BigInteger cumulativeGasUsed) {
215217
this.cumulativeGasUsed = cumulativeGasUsed;
216218
return this;
217219
}

0 commit comments

Comments
 (0)