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

Commit9512b09

Browse files
committed
Code coverage improvements
Proxy Models hex parse improvementsProxyStorageAt empty response check
1 parentbc50cae commit9512b09

File tree

13 files changed

+183
-74
lines changed

13 files changed

+183
-74
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
importjava.math.BigInteger;
2020
importjava.util.Optional;
21+
importjava.util.regex.Pattern;
2122

2223
/**
2324
* Proxy API Implementation
@@ -56,6 +57,8 @@ public class ProxyApiProvider extends BasicProvider implements IProxyApi {
5657
privatestaticfinalStringHEX_PARAM ="&hex=";
5758
privatestaticfinalStringTO_PARAM ="&to=";
5859

60+
privatestaticfinalPatternEMPTY_HEX =Pattern.compile("0x0+");
61+
5962
ProxyApiProvider(finalIQueueManagerqueue,
6063
finalStringbaseUrl,
6164
finalIHttpExecutorexecutor) {
@@ -191,7 +194,7 @@ public Optional<String> storageAt(final String address, final long position) thr
191194

192195
finalStringurlParams =ACT_STORAGEAT_PARAM +ADDRESS_PARAM +address +POSITION_PARAM +compPosition +TAG_LAST_PARAM;
193196
finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class);
194-
return (BasicUtils.isEmpty(response.getResult()))
197+
return (BasicUtils.isEmpty(response.getResult()) ||EMPTY_HEX.matcher(response.getResult()).matches())
195198
?Optional.empty()
196199
:Optional.of(response.getResult());
197200
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
/**
2323
* Http client implementation
24-
* @see IHttpExecutor
2524
*
2625
* @author GoodforGod
26+
* @see IHttpExecutor
2727
* @since 28.10.2018
2828
*/
2929
publicclassHttpExecutorimplementsIHttpExecutor {
@@ -59,10 +59,9 @@ public HttpExecutor(final int connectTimeout,
5959
}
6060

6161
/**
62-
*
6362
* @param connectTimeout custom connection establish timeout in millis
64-
* @param readTimeout custom read timeout in millis
65-
* @param headers custom HTTP headers
63+
* @param readTimeoutcustom read timeout in millis
64+
* @param headerscustom HTTP headers
6665
*/
6766
publicHttpExecutor(finalintconnectTimeout,
6867
finalintreadTimeout,
@@ -88,15 +87,14 @@ public String get(final String urlAsString) {
8887
finalHttpURLConnectionconnection =buildConnection(urlAsString,"GET");
8988
finalintstatus =connection.getResponseCode();
9089
if (status ==HTTP_MOVED_TEMP ||status ==HTTP_MOVED_PERM) {
91-
finalStringlocation =connection.getHeaderField("Location");
92-
returnget(location);
90+
returnget(connection.getHeaderField("Location"));
9391
}
9492

9593
finalStringdata =readData(connection);
9694
connection.disconnect();
9795
returndata;
9896
}catch (SocketTimeoutExceptione) {
99-
thrownewApiTimeoutException("Timeout: Could not establish connection for " +connectTimeout+" millis",e);
97+
thrownewApiTimeoutException("Timeout: Could not establish connection for " +connectTimeout+" millis",e);
10098
}catch (Exceptione) {
10199
thrownewConnectionException(e.getLocalizedMessage(),e);
102100
}
@@ -117,14 +115,15 @@ public String post(final String urlAsString, final String dataToPost) {
117115

118116
finalintstatus =connection.getResponseCode();
119117
if (status ==HTTP_MOVED_TEMP ||status ==HTTP_MOVED_PERM) {
120-
finalStringlocation =connection.getHeaderField("Location");
121-
returnpost(location,dataToPost);
118+
returnpost(connection.getHeaderField("Location"),dataToPost);
122119
}
123120

124121
finalStringdata =readData(connection);
125122
connection.disconnect();
126123
returndata;
127-
}catch (IOExceptione) {
124+
}catch (SocketTimeoutExceptione) {
125+
thrownewApiTimeoutException("Timeout: Could not establish connection for " +connectTimeout +" millis",e);
126+
}catch (Exceptione) {
128127
thrownewConnectionException(e.getLocalizedMessage(),e);
129128
}
130129
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
publicclassLog {
1717

1818
privateStringblockNumber;
19-
privatelong_blockNumber;
19+
privateLong_blockNumber;
2020
privateStringaddress;
2121
privateStringtransactionHash;
2222
privateStringtransactionIndex;
23-
privatelong_transactionIndex;
23+
privateLong_transactionIndex;
2424
privateStringtimeStamp;
2525
privateLocalDateTime_timeStamp;
2626
privateStringdata;
@@ -30,11 +30,11 @@ public class Log {
3030
privateBigInteger_gasUsed;
3131
privateList<String>topics;
3232
privateStringlogIndex;
33-
privatelong_logIndex;
33+
privateLong_logIndex;
3434

3535
//<editor-fold desc="Getters">
36-
publiclonggetBlockNumber() {
37-
if(!BasicUtils.isEmpty(blockNumber)){
36+
publicLonggetBlockNumber() {
37+
if(_blockNumber ==null &&!BasicUtils.isEmpty(blockNumber)){
3838
_blockNumber =BasicUtils.parseHex(blockNumber).longValue();
3939
}
4040
return_blockNumber;
@@ -48,8 +48,8 @@ public String getTransactionHash() {
4848
returntransactionHash;
4949
}
5050

51-
publiclonggetTransactionIndex() {
52-
if(!BasicUtils.isEmpty(transactionIndex)){
51+
publicLonggetTransactionIndex() {
52+
if(_transactionIndex ==null &&!BasicUtils.isEmpty(transactionIndex)){
5353
_transactionIndex =BasicUtils.parseHex(transactionIndex).longValue();
5454
}
5555

@@ -90,8 +90,8 @@ public List<String> getTopics() {
9090
returntopics;
9191
}
9292

93-
publiclonggetLogIndex() {
94-
if(!BasicUtils.isEmpty(logIndex)){
93+
publicLonggetLogIndex() {
94+
if(_logIndex ==null &&!BasicUtils.isEmpty(logIndex)){
9595
_logIndex =BasicUtils.parseHex(logIndex).longValue();
9696
}
9797
return_logIndex;

‎src/main/java/io/api/etherscan/model/proxy/BlockProxy.java‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
importio.api.etherscan.util.BasicUtils;
44

5+
importjava.math.BigInteger;
56
importjava.time.LocalDateTime;
67
importjava.time.ZoneOffset;
78
importjava.util.List;
@@ -15,10 +16,12 @@
1516
publicclassBlockProxy {
1617

1718
privateStringnumber;
19+
privateLong_number;
1820
privateStringhash;
1921
privateStringparentHash;
2022
privateStringstateRoot;
2123
privateStringsize;
24+
privateLong_size;
2225
privateStringdifficulty;
2326
privateStringtotalDifficulty;
2427
privateStringtimestamp;
@@ -30,7 +33,9 @@ public class BlockProxy {
3033
privateStringlogsBloom;
3134
privateStringmixHash;
3235
privateStringgasUsed;
36+
privateBigInteger_gasUsed;
3337
privateStringgasLimit;
38+
privateBigInteger_gasLimit;
3439

3540
privateStringsha3Uncles;
3641
privateList<String>uncles;
@@ -40,8 +45,10 @@ public class BlockProxy {
4045
privateList<TxProxy>transactions;
4146

4247
//<editor-fold desc="Getters">
43-
publicStringgetNumber() {
44-
returnnumber;
48+
publicLonggetNumber() {
49+
if(_number ==null && !BasicUtils.isEmpty(number))
50+
_number =BasicUtils.parseHex(number).longValue();
51+
return_number;
4552
}
4653

4754
publicStringgetHash() {
@@ -56,8 +63,10 @@ public String getStateRoot() {
5663
returnstateRoot;
5764
}
5865

59-
publicStringgetSize() {
60-
returnsize;
66+
publicLonggetSize() {
67+
if(_size ==null && !BasicUtils.isEmpty(size))
68+
_size =BasicUtils.parseHex(size).longValue();
69+
return_size;
6170
}
6271

6372
publicStringgetDifficulty() {
@@ -94,12 +103,16 @@ public String getMixHash() {
94103
returnmixHash;
95104
}
96105

97-
publicStringgetGasUsed() {
98-
returngasUsed;
106+
publicBigIntegergetGasUsed() {
107+
if(_gasUsed ==null && !BasicUtils.isEmpty(gasUsed))
108+
_gasUsed =BasicUtils.parseHex(gasUsed);
109+
return_gasUsed;
99110
}
100111

101-
publicStringgetGasLimit() {
102-
returngasLimit;
112+
publicBigIntegergetGasLimit() {
113+
if(_gasLimit ==null && !BasicUtils.isEmpty(gasLimit))
114+
_gasLimit =BasicUtils.parseHex(gasLimit);
115+
return_gasLimit;
103116
}
104117

105118
publicStringgetSha3Uncles() {

‎src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java‎

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

33
importio.api.etherscan.model.Log;
4+
importio.api.etherscan.util.BasicUtils;
45

6+
importjava.math.BigInteger;
57
importjava.util.List;
68

79
/**
@@ -16,11 +18,15 @@ public class ReceiptProxy {
1618
privateStringfrom;
1719
privateStringto;
1820
privateStringblockNumber;
21+
privateLong_blockNumber;
1922
privateStringblockHash;
2023
privateStringtransactionHash;
2124
privateStringtransactionIndex;
25+
privateLong_transactionIndex;
2226
privateStringgasUsed;
27+
privateBigInteger_gasUsed;
2328
privateStringcumulativeGasUsed;
29+
privateBigInteger_cumulativeGasUsed;
2430
privateStringcontractAddress;
2531

2632
privateList<Log>logs;
@@ -39,8 +45,10 @@ public String getTo() {
3945
returnto;
4046
}
4147

42-
publicStringgetBlockNumber() {
43-
returnblockNumber;
48+
publicLonggetBlockNumber() {
49+
if(_blockNumber ==null && !BasicUtils.isEmpty(blockNumber))
50+
_blockNumber =BasicUtils.parseHex(blockNumber).longValue();
51+
return_blockNumber;
4452
}
4553

4654
publicStringgetBlockHash() {
@@ -51,16 +59,22 @@ public String getTransactionHash() {
5159
returntransactionHash;
5260
}
5361

54-
publicStringgetTransactionIndex() {
55-
returntransactionIndex;
62+
publicLonggetTransactionIndex() {
63+
if(_transactionIndex ==null && !BasicUtils.isEmpty(transactionIndex))
64+
_transactionIndex =BasicUtils.parseHex(transactionIndex).longValue();
65+
return_transactionIndex;
5666
}
5767

58-
publicStringgetGasUsed() {
59-
returngasUsed;
68+
publicBigIntegergetGasUsed() {
69+
if(_gasUsed ==null && !BasicUtils.isEmpty(gasUsed))
70+
_gasUsed =BasicUtils.parseHex(gasUsed);
71+
return_gasUsed;
6072
}
6173

62-
publicStringgetCumulativeGasUsed() {
63-
returncumulativeGasUsed;
74+
publicBigIntegergetCumulativeGasUsed() {
75+
if(_cumulativeGasUsed ==null && !BasicUtils.isEmpty(cumulativeGasUsed))
76+
_cumulativeGasUsed =BasicUtils.parseHex(cumulativeGasUsed);
77+
return_cumulativeGasUsed;
6478
}
6579

6680
publicStringgetContractAddress() {

‎src/main/java/io/api/etherscan/model/proxy/TxProxy.java‎

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

3+
importio.api.etherscan.util.BasicUtils;
4+
5+
importjava.math.BigInteger;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
@@ -11,17 +15,22 @@ public class TxProxy {
1115
privateStringto;
1216
privateStringhash;
1317
privateStringtransactionIndex;
18+
privateLong_transactionIndex;
1419
privateStringfrom;
15-
privateStringgas;
1620
privateStringv;
1721
privateStringinput;
1822
privateStrings;
1923
privateStringr;
2024
privateStringnonce;
25+
privateLong_nonce;
2126
privateStringvalue;
27+
privateStringgas;
28+
privateBigInteger_gas;
2229
privateStringgasPrice;
30+
privateBigInteger_gasPrice;
2331
privateStringblockHash;
2432
privateStringblockNumber;
33+
privateLong_blockNumber;
2534

2635
//<editor-fold desc="Getters">
2736
publicStringgetTo() {
@@ -32,16 +41,20 @@ public String getHash() {
3241
returnhash;
3342
}
3443

35-
publicStringgetTransactionIndex() {
36-
returntransactionIndex;
44+
publicLonggetTransactionIndex() {
45+
if(_transactionIndex ==null && !BasicUtils.isEmpty(transactionIndex))
46+
_transactionIndex =BasicUtils.parseHex(transactionIndex).longValue();
47+
return_transactionIndex;
3748
}
3849

3950
publicStringgetFrom() {
4051
returnfrom;
4152
}
4253

43-
publicStringgetGas() {
44-
returngas;
54+
publicBigIntegergetGas() {
55+
if(_gas ==null && !BasicUtils.isEmpty(gas))
56+
_gas =BasicUtils.parseHex(gas);
57+
return_gas;
4558
}
4659

4760
publicStringgetV() {
@@ -60,24 +73,30 @@ public String getR() {
6073
returnr;
6174
}
6275

63-
publicStringgetNonce() {
64-
returnnonce;
76+
publicLonggetNonce() {
77+
if(_nonce ==null && !BasicUtils.isEmpty(nonce))
78+
_nonce =BasicUtils.parseHex(nonce).longValue();
79+
return_nonce;
6580
}
6681

6782
publicStringgetValue() {
6883
returnvalue;
6984
}
7085

71-
publicStringgetGasPrice() {
72-
returngasPrice;
86+
publicBigIntegergetGasPrice() {
87+
if(_gasPrice ==null && !BasicUtils.isEmpty(gasPrice))
88+
_gasPrice =BasicUtils.parseHex(gasPrice);
89+
return_gasPrice;
7390
}
7491

7592
publicStringgetBlockHash() {
7693
returnblockHash;
7794
}
7895

79-
publicStringgetBlockNumber() {
80-
returnblockNumber;
96+
publicLonggetBlockNumber() {
97+
if(_blockNumber ==null && !BasicUtils.isEmpty(blockNumber))
98+
_blockNumber =BasicUtils.parseHex(blockNumber).longValue();
99+
return_blockNumber;
81100
}
82101
//</editor-fold>
83102
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp