Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb05bd8a

Browse files
committed
[2.0.0]
Tx refactored and simplified and common parts moved to BlockTxComparable for multiple models addedGasOracle simplified and reinforcedPrice reinforcedGasEstimate.java removed as useless
1 parentd1ec9e5 commitb05bd8a

23 files changed

+368
-415
lines changed

‎src/main/java/io/goodforgod/api/etherscan/GasTrackerAPI.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
packageio.goodforgod.api.etherscan;
22

33
importio.goodforgod.api.etherscan.error.EtherScanException;
4-
importio.goodforgod.api.etherscan.model.GasEstimate;
54
importio.goodforgod.api.etherscan.model.GasOracle;
65
importio.goodforgod.api.etherscan.model.Wei;
6+
importjava.time.Duration;
77
importorg.jetbrains.annotations.NotNull;
88

99
/**
@@ -16,13 +16,13 @@
1616
publicinterfaceGasTrackerAPI {
1717

1818
/**
19-
* Returns the estimated time, in seconds, for a transaction to be confirmed on the blockchain.
19+
* Returns the estimated time for a transaction to be confirmed on the blockchain.
2020
*
21-
* @returnfast, suggested gas price
21+
* @returnestimated time
2222
* @throws EtherScanException parent exception class
2323
*/
2424
@NotNull
25-
GasEstimateestimate(@NotNullWeiwei)throwsEtherScanException;
25+
Durationestimate(@NotNullWeiwei)throwsEtherScanException;
2626

2727
/**
2828
* Returns the current Safe, Proposed and Fast gas prices.

‎src/main/java/io/goodforgod/api/etherscan/GasTrackerAPIProvider.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
importio.goodforgod.api.etherscan.error.EtherScanResponseException;
55
importio.goodforgod.api.etherscan.http.EthHttpClient;
66
importio.goodforgod.api.etherscan.manager.RequestQueueManager;
7-
importio.goodforgod.api.etherscan.model.GasEstimate;
87
importio.goodforgod.api.etherscan.model.GasOracle;
98
importio.goodforgod.api.etherscan.model.Wei;
109
importio.goodforgod.api.etherscan.model.response.GasEstimateResponseTO;
1110
importio.goodforgod.api.etherscan.model.response.GasOracleResponseTO;
11+
importjava.time.Duration;
1212
importorg.jetbrains.annotations.NotNull;
1313

1414
/**
@@ -33,13 +33,13 @@ final class GasTrackerAPIProvider extends BasicProvider implements GasTrackerAPI
3333
}
3434

3535
@Override
36-
public@NotNullGasEstimateestimate(@NotNullWeiwei)throwsEtherScanException {
36+
public@NotNullDurationestimate(@NotNullWeiwei)throwsEtherScanException {
3737
finalStringurlParams =ACT_GAS_ESTIMATE_PARAM +GASPRICE_PARAM +wei.asWei().toString();
3838
finalGasEstimateResponseTOresponse =getRequest(urlParams,GasEstimateResponseTO.class);
3939
if (response.getStatus() !=1)
4040
thrownewEtherScanResponseException(response);
4141

42-
returnnewGasEstimate(Long.parseLong(response.getResult()));
42+
returnDuration.ofSeconds(Long.parseLong(response.getResult()));
4343
}
4444

4545
@NotNull

‎src/main/java/io/goodforgod/api/etherscan/model/BaseTx.java‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
importjava.time.LocalDateTime;
77
importjava.time.ZoneOffset;
88
importjava.util.Objects;
9+
importorg.jetbrains.annotations.NotNull;
910

1011
/**
1112
* @author GoodforGod
1213
* @since 28.10.2018
1314
*/
14-
abstractclassBaseTx {
15+
abstractclassBaseTximplementsComparable<BaseTx>{
1516

1617
longblockNumber;
1718
StringtimeStamp;
@@ -84,17 +85,7 @@ public int hashCode() {
8485
}
8586

8687
@Override
87-
publicStringtoString() {
88-
return"BaseTx{" +
89-
"blockNumber=" +blockNumber +
90-
", timeStamp='" +timeStamp +'\'' +
91-
", hash='" +hash +'\'' +
92-
", from='" +from +'\'' +
93-
", to='" +to +'\'' +
94-
", contractAddress='" +contractAddress +'\'' +
95-
", input='" +input +'\'' +
96-
", gas=" +gas +
97-
", gasUsed=" +gasUsed +
98-
'}';
88+
publicintcompareTo(@NotNullBaseTxo) {
89+
returnLong.compare(blockNumber,o.blockNumber);
9990
}
10091
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
importjava.time.LocalDateTime;
77
importjava.time.ZoneOffset;
88
importjava.util.Objects;
9+
importorg.jetbrains.annotations.NotNull;
910

1011
/**
1112
* @author GoodforGod
1213
* @since 28.10.2018
1314
*/
14-
publicclassBlock {
15+
publicclassBlockimplementsComparable<Block>{
1516

1617
longblockNumber;
1718
BigIntegerblockReward;
@@ -58,10 +59,14 @@ public String toString() {
5859
"blockNumber=" +blockNumber +
5960
", blockReward=" +blockReward +
6061
", timeStamp='" +timeStamp +'\'' +
61-
", _timeStamp=" +_timeStamp +
6262
'}';
6363
}
6464

65+
@Override
66+
publicintcompareTo(@NotNullBlocko) {
67+
returnLong.compare(blockNumber,o.blockNumber);
68+
}
69+
6570
publicstaticBlockBuilderbuilder() {
6671
returnnewBlockBuilder();
6772
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
packageio.goodforgod.api.etherscan.model;
2+
3+
importjava.math.BigInteger;
4+
importjava.util.Objects;
5+
importorg.jetbrains.annotations.NotNull;
6+
7+
/**
8+
* @author Anton Kurako (GoodforGod)
9+
* @since 15.05.2023
10+
*/
11+
abstractclassBlockTxextendsBaseTx {
12+
13+
longnonce;
14+
StringblockHash;
15+
longtransactionIndex;
16+
longconfirmations;
17+
BigIntegergasPrice;
18+
BigIntegercumulativeGasUsed;
19+
20+
publiclonggetNonce() {
21+
returnnonce;
22+
}
23+
24+
publicStringgetBlockHash() {
25+
returnblockHash;
26+
}
27+
28+
publiclonggetTransactionIndex() {
29+
returntransactionIndex;
30+
}
31+
32+
publicWeigetGasPrice() {
33+
returnWei.ofWei(gasPrice);
34+
}
35+
36+
publicWeigetGasUsedCumulative() {
37+
returnWei.ofWei(cumulativeGasUsed);
38+
}
39+
40+
publiclonggetConfirmations() {
41+
returnconfirmations;
42+
}
43+
44+
@Override
45+
publicbooleanequals(Objecto) {
46+
if (this ==o)
47+
returntrue;
48+
if (!(oinstanceofBlockTx))
49+
returnfalse;
50+
if (!super.equals(o))
51+
returnfalse;
52+
BlockTxblockTx = (BlockTx)o;
53+
returnnonce ==blockTx.nonce &&transactionIndex ==blockTx.transactionIndex
54+
&&Objects.equals(blockHash,blockTx.blockHash);
55+
}
56+
57+
@Override
58+
publicinthashCode() {
59+
returnObjects.hash(super.hashCode(),nonce,blockHash,transactionIndex);
60+
}
61+
62+
@Override
63+
publicintcompareTo(@NotNullBaseTxo) {
64+
finalintsuperCompare =super.compareTo(o);
65+
if (superCompare ==0) {
66+
if (oinstanceofTx) {
67+
returnLong.compare(transactionIndex, ((Tx)o).getTransactionIndex());
68+
}elseif (oinstanceofTxErc20) {
69+
returnLong.compare(transactionIndex, ((TxErc20)o).getTransactionIndex());
70+
}elseif (oinstanceofTxErc721) {
71+
returnLong.compare(transactionIndex, ((TxErc721)o).getTransactionIndex());
72+
}elseif (oinstanceofTxErc1155) {
73+
returnLong.compare(transactionIndex, ((TxErc1155)o).getTransactionIndex());
74+
}
75+
}
76+
77+
returnsuperCompare;
78+
}
79+
}

‎src/main/java/io/goodforgod/api/etherscan/model/GasEstimate.java‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
publicclassGasOracle {
1515

1616
privateLongLastBlock;
17-
privateIntegerSafeGasPrice;
18-
privateIntegerProposeGasPrice;
19-
privateIntegerFastGasPrice;
20-
privateDoublesuggestBaseFee;
17+
privateBigIntegerSafeGasPrice;
18+
privateBigIntegerProposeGasPrice;
19+
privateBigIntegerFastGasPrice;
20+
privateBigDecimalsuggestBaseFee;
2121
privateStringgasUsedRatio;
2222

2323
protectedGasOracle() {}
@@ -27,18 +27,18 @@ public Long getLastBlock() {
2727
}
2828

2929
publicWeigetSafeGasPriceInWei() {
30-
returnWei.ofWei(BigInteger.valueOf(SafeGasPrice).multiply(BigInteger.TEN.pow(9)));
30+
returnWei.ofGwei(SafeGasPrice);
3131
}
3232

3333
publicWeigetProposeGasPriceInWei() {
34-
returnWei.ofWei(BigInteger.valueOf(ProposeGasPrice).multiply(BigInteger.TEN.pow(9)));
34+
returnWei.ofGwei(ProposeGasPrice);
3535
}
3636

3737
publicWeigetFastGasPriceInWei() {
38-
returnWei.ofWei(BigInteger.valueOf(FastGasPrice).multiply(BigInteger.TEN.pow(9)));
38+
returnWei.ofGwei(FastGasPrice);
3939
}
4040

41-
publicDoublegetSuggestBaseFee() {
41+
publicBigDecimalgetSuggestBaseFee() {
4242
returnsuggestBaseFee;
4343
}
4444

@@ -52,12 +52,14 @@ public List<BigDecimal> getGasUsedRatio() {
5252
publicbooleanequals(Objecto) {
5353
if (this ==o)
5454
returntrue;
55-
if (o ==null ||getClass() !=o.getClass())
55+
if (!(oinstanceofGasOracle))
5656
returnfalse;
5757
GasOraclegasOracle = (GasOracle)o;
58-
returnLastBlock.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+
returnObjects.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);
6163
}
6264

6365
@Override
@@ -73,7 +75,7 @@ public String toString() {
7375
", ProposeGasPrice=" +ProposeGasPrice +
7476
", FastGasPrice=" +FastGasPrice +
7577
", suggestBaseFee=" +suggestBaseFee +
76-
", gasUsedRatio='" +gasUsedRatio +'\'' +
78+
", gasUsedRatio=" +gasUsedRatio +
7779
'}';
7880
}
7981

@@ -87,7 +89,7 @@ public static final class GasOracleBuilder {
8789
privateWeisafeGasPrice;
8890
privateWeiproposeGasPrice;
8991
privateWeifastGasPrice;
90-
privateDoublesuggestBaseFee;
92+
privateBigDecimalsuggestBaseFee;
9193
privateList<BigDecimal>gasUsedRatio;
9294

9395
privateGasOracleBuilder() {}
@@ -112,7 +114,7 @@ public GasOracleBuilder withFastGasPrice(Wei fastGasPrice) {
112114
returnthis;
113115
}
114116

115-
publicGasOracleBuilderwithSuggestBaseFee(DoublesuggestBaseFee) {
117+
publicGasOracleBuilderwithSuggestBaseFee(BigDecimalsuggestBaseFee) {
116118
this.suggestBaseFee =suggestBaseFee;
117119
returnthis;
118120
}
@@ -127,18 +129,18 @@ public GasOracle build() {
127129
gasOracle.LastBlock =this.lastBlock;
128130
gasOracle.suggestBaseFee =this.suggestBaseFee;
129131
if (this.proposeGasPrice !=null) {
130-
gasOracle.ProposeGasPrice =this.proposeGasPrice.asGwei().intValue();
132+
gasOracle.ProposeGasPrice =this.proposeGasPrice.asGwei().toBigInteger();
131133
}
132134
if (this.safeGasPrice !=null) {
133-
gasOracle.SafeGasPrice =this.safeGasPrice.asGwei().intValue();
135+
gasOracle.SafeGasPrice =this.safeGasPrice.asGwei().toBigInteger();
134136
}
135137
if (this.fastGasPrice !=null) {
136-
gasOracle.FastGasPrice =this.fastGasPrice.asGwei().intValue();
138+
gasOracle.FastGasPrice =this.fastGasPrice.asGwei().toBigInteger();
137139
}
138140
if (this.gasUsedRatio !=null) {
139141
gasOracle.gasUsedRatio =this.gasUsedRatio.stream()
140142
.map(BigDecimal::toString)
141-
.collect(Collectors.joining(","));
143+
.collect(Collectors.joining(","));
142144
}
143145
returngasOracle;
144146
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,15 @@ public int hashCode() {
139139
publicStringtoString() {
140140
return"Log{" +
141141
"blockNumber='" +blockNumber +'\'' +
142-
", _blockNumber=" +_blockNumber +
143142
", address='" +address +'\'' +
144143
", transactionHash='" +transactionHash +'\'' +
145144
", transactionIndex='" +transactionIndex +'\'' +
146-
", _transactionIndex=" +_transactionIndex +
147145
", timeStamp='" +timeStamp +'\'' +
148-
", _timeStamp=" +_timeStamp +
149146
", data='" +data +'\'' +
150147
", gasPrice='" +gasPrice +'\'' +
151-
", _gasPrice=" +_gasPrice +
152148
", gasUsed='" +gasUsed +'\'' +
153-
", _gasUsed=" +_gasUsed +
154149
", topics=" +topics +
155150
", logIndex='" +logIndex +'\'' +
156-
", _logIndex=" +_logIndex +
157151
'}';
158152
}
159153

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp