Skip to content

Commit fffd463

Browse files
committed
Proxy provider fixes
Model fixes & refactoring Test improvements & fixes
1 parent d8a7865 commit fffd463

19 files changed

+129
-252
lines changed
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package io.api.etherscan;
22

33
import io.api.etherscan.core.impl.EtherScanApi;
4-
import io.api.etherscan.model.*;
5-
6-
import java.util.List;
7-
import java.util.Optional;
4+
import io.api.etherscan.model.Balance;
85

96
/**
107
*
@@ -13,16 +10,6 @@ public class App {
1310
public static void main(String[] args) {
1411
EtherScanApi api = new EtherScanApi();
1512
Balance balance = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
16-
Balance balance1 = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
17-
Balance balance2 = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
18-
Balance balance3 = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
19-
Balance balance4 = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
20-
Balance balance5 = api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
21-
List<Tx> txs = api.account().txs("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
22-
List<TxToken> txTokens = api.account().txsToken("0xf261B3A60Ef40eE0B369B0705c1a2c58B02799DF");
23-
List<TxInternal> txInternals = api.account().txsInternal("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3");
24-
Optional<UncleBlock> uncles = api.block().uncles(2165403);
25-
Optional<UncleBlock> uncleEmpty = api.block().uncles(999965403);
2613
System.out.println("Test");
2714
}
2815
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.api.etherscan.error.ApiException;
44
import io.api.etherscan.model.proxy.BlockProxy;
5-
import io.api.etherscan.model.proxy.TxInfoProxy;
5+
import io.api.etherscan.model.proxy.ReceiptProxy;
66
import io.api.etherscan.model.proxy.TxProxy;
77
import org.jetbrains.annotations.NotNull;
88

@@ -70,7 +70,7 @@ public interface IProxyApi {
7070
* Returns the receipt of a transaction by transaction hash
7171
* eth_getTransactionReceipt
7272
*/
73-
@NotNull Optional<TxInfoProxy> txReceipt(String txhash) throws ApiException;
73+
@NotNull Optional<ReceiptProxy> txReceipt(String txhash) throws ApiException;
7474

7575
/**
7676
* Executes a new message call immediately without creating a transaction on the block chain

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io.api.etherscan.executor.IHttpExecutor;
88
import io.api.etherscan.manager.IQueueManager;
99
import io.api.etherscan.model.proxy.BlockProxy;
10-
import io.api.etherscan.model.proxy.TxInfoProxy;
10+
import io.api.etherscan.model.proxy.ReceiptProxy;
1111
import io.api.etherscan.model.proxy.TxProxy;
1212
import io.api.etherscan.model.proxy.utility.BlockProxyTO;
1313
import io.api.etherscan.model.proxy.utility.StringProxyTO;
@@ -148,7 +148,7 @@ public Optional<String> txSendRaw(final String hexEncodedTx) throws ApiException
148148

149149
@NotNull
150150
@Override
151-
public Optional<TxInfoProxy> txReceipt(final String txhash) throws ApiException {
151+
public Optional<ReceiptProxy> txReceipt(final String txhash) throws ApiException {
152152
BasicUtils.validateTxHash(txhash);
153153

154154
final String urlParams = ACT_TX_RECEIPT_PARAM + TXHASH_PARAM + txhash;

src/main/java/io/api/etherscan/error/ConnectionException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
*/
99
public class ConnectionException extends ApiException {
1010

11-
public ConnectionException(String message) {
12-
super(message);
13-
}
14-
1511
public ConnectionException(String message, Throwable cause) {
1612
super(message, cause);
1713
}

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,8 @@ abstract class BaseTx {
2323
private BigInteger value;
2424
private String contractAddress;
2525
private String input;
26-
private long gas;
27-
private long gasUsed;
28-
29-
BaseTx() { }
30-
31-
public BaseTx(long blockNumber, LocalDateTime _timeStamp, String hash,
32-
String from, String to, BigInteger value, String contractAddress,
33-
String input, long gas, long gasUsed) {
34-
this.blockNumber = blockNumber;
35-
this._timeStamp = _timeStamp;
36-
this.hash = hash;
37-
this.from = from;
38-
this.to = to;
39-
this.value = value;
40-
this.contractAddress = contractAddress;
41-
this.input = input;
42-
this.gas = gas;
43-
this.gasUsed = gasUsed;
44-
}
26+
private BigInteger gas;
27+
private BigInteger gasUsed;
4528

4629
//<editor-fold desc="Getter">
4730
public long getBlockNumber() {
@@ -78,11 +61,11 @@ public String getInput() {
7861
return input;
7962
}
8063

81-
public long getGas() {
64+
public BigInteger getGas() {
8265
return gas;
8366
}
8467

85-
public long getGasUsed() {
68+
public BigInteger getGasUsed() {
8669
return gasUsed;
8770
}
8871
//</editor-fold>
Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.api.etherscan.model;
22

3+
import io.api.etherscan.util.BasicUtils;
4+
5+
import java.math.BigInteger;
36
import java.time.LocalDateTime;
7+
import java.time.ZoneOffset;
48
import java.util.List;
59

610
/**
@@ -12,37 +16,28 @@
1216
public class Log {
1317

1418
private String blockNumber;
19+
private long _blockNumber;
1520
private String address;
1621
private String transactionHash;
1722
private String transactionIndex;
23+
private long _transactionIndex;
1824
private String timeStamp;
1925
private LocalDateTime _timeStamp;
2026
private String data;
2127
private String gasPrice;
28+
private BigInteger _gasPrice;
2229
private String gasUsed;
30+
private BigInteger _gasUsed;
2331
private List<String> topics;
2432
private String logIndex;
25-
26-
public Log() { }
27-
28-
public Log(String blockNumber, String address, String transactionHash, String transactionIndex,
29-
LocalDateTime _timeStamp, String data, String gasPrice, String gasUsed,
30-
List<String> topics, String logIndex) {
31-
this.blockNumber = blockNumber;
32-
this.address = address;
33-
this.transactionHash = transactionHash;
34-
this.transactionIndex = transactionIndex;
35-
this._timeStamp = _timeStamp;
36-
this.data = data;
37-
this.gasPrice = gasPrice;
38-
this.gasUsed = gasUsed;
39-
this.topics = topics;
40-
this.logIndex = logIndex;
41-
}
33+
private long _logIndex;
4234

4335
//<editor-fold desc="Getters">
44-
public String getBlockNumber() {
45-
return blockNumber;
36+
public long getBlockNumber() {
37+
if(!BasicUtils.isEmpty(blockNumber)){
38+
_blockNumber = BasicUtils.parseHex(blockNumber).longValue();
39+
}
40+
return _blockNumber;
4641
}
4742

4843
public String getAddress() {
@@ -53,36 +48,53 @@ public String getTransactionHash() {
5348
return transactionHash;
5449
}
5550

56-
public String getTransactionIndex() {
57-
return transactionIndex;
58-
}
51+
public long getTransactionIndex() {
52+
if(!BasicUtils.isEmpty(transactionIndex)){
53+
_transactionIndex = BasicUtils.parseHex(transactionIndex).longValue();
54+
}
5955

60-
public String getTimeStamp() {
61-
return timeStamp;
56+
return _transactionIndex;
6257
}
6358

64-
public LocalDateTime get_timeStamp() {
59+
public LocalDateTime getTimeStamp() {
60+
if(_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) {
61+
long formatted = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
62+
? BasicUtils.parseHex(timeStamp).longValue()
63+
: Long.valueOf(timeStamp);
64+
_timeStamp = LocalDateTime.ofEpochSecond(formatted, 0, ZoneOffset.UTC);
65+
}
6566
return _timeStamp;
6667
}
6768

6869
public String getData() {
6970
return data;
7071
}
7172

72-
public String getGasPrice() {
73-
return gasPrice;
73+
public BigInteger getGasPrice() {
74+
if(!BasicUtils.isEmpty(gasPrice)){
75+
_gasPrice = BasicUtils.parseHex(gasPrice);
76+
}
77+
78+
return _gasPrice;
7479
}
7580

76-
public String getGasUsed() {
77-
return gasUsed;
81+
public BigInteger getGasUsed() {
82+
if(!BasicUtils.isEmpty(gasUsed)){
83+
_gasUsed = BasicUtils.parseHex(gasUsed);
84+
}
85+
86+
return _gasUsed;
7887
}
7988

8089
public List<String> getTopics() {
8190
return topics;
8291
}
8392

84-
public String getLogIndex() {
85-
return logIndex;
93+
public long getLogIndex() {
94+
if(!BasicUtils.isEmpty(logIndex)){
95+
_logIndex = BasicUtils.parseHex(logIndex).longValue();
96+
}
97+
return _logIndex;
8698
}
8799
//</editor-fold>
88100
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.api.etherscan.util.BasicUtils;
44

5+
import java.math.BigInteger;
6+
57
/**
68
* ! NO DESCRIPTION !
79
*
@@ -13,8 +15,8 @@ public class Tx extends BaseTx {
1315
private long nonce;
1416
private String blockHash;
1517
private int transactionIndex;
16-
private long gasPrice;
17-
private long cumulativeGasUsed;
18+
private BigInteger gasPrice;
19+
private BigInteger cumulativeGasUsed;
1820
private long confirmations;
1921
private String isError;
2022
private String txreceipt_status;
@@ -32,7 +34,7 @@ public int getTransactionIndex() {
3234
return transactionIndex;
3335
}
3436

35-
public long getGasPrice() {
37+
public BigInteger getGasPrice() {
3638
return gasPrice;
3739
}
3840

@@ -44,7 +46,7 @@ public String getTxreceipt_status() {
4446
return txreceipt_status;
4547
}
4648

47-
public long getCumulativeGasUsed() {
49+
public BigInteger getCumulativeGasUsed() {
4850
return cumulativeGasUsed;
4951
}
5052

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ public class Uncle {
1414
private BigInteger blockreward;
1515
private int unclePosition;
1616

17-
public Uncle() {}
18-
19-
public Uncle(String miner, BigInteger blockreward, int unclePosition) {
20-
this.miner = miner;
21-
this.blockreward = blockreward;
22-
this.unclePosition = unclePosition;
23-
}
24-
2517
//<editor-fold desc="Getters">
2618
public String getMiner() {
2719
return miner;

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

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)