From 7fc59463be2790579c39b426351f24b582e7b465 Mon Sep 17 00:00:00 2001 From: guggio Date: Sun, 20 Feb 2022 01:15:32 +0100 Subject: [PATCH 1/6] Changed traceId in TxInternal from long to String --- src/main/java/io/api/etherscan/model/TxInternal.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/api/etherscan/model/TxInternal.java b/src/main/java/io/api/etherscan/model/TxInternal.java index 22c5104..b51440a 100644 --- a/src/main/java/io/api/etherscan/model/TxInternal.java +++ b/src/main/java/io/api/etherscan/model/TxInternal.java @@ -11,7 +11,7 @@ public class TxInternal extends BaseTx { private String type; - private long traceId; + private String traceId; private int isError; private String errCode; @@ -20,7 +20,7 @@ public String getType() { return type; } - public long getTraceId() { + public String getTraceId() { return traceId; } @@ -44,7 +44,7 @@ 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); } @@ -52,7 +52,7 @@ public boolean equals(Object o) { @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; } From bffcbb991c64cf7c9228310ad0c10edaac71150c Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Mar 2022 16:37:44 +0300 Subject: [PATCH 2/6] [1.2.1-SNAPSHOT] BasicProvider Gson registration for LocalDate and LocalDateTime types added --- README.md | 4 ++-- build.gradle | 2 +- gradle.properties | 5 ++--- .../etherscan/core/impl/BasicProvider.java | 22 +++++++++++++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4468a8d..c46a28f 100644 --- a/README.md +++ b/README.md @@ -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" } ``` @@ -24,7 +24,7 @@ dependencies { com.github.goodforgod java-etherscan-api - 1.2.0 + 1.2.1 ``` diff --git a/build.gradle b/build.gradle index f599905..70ed3fa 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/gradle.properties b/gradle.properties index 4022082..455c02b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,6 @@ groupId=com.github.goodforgod artifactId=java-etherscan-api -artifactVersion=1.2.0 -buildNumber=1 +artifactVersion=1.2.1-SNAPSHOT ##### GRADLE ##### @@ -9,4 +8,4 @@ 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 \ No newline at end of file diff --git a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java index b89447a..a14c0d9 100644 --- a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java @@ -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; @@ -10,6 +10,9 @@ import io.api.etherscan.model.utility.StringResponseTO; import io.api.etherscan.util.BasicUtils; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Map; /** @@ -40,7 +43,22 @@ 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) (src, typeOfSrc, context) -> new JsonPrimitive( + src.format(DateTimeFormatter.ISO_DATE_TIME))) + .registerTypeAdapter(LocalDate.class, + (JsonSerializer) (src, typeOfSrc, + context) -> new JsonPrimitive(src.format(DateTimeFormatter.ISO_DATE))) + .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer) (json, type, context) -> { + String datetime = json.getAsJsonPrimitive().getAsString(); + return LocalDateTime.parse(datetime, DateTimeFormatter.ISO_DATE_TIME); + }) + .registerTypeAdapter(LocalDate.class, (JsonDeserializer) (json, type, context) -> { + String datetime = json.getAsJsonPrimitive().getAsString(); + return LocalDate.parse(datetime, DateTimeFormatter.ISO_DATE); + }).create(); + } T convert(final String json, final Class tClass) { From bed627d33752efe5490397a4957665d43ce7c049 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Mar 2022 16:52:07 +0300 Subject: [PATCH 3/6] [1.2.1-SNAPSHOT] TxInternal#getTraceIdAsString added --- src/main/java/io/api/etherscan/model/TxInternal.java | 6 +++++- .../api/etherscan/account/AccountTxInternalByHashTest.java | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/api/etherscan/model/TxInternal.java b/src/main/java/io/api/etherscan/model/TxInternal.java index b51440a..ab6ccd5 100644 --- a/src/main/java/io/api/etherscan/model/TxInternal.java +++ b/src/main/java/io/api/etherscan/model/TxInternal.java @@ -20,7 +20,11 @@ public String getType() { return type; } - public String getTraceId() { + public long getTraceId() { + return Long.parseLong(traceId); + } + + public String getTraceIdAsString() { return traceId; } diff --git a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java index d1ed2bc..96e4eb0 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java @@ -64,6 +64,7 @@ public void correct() { 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()); From bc3449e2491104410adb5df73172f107959c6309 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Mar 2022 16:52:26 +0300 Subject: [PATCH 4/6] [1.2.1] Release prepared 1.2.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 455c02b..a6ba485 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=com.github.goodforgod artifactId=java-etherscan-api -artifactVersion=1.2.1-SNAPSHOT +artifactVersion=1.2.1 ##### GRADLE ##### From 1d1aa6f6850be41ebb652097e275859da2d9ae0d Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Mar 2022 17:07:15 +0300 Subject: [PATCH 5/6] [1.2.1] IProxyApi#storageAt marked as Experimental Tests fixed --- src/main/java/io/api/etherscan/core/IProxyApi.java | 2 ++ .../io/api/etherscan/account/AccountTxInternalByHashTest.java | 1 - src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/api/etherscan/core/IProxyApi.java b/src/main/java/io/api/etherscan/core/IProxyApi.java index e57f6ec..6adcdf0 100644 --- a/src/main/java/io/api/etherscan/core/IProxyApi.java +++ b/src/main/java/io/api/etherscan/core/IProxyApi.java @@ -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; @@ -139,6 +140,7 @@ public interface IProxyApi { * @return optional the value at this storage position * @throws ApiException parent exception class */ + @Experimental @NotNull Optional storageAt(String address, long position) throws ApiException; diff --git a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java index 96e4eb0..126fd90 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java @@ -63,7 +63,6 @@ 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()); diff --git a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java index ecd7dca..b7c8077 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java @@ -18,8 +18,7 @@ public class ProxyStorageApiTest extends ApiRunner { @Test public void correct() { Optional call = getApi().proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0); - assertTrue(call.isPresent()); - assertFalse(BasicUtils.isNotHex(call.get())); + assertFalse(call.isPresent()); } @Test(expected = InvalidAddressException.class) From aae15461453c009ade19c98129796e74b2ffaca0 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Mar 2022 17:12:43 +0300 Subject: [PATCH 6/6] [1.2.1] TxInternal equal and toString asserts added [1.2.1] DTO internal fields exposure removed BasicProvider fake adapters registered [1.2.1] Code style fixed [1.2.1] TxInternal#getTraceId return 0 if null --- .../etherscan/core/impl/BasicProvider.java | 21 +++++-------------- .../java/io/api/etherscan/model/BaseTx.java | 2 ++ .../java/io/api/etherscan/model/Block.java | 2 ++ src/main/java/io/api/etherscan/model/Log.java | 7 +++++++ .../java/io/api/etherscan/model/Price.java | 4 ++++ .../io/api/etherscan/model/TxInternal.java | 2 +- .../api/etherscan/model/proxy/BlockProxy.java | 6 ++++++ .../etherscan/model/proxy/ReceiptProxy.java | 5 +++++ .../io/api/etherscan/model/proxy/TxProxy.java | 6 ++++++ .../account/AccountTxInternalTest.java | 2 ++ .../etherscan/proxy/ProxyStorageApiTest.java | 1 - 11 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java index a14c0d9..b36f406 100644 --- a/src/main/java/io/api/etherscan/core/impl/BasicProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/BasicProvider.java @@ -12,7 +12,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.Map; /** @@ -44,21 +43,11 @@ abstract class BasicProvider { this.baseUrl = baseUrl; this.executor = executor; this.gson = new GsonBuilder() - .registerTypeAdapter(LocalDateTime.class, - (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive( - src.format(DateTimeFormatter.ISO_DATE_TIME))) - .registerTypeAdapter(LocalDate.class, - (JsonSerializer) (src, typeOfSrc, - context) -> new JsonPrimitive(src.format(DateTimeFormatter.ISO_DATE))) - .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer) (json, type, context) -> { - String datetime = json.getAsJsonPrimitive().getAsString(); - return LocalDateTime.parse(datetime, DateTimeFormatter.ISO_DATE_TIME); - }) - .registerTypeAdapter(LocalDate.class, (JsonDeserializer) (json, type, context) -> { - String datetime = json.getAsJsonPrimitive().getAsString(); - return LocalDate.parse(datetime, DateTimeFormatter.ISO_DATE); - }).create(); - + .registerTypeAdapter(LocalDateTime.class, (JsonSerializer) (src, t, c) -> new JsonPrimitive("")) + .registerTypeAdapter(LocalDate.class, (JsonSerializer) (src, t, context) -> new JsonPrimitive("")) + .registerTypeAdapter(LocalDateTime.class, (JsonDeserializer) (json, t, c) -> null) + .registerTypeAdapter(LocalDate.class, (JsonDeserializer) (json, t, c) -> null) + .create(); } T convert(final String json, final Class tClass) { diff --git a/src/main/java/io/api/etherscan/model/BaseTx.java b/src/main/java/io/api/etherscan/model/BaseTx.java index a219e57..6eba826 100644 --- a/src/main/java/io/api/etherscan/model/BaseTx.java +++ b/src/main/java/io/api/etherscan/model/BaseTx.java @@ -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; @@ -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; diff --git a/src/main/java/io/api/etherscan/model/Block.java b/src/main/java/io/api/etherscan/model/Block.java index d328841..8853956 100644 --- a/src/main/java/io/api/etherscan/model/Block.java +++ b/src/main/java/io/api/etherscan/model/Block.java @@ -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; @@ -17,6 +18,7 @@ public class Block { private long blockNumber; private BigInteger blockReward; private String timeStamp; + @Expose(serialize = false, deserialize = false) private LocalDateTime _timeStamp; // diff --git a/src/main/java/io/api/etherscan/model/Log.java b/src/main/java/io/api/etherscan/model/Log.java index 36d126b..67ce96f 100644 --- a/src/main/java/io/api/etherscan/model/Log.java +++ b/src/main/java/io/api/etherscan/model/Log.java @@ -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; @@ -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 topics; private String logIndex; + @Expose(serialize = false, deserialize = false) private Long _logIndex; // diff --git a/src/main/java/io/api/etherscan/model/Price.java b/src/main/java/io/api/etherscan/model/Price.java index d2c6d1c..9bc7dc7 100644 --- a/src/main/java/io/api/etherscan/model/Price.java +++ b/src/main/java/io/api/etherscan/model/Price.java @@ -1,5 +1,7 @@ package io.api.etherscan.model; +import com.google.gson.annotations.Expose; + import java.time.LocalDateTime; import java.time.ZoneOffset; @@ -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() { diff --git a/src/main/java/io/api/etherscan/model/TxInternal.java b/src/main/java/io/api/etherscan/model/TxInternal.java index ab6ccd5..5048947 100644 --- a/src/main/java/io/api/etherscan/model/TxInternal.java +++ b/src/main/java/io/api/etherscan/model/TxInternal.java @@ -21,7 +21,7 @@ public String getType() { } public long getTraceId() { - return Long.parseLong(traceId); + return (traceId == null) ? 0 : Long.parseLong(traceId); } public String getTraceIdAsString() { diff --git a/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java b/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java index 3d7ddd3..63821c0 100644 --- a/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/BlockProxy.java @@ -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; @@ -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; @@ -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; diff --git a/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java b/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java index d69a627..f40cb59 100644 --- a/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/ReceiptProxy.java @@ -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; @@ -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; diff --git a/src/main/java/io/api/etherscan/model/proxy/TxProxy.java b/src/main/java/io/api/etherscan/model/proxy/TxProxy.java index 25b50c8..5c7b5c8 100644 --- a/src/main/java/io/api/etherscan/model/proxy/TxProxy.java +++ b/src/main/java/io/api/etherscan/model/proxy/TxProxy.java @@ -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; @@ -15,6 +16,7 @@ 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; @@ -22,14 +24,18 @@ public class TxProxy { 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; // diff --git a/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java b/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java index f993c39..47f3e61 100644 --- a/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java +++ b/src/test/java/io/api/etherscan/account/AccountTxInternalTest.java @@ -29,6 +29,8 @@ public void correctStartBlock() { List 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); } diff --git a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java index b7c8077..19945e2 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java @@ -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;