Skip to content

Commit 6d5a02b

Browse files
committed
LogQuery builders for log api part
Providers improvements Providers contracts Other models improvements & refactoring
1 parent 0b60b49 commit 6d5a02b

35 files changed

+706
-49
lines changed

src/main/java/io/api/core/EtherScanApi.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ public EtherScanApi(final String apiKey) {
3535

3636
public EtherScanApi(final String apiKey,
3737
final EthereumNetwork network) {
38-
final EthereumNetwork usedNetwork = (network == null)
39-
? EthereumNetwork.MAINNET
40-
: network;
41-
4238
// EtherScan 5req\sec limit support
4339
final IQueueManager masterQueue = new QueueManager(5, 1);
4440

41+
final EthereumNetwork usedNetwork = (network == null) ? EthereumNetwork.MAINNET : network;
4542
final String url = "https://" + usedNetwork.getDomain() + ".etherscan.io/api" + "?apikey=" + apiKey;
4643
this.contract = new ContractProvider(masterQueue, url, HEADERS);
4744
this.account = new AccountProvider(masterQueue, url, HEADERS);

src/main/java/io/api/core/IAccountProvider.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ public interface IAccountProvider {
1919
@NotNull Balance balance(String address) throws ApiException;
2020

2121
/**
22-
* Maximum 20 address for batch request
22+
* Maximum 20 address for single batch request
2323
* If address > 20, then there will be more than 1 request performed
2424
*/
2525
@NotNull List<Balance> balances(List<String> addresses) throws ApiException;
2626

2727
/** All txs */
2828
@NotNull List<Tx> txs(String address) throws ApiException;
29-
@NotNull List<Tx> txs(String address, long startBlock);
30-
@NotNull List<Tx> txs(String address, long startBlock, long endBlock);
29+
@NotNull List<Tx> txs(String address, long startBlock) throws ApiException;
30+
@NotNull List<Tx> txs(String address, long startBlock, long endBlock) throws ApiException;
3131

3232
/** All internal txs */
33-
@NotNull List<TxInternal> txsInternal(String address);
34-
@NotNull List<TxInternal> txsInternal(String address, long startBlock);
35-
@NotNull List<TxInternal> txsInternal(String address, long startBlock, long endBlock);
33+
@NotNull List<TxInternal> txsInternal(String address) throws ApiException;
34+
@NotNull List<TxInternal> txsInternal(String address, long startBlock) throws ApiException;
35+
@NotNull List<TxInternal> txsInternal(String address, long startBlock, long endBlock) throws ApiException;
3636
@NotNull List<TxInternal> txsInternalByHash(String txhash);
3737

3838
/** All token txs */
39-
@NotNull List<TxToken> txsToken(String address);
40-
@NotNull List<TxToken> txsToken(String address, long startBlock);
41-
@NotNull List<TxToken> txsToken(String address, long startBlock, long endBlock);
39+
@NotNull List<TxToken> txsToken(String address) throws ApiException;
40+
@NotNull List<TxToken> txsToken(String address, long startBlock) throws ApiException;
41+
@NotNull List<TxToken> txsToken(String address, long startBlock, long endBlock) throws ApiException;
4242

4343
/** All blocks mined by address */
44-
@NotNull List<Block> minedBlocks(String address);
44+
@NotNull List<Block> minedBlocks(String address) throws ApiException;
4545
}

src/main/java/io/api/core/IBlockProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
*/
1212
public interface IBlockProvider {
1313

14+
/** Return uncle blocks */
1415
UncleBlock uncles(long blockNumber);
1516
}

src/main/java/io/api/core/ILogsProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.api.core;
22

3+
import io.api.model.Log;
4+
5+
import java.util.List;
6+
37
/**
48
* EtherScan - API Descriptions
59
* https://etherscan.io/apis#logs
@@ -9,4 +13,7 @@
913
*/
1014
public interface ILogsProvider {
1115

16+
List<Log> logs(String address);
17+
List<Log> logs(String address, long startBlock);
18+
List<Log> logs(String address, long startBlock, long endBlock);
1219
}

src/main/java/io/api/core/IParityProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
*/
1010
public interface IParityProvider {
1111

12+
//TODO implement
1213
}

src/main/java/io/api/core/IStatisticProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.api.core;
22

3+
import io.api.model.Price;
4+
import io.api.model.Supply;
5+
36
/**
47
* EtherScan - API Descriptions
58
* https://etherscan.io/apis#stats
@@ -9,4 +12,9 @@
912
*/
1013
public interface IStatisticProvider {
1114

15+
/** Eth Total Supply */
16+
Supply supply();
17+
18+
/** Eth last USD and BTC price */
19+
Price lastPrice();
1220
}

src/main/java/io/api/core/ITokenProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.api.core;
22

3+
import java.math.BigInteger;
4+
35
/**
46
* EtherScan - API Descriptions
57
* https://etherscan.io/apis#tokens
@@ -9,4 +11,9 @@
911
*/
1012
public interface ITokenProvider {
1113

14+
/** ERC20 Total Supply */
15+
BigInteger supply(String contract);
16+
17+
/** ERC20 token balance for address */
18+
BigInteger balance(String address, String contract);
1219
}

src/main/java/io/api/core/impl/AccountProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.api.util.BasicUtils;
99
import org.jetbrains.annotations.NotNull;
1010

11+
import java.math.BigInteger;
1112
import java.util.ArrayList;
1213
import java.util.Collections;
1314
import java.util.List;
@@ -61,7 +62,7 @@ public Balance balance(final String address) {
6162
if (response.getStatus() != 1)
6263
throw new EtherScanException(response.getMessage() + ", with status " + response.getStatus());
6364

64-
return new Balance(address, Long.valueOf(response.getResult()));
65+
return new Balance(address, new BigInteger(response.getResult()));
6566
}
6667

6768
@NotNull
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class BlockProvider {
13+
public class BlockProvider extends BasicProvider {
1014

15+
public BlockProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class LogsProvider {
13+
public class LogsProvider extends BasicProvider {
1014

15+
public LogsProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class ParityProvider {
13+
public class ParityProvider extends BasicProvider {
1014

15+
public ParityProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class StatisticProvider {
13+
public class StatisticProvider extends BasicProvider {
1014

15+
public StatisticProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class TokenProvider {
13+
public class TokenProvider extends BasicProvider {
1014

15+
public TokenProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.api.core.impl;
22

3+
import io.api.manager.IQueueManager;
4+
5+
import java.util.Map;
6+
37
/**
48
* ! NO DESCRIPTION !
59
*
610
* @author GoodforGod
711
* @since 28.10.2018
812
*/
9-
public class TransactionProvider {
13+
public class TransactionProvider extends BasicProvider {
1014

15+
public TransactionProvider(final IQueueManager queue,
16+
final String baseUrl,
17+
final Map<String, String> headers) {
18+
super(queue, "", baseUrl, headers);
19+
}
1120
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.api.error;
2+
3+
/**
4+
* ! NO DESCRIPTION !
5+
*
6+
* @author GoodforGod
7+
* @since 31.10.2018
8+
*/
9+
public class LogQueryException extends ApiException {
10+
11+
public LogQueryException(String message) {
12+
super(message);
13+
}
14+
}

src/main/java/io/api/model/Balance.java

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

33
import io.api.model.temporary.BalanceTO;
44

5+
import java.math.BigInteger;
6+
57
/**
68
* ! NO DESCRIPTION !
79
*
@@ -11,42 +13,42 @@
1113
public class Balance {
1214

1315
/** Balance in Wei */
14-
private final long balance;
16+
private final Wei balance;
1517
private final String address;
1618

1719
public Balance(final String address,
18-
final long balance) {
20+
final BigInteger balance) {
1921
this.address = address;
20-
this.balance = balance;
22+
this.balance = new Wei(balance);
2123
}
2224

2325
public static Balance of(BalanceTO balance) {
24-
return new Balance(balance.getAccount(), Long.valueOf(balance.getBalance()));
26+
return new Balance(balance.getAccount(), new BigInteger(balance.getBalance()));
2527
}
2628

2729
//<editor-fold desc="Getters">
2830
public String getAddress() {
2931
return address;
3032
}
3133

32-
public long getWei() {
33-
return balance;
34+
public BigInteger getWei() {
35+
return balance.getValue();
3436
}
3537

36-
public double getKwei() {
37-
return balance / 1000;
38+
public BigInteger getKwei() {
39+
return balance.getKwei();
3840
}
3941

40-
public double getMwei() {
41-
return balance / 1000000;
42+
public BigInteger getMwei() {
43+
return balance.getMwei();
4244
}
4345

44-
public double getGwei() {
45-
return balance / 1000000000;
46+
public BigInteger getGwei() {
47+
return balance.getGwei();
4648
}
4749

48-
public double getEther() {
49-
return balance / 1000000000000000L;
50+
public BigInteger getEther() {
51+
return balance.getEther();
5052
}
5153
//</editor-fold>
5254

@@ -57,17 +59,14 @@ public boolean equals(Object o) {
5759

5860
Balance balance1 = (Balance) o;
5961

60-
if (Double.compare(balance1.balance, balance) != 0) return false;
61-
return address.equals(balance1.address);
62+
if (!balance.equals(balance1.balance)) return false;
63+
return address != null ? address.equals(balance1.address) : balance1.address == null;
6264
}
6365

6466
@Override
6567
public int hashCode() {
66-
int result;
67-
long temp;
68-
result = address.hashCode();
69-
temp = Double.doubleToLongBits(balance);
70-
result = 31 * result + (int) (temp ^ (temp >>> 32));
68+
int result = balance.hashCode();
69+
result = 31 * result + (address != null ? address.hashCode() : 0);
7170
return result;
7271
}
7372

0 commit comments

Comments
 (0)