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

Commitddccdef

Browse files
committed
ToString()
HttpExecutor improvements + default read timeout 0Coverage improvements + README fixs
1 parent9512b09 commitddccdef

26 files changed

+431
-38
lines changed

‎README.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ dependencies {
4343
API support Ethereum:*[MAINNET](https://etherscan.io),[ROPSTEN](https://ropsten.etherscan.io),
4444
[KOVAN](https://kovan.etherscan.io),[RINKEBY](https://rinkeby.etherscan.io)* networks.
4545
```java
46-
EtherScanApi api=newEtherScanApi(EthNetwork.MAINTNET);
47-
EtherScanApi api=newEtherScanApi(EthNetwork.RINKEBY);
48-
EtherScanApi api=newEtherScanApi("YourApiKey",EthNetwork.KOVAN);
46+
EtherScanApi api=newEtherScanApi(EthNetwork.MAINNET);// Default
47+
EtherScanApi apiRinkeby=newEtherScanApi(EthNetwork.RINKEBY);
48+
EtherScanApi apiRopsten=newEtherScanApi(EthNetwork.ROPSTEN);
49+
EtherScanApi apiKovan=newEtherScanApi("YourApiKey",EthNetwork.KOVAN);
4950
```
5051

5152
##Custom HttpClient
@@ -56,10 +57,10 @@ just implement **IHttpExecutor** by your self or initialize it with your values.
5657
```java
5758
int connectionTimeout=10000;
5859
int readTimeout=7000;
60+
5961
Supplier<IHttpExecutor> supplier= ()->newHttpExecutor(connectionTimeout);
6062
Supplier<IHttpExecutor> supplierFull= ()->newHttpExecutor(connectionTimeout, readTimeout);
61-
62-
63+
6364
EtherScanApi api=newEtherScanApi(EthNetwork.RINKEBY, supplier);
6465
EtherScanApi apiWithKey=newEtherScanApi("YourApiKey",EthNetwork.MAINNET, supplierFull);
6566
```
@@ -70,14 +71,15 @@ You can read about all API methods on [Etherscan](https://etherscan.io/apis)
7071

7172
*Library support all available EtherScan API.*
7273

73-
You can use API with you key or without key as well (Check API request\sec restrictions).
74-
Library support limit when used without key and will limit requests up to*5 req/sec by itself*.
74+
You can use library*with or without* API key*([Check API request\sec restrictions when used without API key](https://ethereum.stackexchange.com/questions/34190/does-etherscan-require-the-use-of-an-api-key))*.
75+
76+
Library will automatically limit requests up to**5 req/sec** when used*without* key.
7577
```java
7678
EtherScanApi api=newEtherScanApi();
7779
EtherScanApi api=newEtherScanApi("YourApiKey");
7880
```
7981

80-
Belowthereare examples for each API category.
82+
Below are examples for each API category.
8183

8284
###Account Api
8385
**Get Ether Balance for a single Address**
@@ -121,6 +123,7 @@ LogQuery query = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70
121123
.setOpTopic0_2(LogOp.OR)
122124
.setOpTopic1_2(LogOp.AND)
123125
.build();
126+
124127
List<Log> logs= api.logs().logs(query);
125128
```
126129

@@ -152,7 +155,7 @@ Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab
152155
```
153156

154157
###Token Api
155-
You can read token API[here](https://etherscan.io/apis#tokens)
158+
You can readabouttoken API[here](https://etherscan.io/apis#tokens)
156159

157160
Token API methods migrated to[Account](#account-api) &[Stats](#stats-api) respectfully.
158161

‎src/main/java/io/api/etherscan/core/impl/EtherScanApi.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importio.api.etherscan.manager.impl.QueueManager;
1111
importio.api.etherscan.model.EthNetwork;
1212
importio.api.etherscan.util.BasicUtils;
13+
importorg.jetbrains.annotations.NotNull;
1314

1415
importjava.util.function.Supplier;
1516

@@ -83,48 +84,55 @@ public EtherScanApi(final String apiKey,
8384
/**
8485
* API for interactions with account and address
8586
*/
87+
@NotNull
8688
publicIAccountApiaccount() {
8789
returnaccount;
8890
}
8991

9092
/**
9193
* API for verifying contract ABI
9294
*/
95+
@NotNull
9396
publicIContractApicontract() {
9497
returncontract;
9598
}
9699

97100
/**
98101
* [BETA] API for interaction with tx statuses
99102
*/
103+
@NotNull
100104
publicITransactionApitxs() {
101105
returntxs;
102106
}
103107

104108
/**
105109
* [BETA] API for getting block rewards and uncles
106110
*/
111+
@NotNull
107112
publicIBlockApiblock() {
108113
returnblock;
109114
}
110115

111116
/**
112117
* [BETA] API for interaction with eth_getLogs
113118
*/
119+
@NotNull
114120
publicILogsApilogs() {
115121
returnlogs;
116122
}
117123

118124
/**
119125
* API for interacting with geth/proxy etherscan
120126
*/
127+
@NotNull
121128
publicIProxyApiproxy() {
122129
returnproxy;
123130
}
124131

125132
/**
126133
* API for eth price and supply statistic
127134
*/
135+
@NotNull
128136
publicIStatisticApistats() {
129137
returnstats;
130138
}

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
importjava.util.HashMap;
1616
importjava.util.Map;
1717
importjava.util.zip.GZIPInputStream;
18+
importjava.util.zip.InflaterInputStream;
1819

1920
importstaticjava.net.HttpURLConnection.HTTP_MOVED_PERM;
2021
importstaticjava.net.HttpURLConnection.HTTP_MOVED_TEMP;
@@ -31,13 +32,12 @@ public class HttpExecutor implements IHttpExecutor {
3132
privatestaticfinalMap<String,String>DEFAULT_HEADERS =newHashMap<>();
3233

3334
privatestaticfinalintCONNECT_TIMEOUT =8000;
34-
privatestaticfinalintREAD_TIMEOUT =30000;
35+
privatestaticfinalintREAD_TIMEOUT =0;
3536

3637
static {
37-
DEFAULT_HEADERS.put("Accept-Language","en;q=0.9");
38+
DEFAULT_HEADERS.put("Accept-Language","en");
3839
DEFAULT_HEADERS.put("Accept-Encoding","deflate, gzip");
3940
DEFAULT_HEADERS.put("User-Agent","Chrome/68.0.3440.106");
40-
DEFAULT_HEADERS.put("Content-Type","application/x-www-form-urlencoded");
4141
DEFAULT_HEADERS.put("Accept-Charset","UTF-8");
4242
}
4343

@@ -46,15 +46,14 @@ public class HttpExecutor implements IHttpExecutor {
4646
privatefinalintreadTimeout;
4747

4848
publicHttpExecutor() {
49-
this(CONNECT_TIMEOUT,READ_TIMEOUT);
49+
this(CONNECT_TIMEOUT);
5050
}
5151

5252
publicHttpExecutor(finalintconnectTimeout) {
5353
this(connectTimeout,READ_TIMEOUT);
5454
}
5555

56-
publicHttpExecutor(finalintconnectTimeout,
57-
finalintreadTimeout) {
56+
publicHttpExecutor(finalintconnectTimeout,finalintreadTimeout) {
5857
this(connectTimeout,readTimeout,DEFAULT_HEADERS);
5958
}
6059

@@ -142,8 +141,13 @@ private String readData(final HttpURLConnection connection) throws IOException {
142141
}
143142

144143
privateInputStreamReadergetStreamReader(finalHttpURLConnectionconnection)throwsIOException {
145-
return (connection.getContentEncoding() !=null &&"gzip".equals(connection.getContentEncoding()))
146-
?newInputStreamReader(newGZIPInputStream(connection.getInputStream()),"utf-8")
147-
:newInputStreamReader(connection.getInputStream(),"utf-8");
144+
finalbooleanhaveEncoding =connection.getContentEncoding() !=null;
145+
146+
if (haveEncoding &&"gzip".equals(connection.getContentEncoding()))
147+
returnnewInputStreamReader(newGZIPInputStream(connection.getInputStream()),"utf-8");
148+
elseif (haveEncoding &&"deflate".equals(connection.getContentEncoding()))
149+
returnnewInputStreamReader(newInflaterInputStream(connection.getInputStream()),"utf-8");
150+
else
151+
returnnewInputStreamReader(connection.getInputStream(),"utf-8");
148152
}
149153
}

‎src/main/java/io/api/etherscan/model/Abi.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,30 @@ public String getContractAbi() {
3636
publicbooleanisVerified() {
3737
returnisVerified;
3838
}
39+
40+
@Override
41+
publicbooleanequals(Objecto) {
42+
if (this ==o)returntrue;
43+
if (o ==null ||getClass() !=o.getClass())returnfalse;
44+
45+
Abiabi = (Abi)o;
46+
47+
if (isVerified !=abi.isVerified)returnfalse;
48+
returncontractAbi !=null ?contractAbi.equals(abi.contractAbi) :abi.contractAbi ==null;
49+
}
50+
51+
@Override
52+
publicinthashCode() {
53+
intresult =contractAbi !=null ?contractAbi.hashCode() :0;
54+
result =31 *result + (isVerified ?1 :0);
55+
returnresult;
56+
}
57+
58+
@Override
59+
publicStringtoString() {
60+
return"Abi{" +
61+
"contractAbi='" +contractAbi +'\'' +
62+
", isVerified=" +isVerified +
63+
'}';
64+
}
3965
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,21 @@ public boolean equals(Object o) {
8484
publicinthashCode() {
8585
returnhash !=null ?hash.hashCode() :0;
8686
}
87+
88+
@Override
89+
publicStringtoString() {
90+
return"BaseTx{" +
91+
"blockNumber=" +blockNumber +
92+
", timeStamp='" +timeStamp +'\'' +
93+
", _timeStamp=" +_timeStamp +
94+
", hash='" +hash +'\'' +
95+
", from='" +from +'\'' +
96+
", to='" +to +'\'' +
97+
", value=" +value +
98+
", contractAddress='" +contractAddress +'\'' +
99+
", input='" +input +'\'' +
100+
", gas=" +gas +
101+
", gasUsed=" +gasUsed +
102+
'}';
103+
}
87104
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ public boolean equals(Object o) {
4949
publicinthashCode() {
5050
return (int) (blockNumber ^ (blockNumber >>>32));
5151
}
52+
53+
@Override
54+
publicStringtoString() {
55+
return"Block{" +
56+
"blockNumber=" +blockNumber +
57+
", blockReward=" +blockReward +
58+
", timeStamp='" +timeStamp +'\'' +
59+
", _timeStamp=" +_timeStamp +
60+
'}';
61+
}
5262
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,26 @@ public Long getLogIndex() {
9797
return_logIndex;
9898
}
9999
//</editor-fold>
100+
101+
@Override
102+
publicStringtoString() {
103+
return"Log{" +
104+
"blockNumber='" +blockNumber +'\'' +
105+
", _blockNumber=" +_blockNumber +
106+
", address='" +address +'\'' +
107+
", transactionHash='" +transactionHash +'\'' +
108+
", transactionIndex='" +transactionIndex +'\'' +
109+
", _transactionIndex=" +_transactionIndex +
110+
", timeStamp='" +timeStamp +'\'' +
111+
", _timeStamp=" +_timeStamp +
112+
", data='" +data +'\'' +
113+
", gasPrice='" +gasPrice +'\'' +
114+
", _gasPrice=" +_gasPrice +
115+
", gasUsed='" +gasUsed +'\'' +
116+
", _gasUsed=" +_gasUsed +
117+
", topics=" +topics +
118+
", logIndex='" +logIndex +'\'' +
119+
", _logIndex=" +_logIndex +
120+
'}';
121+
}
100122
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ public LocalDateTime btcTimestamp() {
3737
_ethbtc_timestamp =LocalDateTime.ofEpochSecond(Long.valueOf(ethbtc_timestamp),0,ZoneOffset.UTC);
3838
return_ethbtc_timestamp;
3939
}
40+
41+
@Override
42+
publicStringtoString() {
43+
return"Price{" +
44+
"ethusd=" +ethusd +
45+
", ethbtc=" +ethbtc +
46+
", ethusd_timestamp='" +ethusd_timestamp +'\'' +
47+
", ethbtc_timestamp='" +ethbtc_timestamp +'\'' +
48+
", _ethusd_timestamp=" +_ethusd_timestamp +
49+
", _ethbtc_timestamp=" +_ethbtc_timestamp +
50+
'}';
51+
}
4052
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ public boolean haveError() {
2121
publicStringgetErrDescription() {
2222
returnerrDescription;
2323
}
24+
25+
@Override
26+
publicStringtoString() {
27+
return"Status{" +
28+
"isError=" +isError +
29+
", errDescription='" +errDescription +'\'' +
30+
'}';
31+
}
2432
}

‎src/main/java/io/api/etherscan/model/TokenBalance.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ public int hashCode() {
3838
result =31 *result + (tokenContract !=null ?tokenContract.hashCode() :0);
3939
returnresult;
4040
}
41+
42+
@Override
43+
publicStringtoString() {
44+
return"TokenBalance{" +
45+
"tokenContract='" +tokenContract +'\'' +
46+
'}';
47+
}
4148
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp