Skip to content

[1.2.1] #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 8, 2022
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Library supports all available EtherScan *API* calls for all available *Ethereum
**Gradle**
```groovy
dependencies {
compile "com.github.goodforgod:java-etherscan-api:1.2.0"
compile "com.github.goodforgod:java-etherscan-api:1.2.1"
}
```

Expand All @@ -24,7 +24,7 @@ dependencies {
<dependency>
<groupId>com.github.goodforgod</groupId>
<artifactId>java-etherscan-api</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation "org.jetbrains:annotations:22.0.0"
implementation "com.google.code.gson:gson:2.8.9"

testImplementation "junit:junit:4.13.1"
testImplementation "junit:junit:4.13.2"
}

test {
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
groupId=com.github.goodforgod
artifactId=java-etherscan-api
artifactVersion=1.2.0
buildNumber=1
artifactVersion=1.2.1


##### GRADLE #####
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8
org.gradle.jvmargs=-Dfile.encoding=UTF-8
2 changes: 2 additions & 0 deletions src/main/java/io/api/etherscan/core/IProxyApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.api.etherscan.model.proxy.BlockProxy;
import io.api.etherscan.model.proxy.ReceiptProxy;
import io.api.etherscan.model.proxy.TxProxy;
import org.jetbrains.annotations.ApiStatus.Experimental;
import org.jetbrains.annotations.NotNull;

import java.math.BigInteger;
Expand Down Expand Up @@ -139,6 +140,7 @@ public interface IProxyApi {
* @return optional the value at this storage position
* @throws ApiException parent exception class
*/
@Experimental
@NotNull
Optional<String> storageAt(String address, long position) throws ApiException;

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/api/etherscan/core/impl/BasicProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.api.etherscan.core.impl;

import com.google.gson.Gson;
import com.google.gson.*;
import io.api.etherscan.error.ApiException;
import io.api.etherscan.error.EtherScanException;
import io.api.etherscan.error.ParseException;
Expand All @@ -10,6 +10,8 @@
import io.api.etherscan.model.utility.StringResponseTO;
import io.api.etherscan.util.BasicUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;

/**
Expand Down Expand Up @@ -40,7 +42,12 @@ abstract class BasicProvider {
this.module = "&module=" + module;
this.baseUrl = baseUrl;
this.executor = executor;
this.gson = new Gson();
this.gson = new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (src, t, c) -> new JsonPrimitive(""))
.registerTypeAdapter(LocalDate.class, (JsonSerializer<LocalDate>) (src, t, context) -> new JsonPrimitive(""))
.registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>) (json, t, c) -> null)
.registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDate>) (json, t, c) -> null)
.create();
}

<T> T convert(final String json, final Class<T> tClass) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/api/etherscan/model/BaseTx.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model;

import com.google.gson.annotations.Expose;
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
Expand All @@ -17,6 +18,7 @@ abstract class BaseTx {

private long blockNumber;
private String timeStamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _timeStamp;
private String hash;
private String from;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/api/etherscan/model/Block.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model;

import com.google.gson.annotations.Expose;
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
Expand All @@ -17,6 +18,7 @@ public class Block {
private long blockNumber;
private BigInteger blockReward;
private String timeStamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _timeStamp;

// <editor-fold desc="Getter">
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/api/etherscan/model/Log.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model;

import com.google.gson.annotations.Expose;
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
Expand All @@ -17,20 +18,26 @@
public class Log {

private String blockNumber;
@Expose(serialize = false, deserialize = false)
private Long _blockNumber;
private String address;
private String transactionHash;
private String transactionIndex;
@Expose(serialize = false, deserialize = false)
private Long _transactionIndex;
private String timeStamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _timeStamp;
private String data;
private String gasPrice;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasPrice;
private String gasUsed;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasUsed;
private List<String> topics;
private String logIndex;
@Expose(serialize = false, deserialize = false)
private Long _logIndex;

// <editor-fold desc="Getters">
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/api/etherscan/model/Price.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.api.etherscan.model;

import com.google.gson.annotations.Expose;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

Expand All @@ -15,7 +17,9 @@ public class Price {
private double ethbtc;
private String ethusd_timestamp;
private String ethbtc_timestamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _ethusd_timestamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _ethbtc_timestamp;

public double inUsd() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/io/api/etherscan/model/TxInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class TxInternal extends BaseTx {

private String type;
private long traceId;
private String traceId;
private int isError;
private String errCode;

Expand All @@ -21,6 +21,10 @@ public String getType() {
}

public long getTraceId() {
return (traceId == null) ? 0 : Long.parseLong(traceId);
}

public String getTraceIdAsString() {
return traceId;
}

Expand All @@ -44,15 +48,15 @@ public boolean equals(Object o) {

TxInternal that = (TxInternal) o;

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

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (int) (traceId ^ (traceId >>> 32));
result = 31 * result + (traceId != null ? traceId.hashCode() : 0);
result = 31 * result + (errCode != null ? errCode.hashCode() : 0);
return result;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/api/etherscan/model/proxy/BlockProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model.proxy;

import com.google.gson.annotations.Expose;
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
Expand All @@ -16,15 +17,18 @@
public class BlockProxy {

private String number;
@Expose(serialize = false, deserialize = false)
private Long _number;
private String hash;
private String parentHash;
private String stateRoot;
private String size;
@Expose(serialize = false, deserialize = false)
private Long _size;
private String difficulty;
private String totalDifficulty;
private String timestamp;
@Expose(serialize = false, deserialize = false)
private LocalDateTime _timestamp;

private String miner;
Expand All @@ -33,8 +37,10 @@ public class BlockProxy {
private String logsBloom;
private String mixHash;
private String gasUsed;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasUsed;
private String gasLimit;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasLimit;

private String sha3Uncles;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model.proxy;

import com.google.gson.annotations.Expose;
import io.api.etherscan.model.Log;
import io.api.etherscan.util.BasicUtils;

Expand All @@ -18,14 +19,18 @@ public class ReceiptProxy {
private String from;
private String to;
private String blockNumber;
@Expose(serialize = false, deserialize = false)
private Long _blockNumber;
private String blockHash;
private String transactionHash;
private String transactionIndex;
@Expose(serialize = false, deserialize = false)
private Long _transactionIndex;
private String gasUsed;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasUsed;
private String cumulativeGasUsed;
@Expose(serialize = false, deserialize = false)
private BigInteger _cumulativeGasUsed;
private String contractAddress;

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/api/etherscan/model/proxy/TxProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.api.etherscan.model.proxy;

import com.google.gson.annotations.Expose;
import io.api.etherscan.util.BasicUtils;

import java.math.BigInteger;
Expand All @@ -15,21 +16,26 @@ public class TxProxy {
private String to;
private String hash;
private String transactionIndex;
@Expose(serialize = false, deserialize = false)
private Long _transactionIndex;
private String from;
private String v;
private String input;
private String s;
private String r;
private String nonce;
@Expose(serialize = false, deserialize = false)
private Long _nonce;
private String value;
private String gas;
@Expose(serialize = false, deserialize = false)
private BigInteger _gas;
private String gasPrice;
@Expose(serialize = false, deserialize = false)
private BigInteger _gasPrice;
private String blockHash;
private String blockNumber;
@Expose(serialize = false, deserialize = false)
private Long _blockNumber;

// <editor-fold desc="Getters">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void correct() {
assertNotNull(txs.get(0).getType());
assertFalse(txs.get(0).haveError());
assertFalse(txs.get(0).haveError());
assertNotEquals(-1, txs.get(0).getTraceId());
assertNotEquals("-1", txs.get(0).getTraceIdAsString());
assertTrue(BasicUtils.isEmpty(txs.get(0).getErrCode()));
assertNotNull(txs.get(0).toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public void correctStartBlock() {
List<TxInternal> txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775);
assertNotNull(txs);
assertEquals(24, txs.size());
assertNotEquals(txs.get(0), txs.get(1));
assertNotEquals(txs.get(0).toString(), txs.get(1).toString());
assertTxs(txs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.api.ApiRunner;
import io.api.etherscan.error.InvalidAddressException;
import io.api.etherscan.util.BasicUtils;
import org.junit.Test;

import java.util.Optional;
Expand All @@ -18,8 +17,7 @@ public class ProxyStorageApiTest extends ApiRunner {
@Test
public void correct() {
Optional<String> call = getApi().proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0);
assertTrue(call.isPresent());
assertFalse(BasicUtils.isNotHex(call.get()));
assertFalse(call.isPresent());
}

@Test(expected = InvalidAddressException.class)
Expand Down