Skip to content

Commit e026400

Browse files
authored
Merge pull request GoodforGod#2 from GoodforGod/develop
1.0.2 Release
2 parents 97197ad + 44a5fe4 commit e026400

File tree

13 files changed

+56
-120
lines changed

13 files changed

+56
-120
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Library supports all available EtherScan *API* calls for all available *Ethereum
1414
<dependency>
1515
<groupId>com.github.goodforgod</groupId>
1616
<artifactId>java-etherscan-api</artifactId>
17-
<version>1.0.1</version>
17+
<version>1.0.2</version>
1818
</dependency>
1919
```
2020

2121
**Gradle**
2222
```groovy
2323
dependencies {
24-
compile 'com.github.goodforgod:java-etherscan-api:1.0.1'
24+
compile 'com.github.goodforgod:java-etherscan-api:1.0.2'
2525
}
2626
```
2727

@@ -165,6 +165,8 @@ Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) resp
165165

166166
## Version History
167167

168+
**1.0.2** - Minor http client improvements.
169+
168170
**1.0.1** - Gorli & TOBALABA networks support.
169171

170172
**1.0.0** - Initial project with all API functionality, for all available networks, with tests coverage for all cases.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.goodforgod</groupId>
77
<artifactId>java-etherscan-api</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.0.2</version>
99
<packaging>jar</packaging>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import io.api.etherscan.util.BasicUtils;
77

88
import java.io.BufferedReader;
9-
import java.io.DataOutputStream;
109
import java.io.IOException;
1110
import java.io.InputStreamReader;
11+
import java.io.OutputStream;
1212
import java.net.HttpURLConnection;
1313
import java.net.SocketTimeoutException;
1414
import java.net.URL;
15+
import java.nio.charset.StandardCharsets;
1516
import java.util.HashMap;
1617
import java.util.Map;
1718
import java.util.zip.GZIPInputStream;
@@ -103,14 +104,16 @@ public String get(final String urlAsString) {
103104
public String post(final String urlAsString, final String dataToPost) {
104105
try {
105106
final HttpURLConnection connection = buildConnection(urlAsString, "POST");
106-
final String contentLength = (BasicUtils.isEmpty(dataToPost)) ? "0" : String.valueOf(dataToPost.length());
107-
connection.setRequestProperty("content-length", contentLength);
107+
final String contentLength = (BasicUtils.isBlank(dataToPost)) ? "0" : String.valueOf(dataToPost.length());
108+
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
109+
connection.setRequestProperty("Content-Length", contentLength);
110+
connection.setFixedLengthStreamingMode(dataToPost.length());
108111

109112
connection.setDoOutput(true);
110-
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
111-
wr.writeBytes(dataToPost);
112-
wr.flush();
113-
wr.close();
113+
connection.connect();
114+
try (OutputStream os = connection.getOutputStream()) {
115+
os.write(dataToPost.getBytes(StandardCharsets.UTF_8));
116+
}
114117

115118
final int status = connection.getResponseCode();
116119
if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) {
@@ -141,13 +144,13 @@ private String readData(final HttpURLConnection connection) throws IOException {
141144
}
142145

143146
private InputStreamReader getStreamReader(final HttpURLConnection connection) throws IOException {
144-
final boolean haveEncoding = connection.getContentEncoding() != null;
145-
146-
if (haveEncoding && "gzip".equals(connection.getContentEncoding()))
147-
return new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "utf-8");
148-
else if (haveEncoding && "deflate".equals(connection.getContentEncoding()))
149-
return new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "utf-8");
150-
else
151-
return new InputStreamReader(connection.getInputStream(), "utf-8");
147+
switch (String.valueOf(connection.getContentEncoding())) {
148+
case "gzip":
149+
return new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "utf-8");
150+
case "deflate":
151+
return new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "utf-8");
152+
default:
153+
return new InputStreamReader(connection.getInputStream(), "utf-8");
154+
}
152155
}
153156
}

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,37 +73,26 @@ public BigInteger getGasUsed() {
7373
@Override
7474
public boolean equals(Object o) {
7575
if (this == o) return true;
76-
if (o == null || getClass() != o.getClass()) return false;
76+
if (!(o instanceof BaseTx)) return false;
7777

7878
BaseTx baseTx = (BaseTx) o;
7979

8080
if (blockNumber != baseTx.blockNumber) return false;
8181
if (timeStamp != null ? !timeStamp.equals(baseTx.timeStamp) : baseTx.timeStamp != null) return false;
82-
if (_timeStamp != null ? !_timeStamp.equals(baseTx._timeStamp) : baseTx._timeStamp != null) return false;
8382
if (hash != null ? !hash.equals(baseTx.hash) : baseTx.hash != null) return false;
8483
if (from != null ? !from.equals(baseTx.from) : baseTx.from != null) return false;
8584
if (to != null ? !to.equals(baseTx.to) : baseTx.to != null) return false;
86-
if (value != null ? !value.equals(baseTx.value) : baseTx.value != null) return false;
87-
if (contractAddress != null ? !contractAddress.equals(baseTx.contractAddress) : baseTx.contractAddress != null)
88-
return false;
89-
if (input != null ? !input.equals(baseTx.input) : baseTx.input != null) return false;
90-
if (gas != null ? !gas.equals(baseTx.gas) : baseTx.gas != null) return false;
91-
return gasUsed != null ? gasUsed.equals(baseTx.gasUsed) : baseTx.gasUsed == null;
85+
return value != null ? value.equals(baseTx.value) : baseTx.value == null;
9286
}
9387

9488
@Override
9589
public int hashCode() {
9690
int result = (int) (blockNumber ^ (blockNumber >>> 32));
9791
result = 31 * result + (timeStamp != null ? timeStamp.hashCode() : 0);
98-
result = 31 * result + (_timeStamp != null ? _timeStamp.hashCode() : 0);
9992
result = 31 * result + (hash != null ? hash.hashCode() : 0);
10093
result = 31 * result + (from != null ? from.hashCode() : 0);
10194
result = 31 * result + (to != null ? to.hashCode() : 0);
10295
result = 31 * result + (value != null ? value.hashCode() : 0);
103-
result = 31 * result + (contractAddress != null ? contractAddress.hashCode() : 0);
104-
result = 31 * result + (input != null ? input.hashCode() : 0);
105-
result = 31 * result + (gas != null ? gas.hashCode() : 0);
106-
result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0);
10796
return result;
10897
}
10998

@@ -112,7 +101,6 @@ public String toString() {
112101
return "BaseTx{" +
113102
"blockNumber=" + blockNumber +
114103
", timeStamp='" + timeStamp + '\'' +
115-
", _timeStamp=" + _timeStamp +
116104
", hash='" + hash + '\'' +
117105
", from='" + from + '\'' +
118106
", to='" + to + '\'' +

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,44 +106,20 @@ public boolean equals(Object o) {
106106
Log log = (Log) o;
107107

108108
if (blockNumber != null ? !blockNumber.equals(log.blockNumber) : log.blockNumber != null) return false;
109-
if (_blockNumber != null ? !_blockNumber.equals(log._blockNumber) : log._blockNumber != null) return false;
110109
if (address != null ? !address.equals(log.address) : log.address != null) return false;
111110
if (transactionHash != null ? !transactionHash.equals(log.transactionHash) : log.transactionHash != null)
112111
return false;
113-
if (transactionIndex != null ? !transactionIndex.equals(log.transactionIndex) : log.transactionIndex != null)
114-
return false;
115-
if (_transactionIndex != null ? !_transactionIndex.equals(log._transactionIndex) : log._transactionIndex != null)
116-
return false;
117112
if (timeStamp != null ? !timeStamp.equals(log.timeStamp) : log.timeStamp != null) return false;
118-
if (_timeStamp != null ? !_timeStamp.equals(log._timeStamp) : log._timeStamp != null) return false;
119-
if (data != null ? !data.equals(log.data) : log.data != null) return false;
120-
if (gasPrice != null ? !gasPrice.equals(log.gasPrice) : log.gasPrice != null) return false;
121-
if (_gasPrice != null ? !_gasPrice.equals(log._gasPrice) : log._gasPrice != null) return false;
122-
if (gasUsed != null ? !gasUsed.equals(log.gasUsed) : log.gasUsed != null) return false;
123-
if (_gasUsed != null ? !_gasUsed.equals(log._gasUsed) : log._gasUsed != null) return false;
124-
if (topics != null ? !topics.equals(log.topics) : log.topics != null) return false;
125-
if (logIndex != null ? !logIndex.equals(log.logIndex) : log.logIndex != null) return false;
126-
return _logIndex != null ? _logIndex.equals(log._logIndex) : log._logIndex == null;
113+
return logIndex != null ? logIndex.equals(log.logIndex) : log.logIndex == null;
127114
}
128115

129116
@Override
130117
public int hashCode() {
131118
int result = blockNumber != null ? blockNumber.hashCode() : 0;
132-
result = 31 * result + (_blockNumber != null ? _blockNumber.hashCode() : 0);
133119
result = 31 * result + (address != null ? address.hashCode() : 0);
134120
result = 31 * result + (transactionHash != null ? transactionHash.hashCode() : 0);
135-
result = 31 * result + (transactionIndex != null ? transactionIndex.hashCode() : 0);
136-
result = 31 * result + (_transactionIndex != null ? _transactionIndex.hashCode() : 0);
137121
result = 31 * result + (timeStamp != null ? timeStamp.hashCode() : 0);
138-
result = 31 * result + (_timeStamp != null ? _timeStamp.hashCode() : 0);
139-
result = 31 * result + (data != null ? data.hashCode() : 0);
140-
result = 31 * result + (gasPrice != null ? gasPrice.hashCode() : 0);
141-
result = 31 * result + (_gasPrice != null ? _gasPrice.hashCode() : 0);
142-
result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0);
143-
result = 31 * result + (_gasUsed != null ? _gasUsed.hashCode() : 0);
144-
result = 31 * result + (topics != null ? topics.hashCode() : 0);
145122
result = 31 * result + (logIndex != null ? logIndex.hashCode() : 0);
146-
result = 31 * result + (_logIndex != null ? _logIndex.hashCode() : 0);
147123
return result;
148124
}
149125

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public boolean equals(Object o) {
4949
if (Double.compare(price.ethbtc, ethbtc) != 0) return false;
5050
if (ethusd_timestamp != null ? !ethusd_timestamp.equals(price.ethusd_timestamp) : price.ethusd_timestamp != null)
5151
return false;
52-
if (ethbtc_timestamp != null ? !ethbtc_timestamp.equals(price.ethbtc_timestamp) : price.ethbtc_timestamp != null)
53-
return false;
54-
if (_ethusd_timestamp != null ? !_ethusd_timestamp.equals(price._ethusd_timestamp) : price._ethusd_timestamp != null)
55-
return false;
56-
return _ethbtc_timestamp != null ? _ethbtc_timestamp.equals(price._ethbtc_timestamp) : price._ethbtc_timestamp == null;
52+
return (ethbtc_timestamp != null ? !ethbtc_timestamp.equals(price.ethbtc_timestamp) : price.ethbtc_timestamp != null);
5753
}
5854

5955
@Override
@@ -66,8 +62,6 @@ public int hashCode() {
6662
result = 31 * result + (int) (temp ^ (temp >>> 32));
6763
result = 31 * result + (ethusd_timestamp != null ? ethusd_timestamp.hashCode() : 0);
6864
result = 31 * result + (ethbtc_timestamp != null ? ethbtc_timestamp.hashCode() : 0);
69-
result = 31 * result + (_ethusd_timestamp != null ? _ethusd_timestamp.hashCode() : 0);
70-
result = 31 * result + (_ethbtc_timestamp != null ? _ethbtc_timestamp.hashCode() : 0);
7165
return result;
7266
}
7367

@@ -78,8 +72,6 @@ public String toString() {
7872
", ethbtc=" + ethbtc +
7973
", ethusd_timestamp='" + ethusd_timestamp + '\'' +
8074
", ethbtc_timestamp='" + ethbtc_timestamp + '\'' +
81-
", _ethusd_timestamp=" + _ethusd_timestamp +
82-
", _ethbtc_timestamp=" + _ethbtc_timestamp +
8375
'}';
8476
}
8577
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@ public boolean equals(Object o) {
6565

6666
if (nonce != tx.nonce) return false;
6767
if (transactionIndex != tx.transactionIndex) return false;
68-
if (confirmations != tx.confirmations) return false;
6968
if (blockHash != null ? !blockHash.equals(tx.blockHash) : tx.blockHash != null) return false;
70-
if (gasPrice != null ? !gasPrice.equals(tx.gasPrice) : tx.gasPrice != null) return false;
71-
if (cumulativeGasUsed != null ? !cumulativeGasUsed.equals(tx.cumulativeGasUsed) : tx.cumulativeGasUsed != null)
72-
return false;
73-
if (isError != null ? !isError.equals(tx.isError) : tx.isError != null) return false;
74-
return txreceipt_status != null ? txreceipt_status.equals(tx.txreceipt_status) : tx.txreceipt_status == null;
69+
return isError != null ? isError.equals(tx.isError) : tx.isError == null;
7570
}
7671

7772
@Override
@@ -80,11 +75,7 @@ public int hashCode() {
8075
result = 31 * result + (int) (nonce ^ (nonce >>> 32));
8176
result = 31 * result + (blockHash != null ? blockHash.hashCode() : 0);
8277
result = 31 * result + transactionIndex;
83-
result = 31 * result + (gasPrice != null ? gasPrice.hashCode() : 0);
84-
result = 31 * result + (cumulativeGasUsed != null ? cumulativeGasUsed.hashCode() : 0);
85-
result = 31 * result + (int) (confirmations ^ (confirmations >>> 32));
8678
result = 31 * result + (isError != null ? isError.hashCode() : 0);
87-
result = 31 * result + (txreceipt_status != null ? txreceipt_status.hashCode() : 0);
8879
return result;
8980
}
9081

@@ -99,6 +90,6 @@ public String toString() {
9990
", confirmations=" + confirmations +
10091
", isError='" + isError + '\'' +
10192
", txreceipt_status='" + txreceipt_status + '\'' +
102-
'}';
93+
"} " + super.toString();
10394
}
10495
}

src/main/java/io/api/etherscan/model/TxInternal.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,19 @@ public String getErrCode() {
3434
@Override
3535
public boolean equals(Object o) {
3636
if (this == o) return true;
37-
if (o == null || getClass() != o.getClass()) return false;
37+
if (!(o instanceof TxInternal)) return false;
3838
if (!super.equals(o)) return false;
3939

4040
TxInternal that = (TxInternal) o;
4141

4242
if (traceId != that.traceId) return false;
43-
if (isError != that.isError) return false;
44-
if (type != null ? !type.equals(that.type) : that.type != null) return false;
4543
return errCode != null ? errCode.equals(that.errCode) : that.errCode == null;
4644
}
4745

4846
@Override
4947
public int hashCode() {
5048
int result = super.hashCode();
51-
result = 31 * result + (type != null ? type.hashCode() : 0);
5249
result = 31 * result + (int) (traceId ^ (traceId >>> 32));
53-
result = 31 * result + isError;
5450
result = 31 * result + (errCode != null ? errCode.hashCode() : 0);
5551
return result;
5652
}
@@ -62,6 +58,6 @@ public String toString() {
6258
", traceId=" + traceId +
6359
", isError=" + isError +
6460
", errCode='" + errCode + '\'' +
65-
'}';
61+
"} " + super.toString();
6662
}
6763
}

src/main/java/io/api/etherscan/model/TxToken.java

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,6 @@ public long getConfirmations() {
5656
}
5757
//</editor-fold>
5858

59-
@Override
60-
public boolean equals(Object o) {
61-
if (this == o) return true;
62-
if (o == null || getClass() != o.getClass()) return false;
63-
if (!super.equals(o)) return false;
64-
65-
TxToken txToken = (TxToken) o;
66-
67-
if (nonce != txToken.nonce) return false;
68-
if (transactionIndex != txToken.transactionIndex) return false;
69-
if (gasPrice != txToken.gasPrice) return false;
70-
if (cumulativeGasUsed != txToken.cumulativeGasUsed) return false;
71-
if (confirmations != txToken.confirmations) return false;
72-
if (blockHash != null ? !blockHash.equals(txToken.blockHash) : txToken.blockHash != null) return false;
73-
if (tokenName != null ? !tokenName.equals(txToken.tokenName) : txToken.tokenName != null) return false;
74-
if (tokenSymbol != null ? !tokenSymbol.equals(txToken.tokenSymbol) : txToken.tokenSymbol != null) return false;
75-
return tokenDecimal != null ? tokenDecimal.equals(txToken.tokenDecimal) : txToken.tokenDecimal == null;
76-
}
77-
78-
@Override
79-
public int hashCode() {
80-
int result = super.hashCode();
81-
result = 31 * result + (int) (nonce ^ (nonce >>> 32));
82-
result = 31 * result + (blockHash != null ? blockHash.hashCode() : 0);
83-
result = 31 * result + (tokenName != null ? tokenName.hashCode() : 0);
84-
result = 31 * result + (tokenSymbol != null ? tokenSymbol.hashCode() : 0);
85-
result = 31 * result + (tokenDecimal != null ? tokenDecimal.hashCode() : 0);
86-
result = 31 * result + transactionIndex;
87-
result = 31 * result + (int) (gasPrice ^ (gasPrice >>> 32));
88-
result = 31 * result + (int) (cumulativeGasUsed ^ (cumulativeGasUsed >>> 32));
89-
result = 31 * result + (int) (confirmations ^ (confirmations >>> 32));
90-
return result;
91-
}
92-
9359
@Override
9460
public String toString() {
9561
return "TxToken{" +
@@ -102,6 +68,6 @@ public String toString() {
10268
", gasPrice=" + gasPrice +
10369
", cumulativeGasUsed=" + cumulativeGasUsed +
10470
", confirmations=" + confirmations +
105-
'}';
71+
"} " + super.toString();
10672
}
10773
}

src/test/java/io/api/etherscan/account/AccountTxTokenTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ public class AccountTxTokenTest extends Assert {
2020

2121
@Test
2222
public void correct() {
23-
List<TxToken> txs = api.account().txsToken("0x05fBf1E3f105df6a4553f3C7f2ed93070A4BAB46");
23+
List<TxToken> txs = api.account().txsToken("0xE376F69ED2218076682e2b3B7b9099eC50aD68c4");
2424
assertNotNull(txs);
25-
assertEquals(106, txs.size());
25+
assertEquals(3, txs.size());
2626
assertTxs(txs);
2727
assertNotEquals(0, txs.get(0).getGasPrice());
2828
assertNotEquals(-1, txs.get(0).getNonce());
29+
2930
assertNotNull(txs.get(0).toString());
31+
assertNotEquals(txs.get(0).toString(), txs.get(1).toString());
32+
3033
assertNotEquals(txs.get(0), txs.get(1));
3134
assertNotEquals(txs.get(0).hashCode(), txs.get(1).hashCode());
35+
36+
assertEquals(txs.get(1), txs.get(1));
37+
assertEquals(txs.get(1).hashCode(), txs.get(1).hashCode());
3238
}
3339

3440
@Test

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy