14
14
public class GasOracle {
15
15
16
16
private Long LastBlock ;
17
- private Integer SafeGasPrice ;
18
- private Integer ProposeGasPrice ;
19
- private Integer FastGasPrice ;
20
- private Double suggestBaseFee ;
17
+ private BigInteger SafeGasPrice ;
18
+ private BigInteger ProposeGasPrice ;
19
+ private BigInteger FastGasPrice ;
20
+ private BigDecimal suggestBaseFee ;
21
21
private String gasUsedRatio ;
22
22
23
23
protected GasOracle () {}
@@ -27,18 +27,18 @@ public Long getLastBlock() {
27
27
}
28
28
29
29
public Wei getSafeGasPriceInWei () {
30
- return Wei .ofWei ( BigInteger . valueOf ( SafeGasPrice ). multiply ( BigInteger . TEN . pow ( 9 )) );
30
+ return Wei .ofGwei ( SafeGasPrice );
31
31
}
32
32
33
33
public Wei getProposeGasPriceInWei () {
34
- return Wei .ofWei ( BigInteger . valueOf ( ProposeGasPrice ). multiply ( BigInteger . TEN . pow ( 9 )) );
34
+ return Wei .ofGwei ( ProposeGasPrice );
35
35
}
36
36
37
37
public Wei getFastGasPriceInWei () {
38
- return Wei .ofWei ( BigInteger . valueOf ( FastGasPrice ). multiply ( BigInteger . TEN . pow ( 9 )) );
38
+ return Wei .ofGwei ( FastGasPrice );
39
39
}
40
40
41
- public Double getSuggestBaseFee () {
41
+ public BigDecimal getSuggestBaseFee () {
42
42
return suggestBaseFee ;
43
43
}
44
44
@@ -52,12 +52,14 @@ public List<BigDecimal> getGasUsedRatio() {
52
52
public boolean equals (Object o ) {
53
53
if (this == o )
54
54
return true ;
55
- if (o == null || getClass () != o . getClass ( ))
55
+ if (!( o instanceof GasOracle ))
56
56
return false ;
57
57
GasOracle gasOracle = (GasOracle ) o ;
58
- return LastBlock .equals (gasOracle .LastBlock ) && SafeGasPrice .equals (gasOracle .SafeGasPrice )
59
- && ProposeGasPrice .equals (gasOracle .ProposeGasPrice ) && FastGasPrice .equals (gasOracle .FastGasPrice )
60
- && suggestBaseFee .equals (gasOracle .suggestBaseFee ) && gasUsedRatio .equals (gasOracle .gasUsedRatio );
58
+ return Objects .equals (LastBlock , gasOracle .LastBlock ) && Objects .equals (SafeGasPrice , gasOracle .SafeGasPrice )
59
+ && Objects .equals (ProposeGasPrice , gasOracle .ProposeGasPrice )
60
+ && Objects .equals (FastGasPrice , gasOracle .FastGasPrice )
61
+ && Objects .equals (suggestBaseFee , gasOracle .suggestBaseFee )
62
+ && Objects .equals (gasUsedRatio , gasOracle .gasUsedRatio );
61
63
}
62
64
63
65
@ Override
@@ -73,7 +75,7 @@ public String toString() {
73
75
", ProposeGasPrice=" + ProposeGasPrice +
74
76
", FastGasPrice=" + FastGasPrice +
75
77
", suggestBaseFee=" + suggestBaseFee +
76
- ", gasUsedRatio=' " + gasUsedRatio + '\'' +
78
+ ", gasUsedRatio=" + gasUsedRatio +
77
79
'}' ;
78
80
}
79
81
@@ -87,7 +89,7 @@ public static final class GasOracleBuilder {
87
89
private Wei safeGasPrice ;
88
90
private Wei proposeGasPrice ;
89
91
private Wei fastGasPrice ;
90
- private Double suggestBaseFee ;
92
+ private BigDecimal suggestBaseFee ;
91
93
private List <BigDecimal > gasUsedRatio ;
92
94
93
95
private GasOracleBuilder () {}
@@ -112,7 +114,7 @@ public GasOracleBuilder withFastGasPrice(Wei fastGasPrice) {
112
114
return this ;
113
115
}
114
116
115
- public GasOracleBuilder withSuggestBaseFee (Double suggestBaseFee ) {
117
+ public GasOracleBuilder withSuggestBaseFee (BigDecimal suggestBaseFee ) {
116
118
this .suggestBaseFee = suggestBaseFee ;
117
119
return this ;
118
120
}
@@ -127,18 +129,18 @@ public GasOracle build() {
127
129
gasOracle .LastBlock = this .lastBlock ;
128
130
gasOracle .suggestBaseFee = this .suggestBaseFee ;
129
131
if (this .proposeGasPrice != null ) {
130
- gasOracle .ProposeGasPrice = this .proposeGasPrice .asGwei ().intValue ();
132
+ gasOracle .ProposeGasPrice = this .proposeGasPrice .asGwei ().toBigInteger ();
131
133
}
132
134
if (this .safeGasPrice != null ) {
133
- gasOracle .SafeGasPrice = this .safeGasPrice .asGwei ().intValue ();
135
+ gasOracle .SafeGasPrice = this .safeGasPrice .asGwei ().toBigInteger ();
134
136
}
135
137
if (this .fastGasPrice != null ) {
136
- gasOracle .FastGasPrice = this .fastGasPrice .asGwei ().intValue ();
138
+ gasOracle .FastGasPrice = this .fastGasPrice .asGwei ().toBigInteger ();
137
139
}
138
140
if (this .gasUsedRatio != null ) {
139
141
gasOracle .gasUsedRatio = this .gasUsedRatio .stream ()
140
142
.map (BigDecimal ::toString )
141
- .collect (Collectors .joining (", " ));
143
+ .collect (Collectors .joining ("," ));
142
144
}
143
145
return gasOracle ;
144
146
}
0 commit comments