Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1416a23

Browse files
committed
[2.0.0-SNAPSHOT]
RequestQueueManager static consts -> static method to produce uniq request queue managersTests manager provision fixed
1 parent6d19b73 commit1416a23

File tree

11 files changed

+69
-60
lines changed

11 files changed

+69
-60
lines changed

‎src/main/java/io/goodforgod/api/etherscan/AccountAPIProvider.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public TokenBalance balance(String address, String contract) throws EtherScanExc
8484
@NotNull
8585
@Override
8686
publicList<Balance>balances(List<String>addresses)throwsEtherScanException {
87-
if (BasicUtils.isEmpty(addresses))
87+
if (BasicUtils.isEmpty(addresses)) {
8888
returnCollections.emptyList();
89+
}
8990

9091
BasicUtils.validateAddresses(addresses);
9192

@@ -96,13 +97,15 @@ public List<Balance> balances(List<String> addresses) throws EtherScanException
9697
for (finalList<String>batch :addressesAsBatches) {
9798
finalStringurlParams =ACT_BALANCE_MULTI_ACTION +TAG_LATEST_PARAM +ADDRESS_PARAM +toAddressParam(batch);
9899
finalBalanceResponseTOresponse =getRequest(urlParams,BalanceResponseTO.class);
99-
if (response.getStatus() !=1)
100+
if (response.getStatus() !=1) {
100101
thrownewEtherScanResponseException(response);
102+
}
101103

102-
if (!BasicUtils.isEmpty(response.getResult()))
104+
if (!BasicUtils.isEmpty(response.getResult())) {
103105
balances.addAll(response.getResult().stream()
104106
.map(r ->newBalance(r.getAccount(),Wei.ofWei(newBigInteger(r.getBalance()))))
105107
.collect(Collectors.toList()));
108+
}
106109
}
107110

108111
returnbalances;

‎src/main/java/io/goodforgod/api/etherscan/EthScanAPIBuilder.java‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ final class EthScanAPIBuilder implements EtherScanAPI.Builder {
2727
privatefinalGsongson =newGsonConfiguration().builder().create();
2828

2929
privateStringapiKey =DEFAULT_KEY;
30+
privateRequestQueueManagerqueueManager;
3031
privateEthNetworkethNetwork =EthNetworks.MAINNET;
31-
privateRequestQueueManagerqueueManager =RequestQueueManager.ANONYMOUS;
3232
privateSupplier<EthHttpClient>ethHttpClientSupplier =DEFAULT_SUPPLIER;
3333
privateSupplier<Converter>converterSupplier = () ->newConverter() {
3434

@@ -49,9 +49,6 @@ public EtherScanAPI.Builder withApiKey(@NotNull String apiKey) {
4949
thrownewEtherScanKeyException("API key can not be null or empty");
5050

5151
this.apiKey =apiKey;
52-
if (!DEFAULT_KEY.equals(apiKey)) {
53-
queueManager =RequestQueueManager.UNLIMITED;
54-
}
5552
returnthis;
5653
}
5754

@@ -92,6 +89,16 @@ public EtherScanAPI.Builder withConverter(@NotNull Supplier<Converter> converter
9289

9390
@Override
9491
public@NotNullEtherScanAPIbuild() {
95-
returnnewEtherScanAPIProvider(apiKey,ethNetwork,queueManager,ethHttpClientSupplier.get(),converterSupplier.get());
92+
RequestQueueManagerrequestQueueManager;
93+
if (queueManager !=null) {
94+
requestQueueManager =queueManager;
95+
}elseif (DEFAULT_KEY.equals(apiKey)) {
96+
requestQueueManager =RequestQueueManager.anonymous();
97+
}else {
98+
requestQueueManager =RequestQueueManager.planFree();
99+
}
100+
101+
returnnewEtherScanAPIProvider(apiKey,ethNetwork,requestQueueManager,ethHttpClientSupplier.get(),
102+
converterSupplier.get());
96103
}
97104
}

‎src/main/java/io/goodforgod/api/etherscan/manager/RequestQueueManager.java‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,33 @@ public interface RequestQueueManager extends AutoCloseable {
1616
/**
1717
* Is used by default when no API KEY is provided
1818
*/
19-
RequestQueueManagerANONYMOUS =newSemaphoreRequestQueueManager(1,Duration.ofMillis(5015L));
19+
staticRequestQueueManageranonymous() {
20+
returnnewSemaphoreRequestQueueManager(1,Duration.ofMillis(5005L));
21+
}
2022

2123
/**
2224
* Is available for all registered free API KEYs
2325
* <a href="https://docs.etherscan.io/getting-started/viewing-api-usage-statistics">Free API KEY</a>
2426
*/
25-
RequestQueueManagerFREE_PLAN =newSemaphoreRequestQueueManager(5,Duration.ofMillis(1015L));
26-
RequestQueueManagerSTANDARD_PLAN =newSemaphoreRequestQueueManager(10,Duration.ofMillis(1015L));
27-
RequestQueueManagerADVANCED_PLAN =newSemaphoreRequestQueueManager(20,Duration.ofMillis(1015L));
28-
RequestQueueManagerPROFESSIONAL_PLAN =newSemaphoreRequestQueueManager(30,Duration.ofMillis(1015L));
27+
staticRequestQueueManagerplanFree() {
28+
returnnewSemaphoreRequestQueueManager(5,Duration.ofMillis(1005L));
29+
}
2930

30-
RequestQueueManagerUNLIMITED =newFakeRequestQueueManager();
31+
staticRequestQueueManagerplanStandard() {
32+
returnnewSemaphoreRequestQueueManager(10,Duration.ofMillis(1005L));
33+
}
34+
35+
staticRequestQueueManagerplanAdvanced() {
36+
returnnewSemaphoreRequestQueueManager(20,Duration.ofMillis(1005L));
37+
}
38+
39+
staticRequestQueueManagerplanProfessional() {
40+
returnnewSemaphoreRequestQueueManager(30,Duration.ofMillis(1005L));
41+
}
42+
43+
staticRequestQueueManagerunlimited() {
44+
returnnewFakeRequestQueueManager();
45+
}
3146

3247
/**
3348
* Waits in queue for chance to take turn

‎src/test/java/io/goodforgod/api/etherscan/ApiRunner.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class ApiRunner extends Assertions {
2020
.orElse(DEFAULT_KEY);
2121

2222
finalRequestQueueManagerqueueManager = (DEFAULT_KEY.equals(API_KEY))
23-
?RequestQueueManager.ANONYMOUS
24-
:RequestQueueManager.FREE_PLAN;
23+
?RequestQueueManager.anonymous()
24+
:RequestQueueManager.planFree();
2525

2626
API =EtherScanAPI.builder()
2727
.withApiKey(ApiRunner.API_KEY)
@@ -30,10 +30,6 @@ public class ApiRunner extends Assertions {
3030
.build();
3131
}
3232

33-
publicstaticStringgetApiKey() {
34-
returnAPI_KEY;
35-
}
36-
3733
publicstaticEtherScanAPIgetApi() {
3834
returnAPI;
3935
}

‎src/test/java/io/goodforgod/api/etherscan/EtherScanAPITests.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ void timeout() throws InterruptedException {
6868
TimeUnit.SECONDS.sleep(5);
6969
Supplier<EthHttpClient>supplier = () ->newUrlEthHttpClient(Duration.ofMillis(300),Duration.ofMillis(300));
7070
EtherScanAPIapi =EtherScanAPI.builder()
71-
.withApiKey(getApiKey())
7271
.withNetwork(() ->URI.create("https://api-unknown.etherscan.io/api"))
7372
.withHttpClient(supplier)
7473
.build();

‎src/test/java/io/goodforgod/api/etherscan/account/AccountTxErc20Tests.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void correct() {
1818
assertNotNull(txs);
1919
assertEquals(3,txs.size());
2020
assertTxs(txs);
21-
assertNotEquals(0,txs.get(0).getGasPrice());
21+
assertNotEquals(0,txs.get(0).getGasPrice().asWei().intValue());
2222
assertNotEquals(-1,txs.get(0).getNonce());
2323

2424
assertNotNull(txs.get(0).toString());
@@ -71,7 +71,7 @@ private void assertTxs(List<TxErc20> txs) {
7171
assertNotNull(tx.getTokenDecimal());
7272
assertNotEquals(-1, (tx.getConfirmations()));
7373
assertNotNull(tx.getGasUsed());
74-
assertNotEquals(-1,tx.getCumulativeGasUsed());
74+
assertNotEquals(-1,tx.getGasUsedCumulative());
7575
assertNotEquals(-1,tx.getTransactionIndex());
7676
}
7777
}

‎src/test/java/io/goodforgod/api/etherscan/account/AccountTxRc1155TokenTests.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void asserTx(TxErc1155 tx) {
7575
assertNotNull(tx.getTokenValue());
7676
assertNotEquals(-1, (tx.getConfirmations()));
7777
assertNotNull(tx.getGasUsed());
78-
assertNotEquals(-1,tx.getCumulativeGasUsed());
78+
assertNotEquals(-1,tx.getGasUsedCumulative());
7979
assertNotEquals(-1,tx.getTransactionIndex());
8080
}
8181
}

‎src/test/java/io/goodforgod/api/etherscan/account/AccountTxRc721TokenTests.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void assertTxs(List<TxErc721> txs) {
7373
assertNotNull(tx.getTokenDecimal());
7474
assertNotEquals(-1, (tx.getConfirmations()));
7575
assertNotNull(tx.getGasUsed());
76-
assertNotEquals(-1,tx.getCumulativeGasUsed());
76+
assertNotEquals(-1,tx.getGasUsedCumulative());
7777
assertNotEquals(-1,tx.getTransactionIndex());
7878
}
7979
}

‎src/test/java/io/goodforgod/api/etherscan/account/AccountTxsTests.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void correct() {
2424
assertNotNull(txs.get(0).getTo());
2525
assertNotNull(txs.get(0).getBlockHash());
2626
assertNotNull(txs.get(0).getGas());
27-
assertNotNull(txs.get(0).getCumulativeGasUsed());
27+
assertNotNull(txs.get(0).getGasUsedCumulative());
2828
assertNotNull(txs.get(0).getGasPrice());
2929
assertNotNull(txs.get(0).getValue());
3030
assertNotNull(txs.get(0).getContractAddress());
@@ -75,7 +75,7 @@ private void assertTxs(List<Tx> txs) {
7575
assertNotEquals(-1, (tx.getNonce()));
7676
assertNotEquals(0, (tx.getTransactionIndex()));
7777
assertNotEquals(0,tx.getConfirmations());
78-
assertNotNull(tx.getTxreceipt_status());
78+
assertNotNull(tx.getTxReceiptStatus());
7979
}
8080
}
8181
}

‎src/test/java/io/goodforgod/api/etherscan/model/ModelBuilderTests.java‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ void txBuilder() {
132132
.withBlockNumber(1L)
133133
.withConfirmations(1L)
134134
.withContractAddress("1")
135-
.withCumulativeGasUsed(BigInteger.ONE)
136135
.withFrom("1")
137136
.withTo("1")
138-
.withGas(BigInteger.ONE)
139-
.withGasPrice(BigInteger.ONE)
140-
.withGasUsed(BigInteger.ONE)
137+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
138+
.withGas(Wei.ofWei(BigInteger.ONE))
139+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
140+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
141141
.withHash("1")
142142
.withInput("1")
143143
.withIsError("1")
144144
.withNonce(1L)
145145
.withTimeStamp(timestamp)
146146
.withValue(BigInteger.ONE)
147147
.withTransactionIndex(1)
148-
.withTxreceiptStatus("1")
148+
.withTxReceiptStatus("1")
149149
.build();
150150

151151
assertNotNull(value);
@@ -162,12 +162,12 @@ void txErc20Builder() {
162162
.withBlockNumber(1L)
163163
.withConfirmations(1L)
164164
.withContractAddress("1")
165-
.withCumulativeGasUsed(BigInteger.ONE)
166165
.withFrom("1")
167166
.withTo("1")
168-
.withGas(BigInteger.ONE)
169-
.withGasPrice(BigInteger.ONE)
170-
.withGasUsed(BigInteger.ONE)
167+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
168+
.withGas(Wei.ofWei(BigInteger.ONE))
169+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
170+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
171171
.withHash("1")
172172
.withInput("1")
173173
.withTokenName("1")
@@ -192,12 +192,12 @@ void txErc721Builder() {
192192
.withBlockNumber(1L)
193193
.withConfirmations(1L)
194194
.withContractAddress("1")
195-
.withCumulativeGasUsed(BigInteger.ONE)
196195
.withFrom("1")
197196
.withTo("1")
198-
.withGas(BigInteger.ONE)
199-
.withGasPrice(BigInteger.ONE)
200-
.withGasUsed(BigInteger.ONE)
197+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
198+
.withGas(Wei.ofWei(BigInteger.ONE))
199+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
200+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
201201
.withHash("1")
202202
.withInput("1")
203203
.withTokenName("1")
@@ -222,12 +222,12 @@ void txErc1155Builder() {
222222
.withBlockNumber(1L)
223223
.withConfirmations(1L)
224224
.withContractAddress("1")
225-
.withCumulativeGasUsed(BigInteger.ONE)
226225
.withFrom("1")
227226
.withTo("1")
228-
.withGas(BigInteger.ONE)
229-
.withGasPrice(BigInteger.ONE)
230-
.withGasUsed(BigInteger.ONE)
227+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
228+
.withGas(Wei.ofWei(BigInteger.ONE))
229+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
230+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
231231
.withHash("1")
232232
.withInput("1")
233233
.withTokenName("1")
@@ -253,8 +253,8 @@ void txInternalBuilder() {
253253
.withFrom("1")
254254
.withTo("1")
255255
.withValue(BigInteger.ONE)
256-
.withGas(BigInteger.ONE)
257-
.withGasUsed(BigInteger.ONE)
256+
.withGas(Wei.ofWei(BigInteger.ONE))
257+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
258258
.withHash("1")
259259
.withInput("1")
260260
.withTimeStamp(timestamp)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp