Skip to content

Commit cafcdff

Browse files
authored
Merge pull request #19 from GoodforGod/dev
[1.2.1]
2 parents 22c9679 + aae1546 commit cafcdff

16 files changed

+59
-15
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Library supports all available EtherScan *API* calls for all available *Ethereum
1515
**Gradle**
1616
```groovy
1717
dependencies {
18-
compile "com.github.goodforgod:java-etherscan-api:1.2.0"
18+
compile "com.github.goodforgod:java-etherscan-api:1.2.1"
1919
}
2020
```
2121

@@ -24,7 +24,7 @@ dependencies {
2424
<dependency>
2525
<groupId>com.github.goodforgod</groupId>
2626
<artifactId>java-etherscan-api</artifactId>
27-
<version>1.2.0</version>
27+
<version>1.2.1</version>
2828
</dependency>
2929
```
3030

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
implementation "org.jetbrains:annotations:22.0.0"
3939
implementation "com.google.code.gson:gson:2.8.9"
4040

41-
testImplementation "junit:junit:4.13.1"
41+
testImplementation "junit:junit:4.13.2"
4242
}
4343

4444
test {

gradle.properties

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
groupId=com.github.goodforgod
22
artifactId=java-etherscan-api
3-
artifactVersion=1.2.0
4-
buildNumber=1
3+
artifactVersion=1.2.1
54

65

76
##### GRADLE #####
87
org.gradle.daemon=true
98
org.gradle.parallel=true
109
org.gradle.configureondemand=true
1110
org.gradle.caching=true
12-
org.gradle.jvmargs=-Dfile.encoding=UTF-8
11+
org.gradle.jvmargs=-Dfile.encoding=UTF-8

src/main/java/io/api/etherscan/core/IProxyApi.java

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.api.etherscan.model.proxy.BlockProxy;
55
import io.api.etherscan.model.proxy.ReceiptProxy;
66
import io.api.etherscan.model.proxy.TxProxy;
7+
import org.jetbrains.annotations.ApiStatus.Experimental;
78
import org.jetbrains.annotations.NotNull;
89

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

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

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

3-
import com.google.gson.Gson;
3+
import com.google.gson.*;
44
import io.api.etherscan.error.ApiException;
55
import io.api.etherscan.error.EtherScanException;
66
import io.api.etherscan.error.ParseException;
@@ -10,6 +10,8 @@
1010
import io.api.etherscan.model.utility.StringResponseTO;
1111
import io.api.etherscan.util.BasicUtils;
1212

13+
import java.time.LocalDate;
14+
import java.time.LocalDateTime;
1315
import java.util.Map;
1416

1517
/**
@@ -40,7 +42,12 @@ abstract class BasicProvider {
4042
this.module = "&module=" + module;
4143
this.baseUrl = baseUrl;
4244
this.executor = executor;
43-
this.gson = new Gson();
45+
this.gson = new GsonBuilder()
46+
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (src, t, c) -> new JsonPrimitive(""))
47+
.registerTypeAdapter(LocalDate.class, (JsonSerializer<LocalDate>) (src, t, context) -> new JsonPrimitive(""))
48+
.registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>) (json, t, c) -> null)
49+
.registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDate>) (json, t, c) -> null)
50+
.create();
4451
}
4552

4653
<T> T convert(final String json, final Class<T> tClass) {

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.util.BasicUtils;
45

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

1819
private long blockNumber;
1920
private String timeStamp;
21+
@Expose(serialize = false, deserialize = false)
2022
private LocalDateTime _timeStamp;
2123
private String hash;
2224
private String from;

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.util.BasicUtils;
45

56
import java.math.BigInteger;
@@ -17,6 +18,7 @@ public class Block {
1718
private long blockNumber;
1819
private BigInteger blockReward;
1920
private String timeStamp;
21+
@Expose(serialize = false, deserialize = false)
2022
private LocalDateTime _timeStamp;
2123

2224
// <editor-fold desc="Getter">

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.util.BasicUtils;
45

56
import java.math.BigInteger;
@@ -17,20 +18,26 @@
1718
public class Log {
1819

1920
private String blockNumber;
21+
@Expose(serialize = false, deserialize = false)
2022
private Long _blockNumber;
2123
private String address;
2224
private String transactionHash;
2325
private String transactionIndex;
26+
@Expose(serialize = false, deserialize = false)
2427
private Long _transactionIndex;
2528
private String timeStamp;
29+
@Expose(serialize = false, deserialize = false)
2630
private LocalDateTime _timeStamp;
2731
private String data;
2832
private String gasPrice;
33+
@Expose(serialize = false, deserialize = false)
2934
private BigInteger _gasPrice;
3035
private String gasUsed;
36+
@Expose(serialize = false, deserialize = false)
3137
private BigInteger _gasUsed;
3238
private List<String> topics;
3339
private String logIndex;
40+
@Expose(serialize = false, deserialize = false)
3441
private Long _logIndex;
3542

3643
// <editor-fold desc="Getters">

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

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

3+
import com.google.gson.annotations.Expose;
4+
35
import java.time.LocalDateTime;
46
import java.time.ZoneOffset;
57

@@ -15,7 +17,9 @@ public class Price {
1517
private double ethbtc;
1618
private String ethusd_timestamp;
1719
private String ethbtc_timestamp;
20+
@Expose(serialize = false, deserialize = false)
1821
private LocalDateTime _ethusd_timestamp;
22+
@Expose(serialize = false, deserialize = false)
1923
private LocalDateTime _ethbtc_timestamp;
2024

2125
public double inUsd() {

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class TxInternal extends BaseTx {
1212

1313
private String type;
14-
private long traceId;
14+
private String traceId;
1515
private int isError;
1616
private String errCode;
1717

@@ -21,6 +21,10 @@ public String getType() {
2121
}
2222

2323
public long getTraceId() {
24+
return (traceId == null) ? 0 : Long.parseLong(traceId);
25+
}
26+
27+
public String getTraceIdAsString() {
2428
return traceId;
2529
}
2630

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

4549
TxInternal that = (TxInternal) o;
4650

47-
if (traceId != that.traceId)
51+
if (!Objects.equals(traceId, that.traceId))
4852
return false;
4953
return Objects.equals(errCode, that.errCode);
5054
}
5155

5256
@Override
5357
public int hashCode() {
5458
int result = super.hashCode();
55-
result = 31 * result + (int) (traceId ^ (traceId >>> 32));
59+
result = 31 * result + (traceId != null ? traceId.hashCode() : 0);
5660
result = 31 * result + (errCode != null ? errCode.hashCode() : 0);
5761
return result;
5862
}

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.util.BasicUtils;
45

56
import java.math.BigInteger;
@@ -16,15 +17,18 @@
1617
public class BlockProxy {
1718

1819
private String number;
20+
@Expose(serialize = false, deserialize = false)
1921
private Long _number;
2022
private String hash;
2123
private String parentHash;
2224
private String stateRoot;
2325
private String size;
26+
@Expose(serialize = false, deserialize = false)
2427
private Long _size;
2528
private String difficulty;
2629
private String totalDifficulty;
2730
private String timestamp;
31+
@Expose(serialize = false, deserialize = false)
2832
private LocalDateTime _timestamp;
2933

3034
private String miner;
@@ -33,8 +37,10 @@ public class BlockProxy {
3337
private String logsBloom;
3438
private String mixHash;
3539
private String gasUsed;
40+
@Expose(serialize = false, deserialize = false)
3641
private BigInteger _gasUsed;
3742
private String gasLimit;
43+
@Expose(serialize = false, deserialize = false)
3844
private BigInteger _gasLimit;
3945

4046
private String sha3Uncles;

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.model.Log;
45
import io.api.etherscan.util.BasicUtils;
56

@@ -18,14 +19,18 @@ public class ReceiptProxy {
1819
private String from;
1920
private String to;
2021
private String blockNumber;
22+
@Expose(serialize = false, deserialize = false)
2123
private Long _blockNumber;
2224
private String blockHash;
2325
private String transactionHash;
2426
private String transactionIndex;
27+
@Expose(serialize = false, deserialize = false)
2528
private Long _transactionIndex;
2629
private String gasUsed;
30+
@Expose(serialize = false, deserialize = false)
2731
private BigInteger _gasUsed;
2832
private String cumulativeGasUsed;
33+
@Expose(serialize = false, deserialize = false)
2934
private BigInteger _cumulativeGasUsed;
3035
private String contractAddress;
3136

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

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

3+
import com.google.gson.annotations.Expose;
34
import io.api.etherscan.util.BasicUtils;
45

56
import java.math.BigInteger;
@@ -15,21 +16,26 @@ public class TxProxy {
1516
private String to;
1617
private String hash;
1718
private String transactionIndex;
19+
@Expose(serialize = false, deserialize = false)
1820
private Long _transactionIndex;
1921
private String from;
2022
private String v;
2123
private String input;
2224
private String s;
2325
private String r;
2426
private String nonce;
27+
@Expose(serialize = false, deserialize = false)
2528
private Long _nonce;
2629
private String value;
2730
private String gas;
31+
@Expose(serialize = false, deserialize = false)
2832
private BigInteger _gas;
2933
private String gasPrice;
34+
@Expose(serialize = false, deserialize = false)
3035
private BigInteger _gasPrice;
3136
private String blockHash;
3237
private String blockNumber;
38+
@Expose(serialize = false, deserialize = false)
3339
private Long _blockNumber;
3440

3541
// <editor-fold desc="Getters">

src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void correct() {
6363
assertNotNull(txs.get(0).getType());
6464
assertFalse(txs.get(0).haveError());
6565
assertFalse(txs.get(0).haveError());
66-
assertNotEquals(-1, txs.get(0).getTraceId());
66+
assertNotEquals("-1", txs.get(0).getTraceIdAsString());
6767
assertTrue(BasicUtils.isEmpty(txs.get(0).getErrCode()));
6868
assertNotNull(txs.get(0).toString());
6969

src/test/java/io/api/etherscan/account/AccountTxInternalTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public void correctStartBlock() {
2929
List<TxInternal> txs = getApi().account().txsInternal("0x2C1ba59D6F58433FB1EaEe7d20b26Ed83bDA51A3", 2558775);
3030
assertNotNull(txs);
3131
assertEquals(24, txs.size());
32+
assertNotEquals(txs.get(0), txs.get(1));
33+
assertNotEquals(txs.get(0).toString(), txs.get(1).toString());
3234
assertTxs(txs);
3335
}
3436

src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.api.ApiRunner;
44
import io.api.etherscan.error.InvalidAddressException;
5-
import io.api.etherscan.util.BasicUtils;
65
import org.junit.Test;
76

87
import java.util.Optional;
@@ -18,8 +17,7 @@ public class ProxyStorageApiTest extends ApiRunner {
1817
@Test
1918
public void correct() {
2019
Optional<String> call = getApi().proxy().storageAt("0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd", 0);
21-
assertTrue(call.isPresent());
22-
assertFalse(BasicUtils.isNotHex(call.get()));
20+
assertFalse(call.isPresent());
2321
}
2422

2523
@Test(expected = InvalidAddressException.class)

0 commit comments

Comments
 (0)