-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathApiRunner.java
66 lines (53 loc) · 2.17 KB
/
ApiRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.manager.impl.SemaphoreRequestQueueManager;
import java.time.Duration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
public class ApiRunner extends Assertions {
private static final String DEFAULT_KEY = "YourApiKeyToken";
private static final EtherScanAPI api;
private static final EtherScanAPI apiRopsten;
private static final EtherScanAPI apiRinkeby;
private static final EtherScanAPI apiKovan;
private static final String apiKey;
static {
final String key = System.getenv("API_KEY");
apiKey = (key == null || key.isEmpty())
? DEFAULT_KEY
: key;
final RequestQueueManager queueManager = (DEFAULT_KEY.equals(apiKey))
? RequestQueueManager.DEFAULT_KEY_QUEUE
: new SemaphoreRequestQueueManager(1, Duration.ofMillis(1200L), Duration.ofMillis(1200L), 0);
api = EtherScanAPI.builder().withApiKey(ApiRunner.apiKey).withNetwork(EthNetworks.MAINNET).withQueue(queueManager)
.build();
apiKovan = EtherScanAPI.builder().withApiKey(ApiRunner.apiKey).withNetwork(EthNetworks.KOVAN).withQueue(queueManager)
.build();
apiRopsten = EtherScanAPI.builder().withApiKey(ApiRunner.apiKey).withNetwork(EthNetworks.ROPSTEN).withQueue(queueManager)
.build();
apiRinkeby = EtherScanAPI.builder().withApiKey(ApiRunner.apiKey).withNetwork(EthNetworks.RINKEBY).withQueue(queueManager)
.build();
}
public static String getApiKey() {
return apiKey;
}
public static EtherScanAPI getApi() {
return api;
}
public static EtherScanAPI getApiRopsten() {
return apiRopsten;
}
public static EtherScanAPI getApiRinkeby() {
return apiRinkeby;
}
public static EtherScanAPI getApiKovan() {
return apiKovan;
}
@AfterAll
public static void cleanup() throws Exception {
api.close();
apiRopsten.close();
apiRinkeby.close();
apiKovan.close();
}
}