Skip to content

Commit 8ba73e8

Browse files
committed
[1.1.0]
SonarQube issues fixed README.md updated
1 parent 8c0754d commit 8ba73e8

19 files changed

+57
-43
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# java-etherscan-api
22

3+
[![GitHub Action](https://github.com/goodforgod/java-etherscan-api/workflows/Java%20CI/badge.svg)](https://github.com/GoodforGod/dummymaker/actions?query=workflow%3A%22Java+CI%22)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
5+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
6+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
37
[![Jitpack](https://jitpack.io/v/iSnow/java-etherscan-api.svg)](https://jitpack.io/#GoodforGod/java-etherscan-api)
48

59
[Etherscan](https://etherscan.io/apis) Java API implementation.
@@ -163,6 +167,8 @@ Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) resp
163167

164168
## Version History
165169

170+
**1.1.0** - Improved error handling, QueueManager improved, Gradle 6.7 instead of Maven, GitHub CI, Sonarcloud analyzer, dependencies updated.
171+
166172
**1.0.2** - Minor http client improvements.
167173

168174
**1.0.1** - Gorli & TOBALABA networks support.
@@ -171,4 +177,4 @@ Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) resp
171177

172178
## License
173179

174-
This project is licensed under the MIT - see the [LICENSE](LICENSE) file for details.
180+
This project licensed under the MIT - see the [LICENSE](LICENSE) file for details.

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
groupId=com.github.goodforgod
22
artifactId=java-etherscan-api
3-
artifactVersion=1.1.0-SNAPSHOT
3+
artifactVersion=1.1.0
44
buildNumber=1
55

66

src/main/java/io/api/etherscan/core/impl/BasicProvider.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ abstract class BasicProvider {
4646
<T> T convert(final String json, final Class<T> tClass) {
4747
try {
4848
final T t = gson.fromJson(json, tClass);
49-
if (t instanceof StringResponseTO) {
50-
if (((StringResponseTO) t).getResult().startsWith("Max rate limit reached")) {
51-
throw new RateLimitException(((StringResponseTO) t).getResult());
52-
}
49+
if (t instanceof StringResponseTO && ((StringResponseTO) t).getResult().startsWith("Max rate limit reached")) {
50+
throw new RateLimitException(((StringResponseTO) t).getResult());
5351
}
5452

5553
return t;

src/main/java/io/api/etherscan/manager/impl/FakeQueueManager.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
public class FakeQueueManager implements IQueueManager {
1212

1313
@Override
14-
public void takeTurn() {}
14+
public void takeTurn() {
15+
// no limit or await provided for fake impl so rate limit exception will be
16+
// thrown if too many calls
17+
}
1518
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.api.etherscan.model.utility.BalanceTO;
44

55
import java.math.BigInteger;
6+
import java.util.Objects;
67

78
/**
89
* ! NO DESCRIPTION !
@@ -63,7 +64,7 @@ public boolean equals(Object o) {
6364

6465
if (!balance.equals(balance1.balance))
6566
return false;
66-
return address != null ? address.equals(balance1.address) : balance1.address == null;
67+
return Objects.equals(address, balance1.address);
6768
}
6869

6970
@Override

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.math.BigInteger;
66
import java.time.LocalDateTime;
77
import java.time.ZoneOffset;
8+
import java.util.Objects;
89

910
/**
1011
* ! NO DESCRIPTION !
@@ -33,7 +34,7 @@ public long getBlockNumber() {
3334

3435
public LocalDateTime getTimeStamp() {
3536
if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp))
36-
_timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC);
37+
_timeStamp = LocalDateTime.ofEpochSecond(Long.parseLong(timeStamp), 0, ZoneOffset.UTC);
3738
return _timeStamp;
3839
}
3940

@@ -81,15 +82,15 @@ public boolean equals(Object o) {
8182

8283
if (blockNumber != baseTx.blockNumber)
8384
return false;
84-
if (timeStamp != null ? !timeStamp.equals(baseTx.timeStamp) : baseTx.timeStamp != null)
85+
if (!Objects.equals(timeStamp, baseTx.timeStamp))
8586
return false;
86-
if (hash != null ? !hash.equals(baseTx.hash) : baseTx.hash != null)
87+
if (!Objects.equals(hash, baseTx.hash))
8788
return false;
88-
if (from != null ? !from.equals(baseTx.from) : baseTx.from != null)
89+
if (!Objects.equals(from, baseTx.from))
8990
return false;
90-
if (to != null ? !to.equals(baseTx.to) : baseTx.to != null)
91+
if (!Objects.equals(to, baseTx.to))
9192
return false;
92-
return value != null ? value.equals(baseTx.value) : baseTx.value == null;
93+
return Objects.equals(value, baseTx.value);
9394
}
9495

9596
@Override

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public long getBlockNumber() {
2626

2727
public LocalDateTime getTimeStamp() {
2828
if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp))
29-
_timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC);
29+
_timeStamp = LocalDateTime.ofEpochSecond(Long.parseLong(timeStamp), 0, ZoneOffset.UTC);
3030
return _timeStamp;
3131
}
3232

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.time.LocalDateTime;
77
import java.time.ZoneOffset;
88
import java.util.List;
9+
import java.util.Objects;
910

1011
/**
1112
* ! NO DESCRIPTION !
@@ -124,15 +125,15 @@ public boolean equals(Object o) {
124125

125126
Log log = (Log) o;
126127

127-
if (blockNumber != null ? !blockNumber.equals(log.blockNumber) : log.blockNumber != null)
128+
if (!Objects.equals(blockNumber, log.blockNumber))
128129
return false;
129-
if (address != null ? !address.equals(log.address) : log.address != null)
130+
if (!Objects.equals(address, log.address))
130131
return false;
131-
if (transactionHash != null ? !transactionHash.equals(log.transactionHash) : log.transactionHash != null)
132+
if (!Objects.equals(transactionHash, log.transactionHash))
132133
return false;
133-
if (timeStamp != null ? !timeStamp.equals(log.timeStamp) : log.timeStamp != null)
134+
if (!Objects.equals(timeStamp, log.timeStamp))
134135
return false;
135-
return logIndex != null ? logIndex.equals(log.logIndex) : log.logIndex == null;
136+
return Objects.equals(logIndex, log.logIndex);
136137
}
137138

138139
@Override

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public double inBtc() {
2828

2929
public LocalDateTime usdTimestamp() {
3030
if (_ethusd_timestamp == null)
31-
_ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethusd_timestamp), 0, ZoneOffset.UTC);
31+
_ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethusd_timestamp), 0, ZoneOffset.UTC);
3232
return _ethusd_timestamp;
3333
}
3434

3535
public LocalDateTime btcTimestamp() {
3636
if (_ethbtc_timestamp == null)
37-
_ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethbtc_timestamp), 0, ZoneOffset.UTC);
37+
_ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethbtc_timestamp), 0, ZoneOffset.UTC);
3838
return _ethbtc_timestamp;
3939
}
4040

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.api.etherscan.model;
22

3+
import java.util.Objects;
4+
35
/**
46
* Contract Execution Status
57
*
@@ -33,7 +35,7 @@ public boolean equals(Object o) {
3335

3436
if (isError != status.isError)
3537
return false;
36-
return errDescription != null ? errDescription.equals(status.errDescription) : status.errDescription == null;
38+
return Objects.equals(errDescription, status.errDescription);
3739
}
3840

3941
@Override

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.api.etherscan.model;
22

33
import java.math.BigInteger;
4+
import java.util.Objects;
45

56
/**
67
* ! NO DESCRIPTION !
@@ -31,8 +32,7 @@ public boolean equals(Object o) {
3132
return false;
3233

3334
TokenBalance that = (TokenBalance) o;
34-
35-
return tokenContract != null ? tokenContract.equals(that.tokenContract) : that.tokenContract == null;
35+
return Objects.equals(tokenContract, that.tokenContract);
3636
}
3737

3838
@Override

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.api.etherscan.util.BasicUtils;
44

55
import java.math.BigInteger;
6+
import java.util.Objects;
67

78
/**
89
* ! NO DESCRIPTION !
@@ -70,9 +71,9 @@ public boolean equals(Object o) {
7071
return false;
7172
if (transactionIndex != tx.transactionIndex)
7273
return false;
73-
if (blockHash != null ? !blockHash.equals(tx.blockHash) : tx.blockHash != null)
74+
if (!Objects.equals(blockHash, tx.blockHash))
7475
return false;
75-
return isError != null ? isError.equals(tx.isError) : tx.isError == null;
76+
return Objects.equals(isError, tx.isError);
7677
}
7778

7879
@Override

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.api.etherscan.model;
22

3+
import java.util.Objects;
4+
35
/**
46
* ! NO DESCRIPTION !
57
*
@@ -44,7 +46,7 @@ public boolean equals(Object o) {
4446

4547
if (traceId != that.traceId)
4648
return false;
47-
return errCode != null ? errCode.equals(that.errCode) : that.errCode == null;
49+
return Objects.equals(errCode, that.errCode);
4850
}
4951

5052
@Override

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.api.etherscan.model;
22

33
import java.math.BigInteger;
4+
import java.util.Objects;
45

56
/**
67
* ! NO DESCRIPTION !
@@ -46,8 +47,7 @@ public boolean equals(Object o) {
4647
return false;
4748

4849
Wei wei = (Wei) o;
49-
50-
return result != null ? result.equals(wei.result) : wei.result == null;
50+
return Objects.equals(result, wei.result);
5151
}
5252

5353
@Override

src/main/java/io/api/etherscan/model/utility/BaseResponseTO.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class BaseResponseTO {
1414
private String message;
1515

1616
public int getStatus() {
17-
return (BasicUtils.isEmpty(status)) ? -1 : Integer.valueOf(status);
17+
return BasicUtils.isEmpty(status) ? -1 : Integer.parseInt(status);
1818
}
1919

2020
public String getMessage() {

src/main/java/io/api/etherscan/model/utility/BlockParam.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99
public class BlockParam {
1010

11-
private long startBlock;
12-
private long endBlock;
11+
private final long startBlock;
12+
private final long endBlock;
1313

1414
public BlockParam(long startBlock, long endBlock) {
1515
this.startBlock = startBlock;

src/main/java/io/api/etherscan/util/BasicUtils.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class BasicUtils {
2626
private static final Pattern TXHASH_PATTERN = Pattern.compile("0x[a-zA-Z0-9]{64}");
2727
private static final Pattern HEX_PATTERN = Pattern.compile("[a-zA-Z0-9]+");
2828

29+
private BasicUtils() {}
30+
2931
public static boolean isEmpty(String value) {
3032
return value == null || value.isEmpty();
3133
}
@@ -42,14 +44,8 @@ public static BlockParam compensateBlocks(long startBlock, long endBlock) {
4244
long startCompensated = compensateMinBlock(startBlock);
4345
long endCompensated = compensateMaxBlock(endBlock);
4446

45-
final long startFinal = (startCompensated > endCompensated)
46-
? endCompensated
47-
: startCompensated;
48-
49-
final long endFinal = (startCompensated > endCompensated)
50-
? startCompensated
51-
: endCompensated;
52-
47+
final long startFinal = Math.min(startCompensated, endCompensated);
48+
final long endFinal = Math.max(startCompensated, endCompensated);
5349
return new BlockParam(startFinal, endFinal);
5450
}
5551

src/test/java/io/api/etherscan/statistic/StatisticPriceApiTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public void correct() {
1818
assertNotNull(price);
1919
assertNotNull(price.btcTimestamp());
2020
assertNotNull(price.usdTimestamp());
21-
assertNotEquals(0, price.inBtc());
22-
assertNotEquals(0, price.inUsd());
21+
assertNotEquals(0.0, price.inBtc());
22+
assertNotEquals(0.0, price.inUsd());
2323
assertNotNull(price.toString());
2424

2525
Price empty = new Price();

src/test/java/io/api/manager/QueueManagerTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ public void fakeManager() {
2323
fakeManager.takeTurn();
2424
fakeManager.takeTurn();
2525
fakeManager.takeTurn();
26+
assertNotNull(fakeManager);
2627
}
2728

2829
@Test(timeout = 3500)
2930
public void queueManager() {
3031
IQueueManager queueManager = new QueueManager(1, 3);
3132
queueManager.takeTurn();
3233
queueManager.takeTurn();
34+
assertNotNull(queueManager);
3335
}
3436

3537
@Test(timeout = 4500)
3638
public void queueManagerWithDelay() {
3739
IQueueManager queueManager = new QueueManager(1, 2, 2);
3840
queueManager.takeTurn();
3941
queueManager.takeTurn();
42+
assertNotNull(queueManager);
4043
}
4144

4245
@Test

0 commit comments

Comments
 (0)