Skip to content

Commit

Permalink
[1.1.0]
Browse files Browse the repository at this point in the history
SonarQube issues fixed
README.md updated
  • Loading branch information
GoodforGod committed Oct 18, 2020
1 parent 8c0754d commit 8ba73e8
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 43 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# java-etherscan-api

[![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)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_java-etherscan-api&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_dummymaker)
[![Jitpack](https://jitpack.io/v/iSnow/java-etherscan-api.svg)](https://jitpack.io/#GoodforGod/java-etherscan-api)

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

## Version History

**1.1.0** - Improved error handling, QueueManager improved, Gradle 6.7 instead of Maven, GitHub CI, Sonarcloud analyzer, dependencies updated.

**1.0.2** - Minor http client improvements.

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

## License

This project is licensed under the MIT - see the [LICENSE](LICENSE) file for details.
This project licensed under the MIT - see the [LICENSE](LICENSE) file for details.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
groupId=com.github.goodforgod
artifactId=java-etherscan-api
artifactVersion=1.1.0-SNAPSHOT
artifactVersion=1.1.0
buildNumber=1


Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/api/etherscan/core/impl/BasicProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ abstract class BasicProvider {
<T> T convert(final String json, final Class<T> tClass) {
try {
final T t = gson.fromJson(json, tClass);
if (t instanceof StringResponseTO) {
if (((StringResponseTO) t).getResult().startsWith("Max rate limit reached")) {
throw new RateLimitException(((StringResponseTO) t).getResult());
}
if (t instanceof StringResponseTO && ((StringResponseTO) t).getResult().startsWith("Max rate limit reached")) {
throw new RateLimitException(((StringResponseTO) t).getResult());
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
public class FakeQueueManager implements IQueueManager {

@Override
public void takeTurn() {}
public void takeTurn() {
// no limit or await provided for fake impl so rate limit exception will be
// thrown if too many calls
}
}
3 changes: 2 additions & 1 deletion src/main/java/io/api/etherscan/model/Balance.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.api.etherscan.model.utility.BalanceTO;

import java.math.BigInteger;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -63,7 +64,7 @@ public boolean equals(Object o) {

if (!balance.equals(balance1.balance))
return false;
return address != null ? address.equals(balance1.address) : balance1.address == null;
return Objects.equals(address, balance1.address);
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/io/api/etherscan/model/BaseTx.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -33,7 +34,7 @@ public long getBlockNumber() {

public LocalDateTime getTimeStamp() {
if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp))
_timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC);
_timeStamp = LocalDateTime.ofEpochSecond(Long.parseLong(timeStamp), 0, ZoneOffset.UTC);
return _timeStamp;
}

Expand Down Expand Up @@ -81,15 +82,15 @@ public boolean equals(Object o) {

if (blockNumber != baseTx.blockNumber)
return false;
if (timeStamp != null ? !timeStamp.equals(baseTx.timeStamp) : baseTx.timeStamp != null)
if (!Objects.equals(timeStamp, baseTx.timeStamp))
return false;
if (hash != null ? !hash.equals(baseTx.hash) : baseTx.hash != null)
if (!Objects.equals(hash, baseTx.hash))
return false;
if (from != null ? !from.equals(baseTx.from) : baseTx.from != null)
if (!Objects.equals(from, baseTx.from))
return false;
if (to != null ? !to.equals(baseTx.to) : baseTx.to != null)
if (!Objects.equals(to, baseTx.to))
return false;
return value != null ? value.equals(baseTx.value) : baseTx.value == null;
return Objects.equals(value, baseTx.value);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/api/etherscan/model/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public long getBlockNumber() {

public LocalDateTime getTimeStamp() {
if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp))
_timeStamp = LocalDateTime.ofEpochSecond(Long.valueOf(timeStamp), 0, ZoneOffset.UTC);
_timeStamp = LocalDateTime.ofEpochSecond(Long.parseLong(timeStamp), 0, ZoneOffset.UTC);
return _timeStamp;
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/api/etherscan/model/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -124,15 +125,15 @@ public boolean equals(Object o) {

Log log = (Log) o;

if (blockNumber != null ? !blockNumber.equals(log.blockNumber) : log.blockNumber != null)
if (!Objects.equals(blockNumber, log.blockNumber))
return false;
if (address != null ? !address.equals(log.address) : log.address != null)
if (!Objects.equals(address, log.address))
return false;
if (transactionHash != null ? !transactionHash.equals(log.transactionHash) : log.transactionHash != null)
if (!Objects.equals(transactionHash, log.transactionHash))
return false;
if (timeStamp != null ? !timeStamp.equals(log.timeStamp) : log.timeStamp != null)
if (!Objects.equals(timeStamp, log.timeStamp))
return false;
return logIndex != null ? logIndex.equals(log.logIndex) : log.logIndex == null;
return Objects.equals(logIndex, log.logIndex);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/api/etherscan/model/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public double inBtc() {

public LocalDateTime usdTimestamp() {
if (_ethusd_timestamp == null)
_ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethusd_timestamp), 0, ZoneOffset.UTC);
_ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethusd_timestamp), 0, ZoneOffset.UTC);
return _ethusd_timestamp;
}

public LocalDateTime btcTimestamp() {
if (_ethbtc_timestamp == null)
_ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.valueOf(ethbtc_timestamp), 0, ZoneOffset.UTC);
_ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethbtc_timestamp), 0, ZoneOffset.UTC);
return _ethbtc_timestamp;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/api/etherscan/model/Status.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.api.etherscan.model;

import java.util.Objects;

/**
* Contract Execution Status
*
Expand Down Expand Up @@ -33,7 +35,7 @@ public boolean equals(Object o) {

if (isError != status.isError)
return false;
return errDescription != null ? errDescription.equals(status.errDescription) : status.errDescription == null;
return Objects.equals(errDescription, status.errDescription);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/api/etherscan/model/TokenBalance.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.api.etherscan.model;

import java.math.BigInteger;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -31,8 +32,7 @@ public boolean equals(Object o) {
return false;

TokenBalance that = (TokenBalance) o;

return tokenContract != null ? tokenContract.equals(that.tokenContract) : that.tokenContract == null;
return Objects.equals(tokenContract, that.tokenContract);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/api/etherscan/model/Tx.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -70,9 +71,9 @@ public boolean equals(Object o) {
return false;
if (transactionIndex != tx.transactionIndex)
return false;
if (blockHash != null ? !blockHash.equals(tx.blockHash) : tx.blockHash != null)
if (!Objects.equals(blockHash, tx.blockHash))
return false;
return isError != null ? isError.equals(tx.isError) : tx.isError == null;
return Objects.equals(isError, tx.isError);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/api/etherscan/model/TxInternal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.api.etherscan.model;

import java.util.Objects;

/**
* ! NO DESCRIPTION !
*
Expand Down Expand Up @@ -44,7 +46,7 @@ public boolean equals(Object o) {

if (traceId != that.traceId)
return false;
return errCode != null ? errCode.equals(that.errCode) : that.errCode == null;
return Objects.equals(errCode, that.errCode);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/api/etherscan/model/Wei.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.api.etherscan.model;

import java.math.BigInteger;
import java.util.Objects;

/**
* ! NO DESCRIPTION !
Expand Down Expand Up @@ -46,8 +47,7 @@ public boolean equals(Object o) {
return false;

Wei wei = (Wei) o;

return result != null ? result.equals(wei.result) : wei.result == null;
return Objects.equals(result, wei.result);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class BaseResponseTO {
private String message;

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

public String getMessage() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/api/etherscan/model/utility/BlockParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
public class BlockParam {

private long startBlock;
private long endBlock;
private final long startBlock;
private final long endBlock;

public BlockParam(long startBlock, long endBlock) {
this.startBlock = startBlock;
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/io/api/etherscan/util/BasicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class BasicUtils {
private static final Pattern TXHASH_PATTERN = Pattern.compile("0x[a-zA-Z0-9]{64}");
private static final Pattern HEX_PATTERN = Pattern.compile("[a-zA-Z0-9]+");

private BasicUtils() {}

public static boolean isEmpty(String value) {
return value == null || value.isEmpty();
}
Expand All @@ -42,14 +44,8 @@ public static BlockParam compensateBlocks(long startBlock, long endBlock) {
long startCompensated = compensateMinBlock(startBlock);
long endCompensated = compensateMaxBlock(endBlock);

final long startFinal = (startCompensated > endCompensated)
? endCompensated
: startCompensated;

final long endFinal = (startCompensated > endCompensated)
? startCompensated
: endCompensated;

final long startFinal = Math.min(startCompensated, endCompensated);
final long endFinal = Math.max(startCompensated, endCompensated);
return new BlockParam(startFinal, endFinal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void correct() {
assertNotNull(price);
assertNotNull(price.btcTimestamp());
assertNotNull(price.usdTimestamp());
assertNotEquals(0, price.inBtc());
assertNotEquals(0, price.inUsd());
assertNotEquals(0.0, price.inBtc());
assertNotEquals(0.0, price.inUsd());
assertNotNull(price.toString());

Price empty = new Price();
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/io/api/manager/QueueManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ public void fakeManager() {
fakeManager.takeTurn();
fakeManager.takeTurn();
fakeManager.takeTurn();
assertNotNull(fakeManager);
}

@Test(timeout = 3500)
public void queueManager() {
IQueueManager queueManager = new QueueManager(1, 3);
queueManager.takeTurn();
queueManager.takeTurn();
assertNotNull(queueManager);
}

@Test(timeout = 4500)
public void queueManagerWithDelay() {
IQueueManager queueManager = new QueueManager(1, 2, 2);
queueManager.takeTurn();
queueManager.takeTurn();
assertNotNull(queueManager);
}

@Test
Expand Down

0 comments on commit 8ba73e8

Please sign in to comment.