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

Commit4ee5873

Browse files
committed
Test for most functionality implemented
Providers improvements & fixesFake queue managerBasic Utils fixes
1 parent555f7d4 commit4ee5873

File tree

39 files changed

+1200
-63
lines changed

39 files changed

+1200
-63
lines changed

‎src/main/java/io/api/etherscan/App.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
*/
1212
publicclassApp {
1313
publicstaticvoidmain(String[]args) {
14-
EtherScanApiapi =newEtherScanApi(args[0]);
14+
EtherScanApiapi =newEtherScanApi();
1515
Balancebalance =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
16+
Balancebalance1 =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
17+
Balancebalance2 =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
18+
Balancebalance3 =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
19+
Balancebalance4 =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
20+
Balancebalance5 =api.account().balance("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
1621
List<Tx>txs =api.account().txs("0x8d4426f94e42f721C7116E81d6688cd935cB3b4F");
1722
List<TxToken>txTokens =api.account().txsToken("0xf261B3A60Ef40eE0B369B0705c1a2c58B02799DF");
1823
List<TxInternal>txInternals =api.account().txsInternal("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3");
1924
Optional<UncleBlock>uncles =api.block().uncles(2165403);
20-
Optional<UncleBlock>uncleBlock =api.block().uncles(999965403);
25+
Optional<UncleBlock>uncleEmpty =api.block().uncles(999965403);
2126
System.out.println("Test");
2227
}
2328
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface IProxyApi {
7070
* Returns the receipt of a transaction by transaction hash
7171
* eth_getTransactionReceipt
7272
*/
73-
@NotNullOptional<TxInfoProxy>txReceipt(Stringtxhash);
73+
@NotNullOptional<TxInfoProxy>txReceipt(Stringtxhash)throwsApiException;
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/BasicProvider.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ abstract class BasicProvider {
3838
this.gson =newGson();
3939
}
4040

41-
private<T>Tconvert(finalStringjson,finalClass<T>tClass) {
41+
<T>Tconvert(finalStringjson,finalClass<T>tClass) {
4242
try {
4343
returngson.fromJson(json,tClass);
4444
}catch (Exceptione) {
4545
thrownewParseException(e.getMessage(),e.getCause());
4646
}
4747
}
4848

49-
privateStringgetRequest(finalStringurlParameters) {
49+
StringgetRequest(finalStringurlParameters) {
5050
queue.takeTurn();
5151
finalStringurl =baseUrl +module +urlParameters;
5252
finalStringresult =executor.get(url);
@@ -56,7 +56,7 @@ private String getRequest(final String urlParameters) {
5656
returnresult;
5757
}
5858

59-
privateStringpostRequest(finalStringurlParameters,finalStringdataToPost) {
59+
StringpostRequest(finalStringurlParameters,finalStringdataToPost) {
6060
queue.takeTurn();
6161
finalStringurl =baseUrl +module +urlParameters;
6262
returnexecutor.post(url,dataToPost);

‎src/main/java/io/api/etherscan/core/impl/BlockApiProvider.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.api.etherscan.core.impl;
22

33
importio.api.etherscan.core.IBlockApi;
4+
importio.api.etherscan.error.ApiException;
45
importio.api.etherscan.executor.IHttpExecutor;
56
importio.api.etherscan.manager.IQueueManager;
67
importio.api.etherscan.model.UncleBlock;
@@ -27,19 +28,21 @@ public class BlockApiProvider extends BasicProvider implements IBlockApi {
2728
BlockApiProvider(finalIQueueManagerqueueManager,
2829
finalStringbaseUrl,
2930
finalIHttpExecutorexecutor) {
30-
super(queueManager,"blockUncle",baseUrl,executor);
31+
super(queueManager,"block",baseUrl,executor);
3132
}
3233

3334
@NotNull
3435
@Override
35-
publicOptional<UncleBlock>uncles(longblockNumber) {
36+
publicOptional<UncleBlock>uncles(longblockNumber)throwsApiException{
3637
finalStringurlParam =ACT_BLOCK_PARAM +BLOCKNO_PARAM +blockNumber;
37-
finalUncleBlockResponseTOresponse =getRequest(urlParam,UncleBlockResponseTO.class);
38+
finalStringresponse =getRequest(urlParam);
39+
if(BasicUtils.isEmpty(response) ||response.contains("NOTOK"))
40+
returnOptional.empty();
3841

39-
BasicUtils.validateTxResponse(response);
40-
41-
return (response.getResult() ==null ||response.getResult().isEmpty())
42+
finalUncleBlockResponseTOresponseTO =convert(response,UncleBlockResponseTO.class);
43+
BasicUtils.validateTxResponse(responseTO);
44+
return (responseTO.getResult() ==null ||responseTO.getResult().isEmpty())
4245
?Optional.empty()
43-
:Optional.of(response.getResult());
46+
:Optional.of(responseTO.getResult());
4447
}
4548
}

‎src/main/java/io/api/etherscan/core/impl/ContractApiProvider.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.api.etherscan.core.impl;
22

33
importio.api.etherscan.core.IContractApi;
4+
importio.api.etherscan.error.ApiException;
45
importio.api.etherscan.error.EtherScanException;
56
importio.api.etherscan.executor.IHttpExecutor;
67
importio.api.etherscan.manager.IQueueManager;
@@ -31,7 +32,7 @@ public class ContractApiProvider extends BasicProvider implements IContractApi {
3132

3233
@NotNull
3334
@Override
34-
publicAbicontractAbi(finalStringaddress) {
35+
publicAbicontractAbi(finalStringaddress)throwsApiException{
3536
BasicUtils.validateAddress(address);
3637

3738
finalStringurlParam =ACT_ABI_PARAM +ADDRESS_PARAM +address;

‎src/main/java/io/api/etherscan/core/impl/EtherScanApi.java‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
importio.api.etherscan.executor.IHttpExecutor;
55
importio.api.etherscan.executor.impl.HttpExecutor;
66
importio.api.etherscan.manager.IQueueManager;
7+
importio.api.etherscan.manager.impl.FakeQueueManager;
78
importio.api.etherscan.manager.impl.QueueManager;
89
importio.api.etherscan.model.EthNetwork;
10+
importio.api.etherscan.util.BasicUtils;
911

1012
importjava.util.function.Supplier;
1113

@@ -28,6 +30,14 @@ public class EtherScanApi {
2830
privatefinalIStatisticApistats;
2931
privatefinalITransactionApitxs;
3032

33+
publicEtherScanApi() {
34+
this("YourApiKeyToken",EthNetwork.MAINNET);
35+
}
36+
37+
publicEtherScanApi(finalEthNetworknetwork) {
38+
this("YourApiKeyToken",network);
39+
}
40+
3141
publicEtherScanApi(finalStringapiKey) {
3242
this(apiKey,EthNetwork.MAINNET);
3343
}
@@ -40,20 +50,25 @@ public EtherScanApi(final String apiKey,
4050
publicEtherScanApi(finalStringapiKey,
4151
finalEthNetworknetwork,
4252
finalSupplier<IHttpExecutor>executorSupplier) {
53+
if (BasicUtils.isEmpty(apiKey))
54+
thrownewNullPointerException("API key can not be null");
55+
4356
// EtherScan 5request\sec limit support by queue manager
44-
finalIQueueManagermasterQueue =newQueueManager(5,1);
45-
finalIHttpExecutorexecutor =executorSupplier.get();
57+
finalIQueueManagermasterQueue = (apiKey.equals("YourApiKeyToken"))
58+
?newFakeQueueManager()
59+
:newQueueManager(5,1);
4660

61+
finalIHttpExecutorexecutor =executorSupplier.get();
4762
finalEthNetworkusedNetwork = (network ==null) ?EthNetwork.MAINNET :network;
4863
finalStringbaseUrl ="https://" +usedNetwork.getDomain() +".etherscan.io/api" +"?apikey=" +apiKey;
4964

5065
this.account =newAccountApiProvider(masterQueue,baseUrl,executor);
51-
this.block=newBlockApiProvider(masterQueue,baseUrl,executor);
66+
this.block =newBlockApiProvider(masterQueue,baseUrl,executor);
5267
this.contract =newContractApiProvider(masterQueue,baseUrl,executor);
53-
this.logs=newLogsApiProvider(masterQueue,baseUrl,executor);
54-
this.proxy=newProxyApiProvider(masterQueue,baseUrl,executor);
55-
this.stats=newStatisticApiProvider(masterQueue,baseUrl,executor);
56-
this.txs=newTransactionApiProvider(masterQueue,baseUrl,executor);
68+
this.logs =newLogsApiProvider(masterQueue,baseUrl,executor);
69+
this.proxy =newProxyApiProvider(masterQueue,baseUrl,executor);
70+
this.stats =newStatisticApiProvider(masterQueue,baseUrl,executor);
71+
this.txs =newTransactionApiProvider(masterQueue,baseUrl,executor);
5772
}
5873

5974
publicIContractApicontract() {

‎src/main/java/io/api/etherscan/core/impl/LogsApiProvider.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.api.etherscan.core.impl;
22

33
importio.api.etherscan.core.ILogsApi;
4+
importio.api.etherscan.error.ApiException;
45
importio.api.etherscan.executor.IHttpExecutor;
56
importio.api.etherscan.manager.IQueueManager;
67
importio.api.etherscan.model.Log;
@@ -32,7 +33,7 @@ public class LogsApiProvider extends BasicProvider implements ILogsApi {
3233

3334
@NotNull
3435
@Override
35-
publicList<Log>logs(finalLogQueryquery) {
36+
publicList<Log>logs(finalLogQueryquery)throwsApiException{
3637
finalStringurlParams =ACT_LOGS_PARAM +query.getParams();
3738
finalLogResponseTOresponse =getRequest(urlParams,LogResponseTO.class);
3839
BasicUtils.validateTxResponse(response);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public Optional<String> txSendRaw(final String hexEncodedTx) throws ApiException
148148

149149
@NotNull
150150
@Override
151-
publicOptional<TxInfoProxy>txReceipt(finalStringtxhash) {
151+
publicOptional<TxInfoProxy>txReceipt(finalStringtxhash)throwsApiException{
152152
BasicUtils.validateTxHash(txhash);
153153

154154
finalStringurlParams =ACT_TX_RECEIPT_PARAM +TXHASH_PARAM +txhash;

‎src/main/java/io/api/etherscan/core/impl/StatisticApiProvider.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.api.etherscan.core.impl;
22

33
importio.api.etherscan.core.IStatisticApi;
4+
importio.api.etherscan.error.ApiException;
45
importio.api.etherscan.error.EtherScanException;
56
importio.api.etherscan.executor.IHttpExecutor;
67
importio.api.etherscan.manager.IQueueManager;
@@ -37,7 +38,7 @@ public class StatisticApiProvider extends BasicProvider implements IStatisticApi
3738

3839
@NotNull
3940
@Override
40-
publicSupplysupply() {
41+
publicSupplysupply()throwsApiException{
4142
finalStringResponseTOresponse =getRequest(ACT_SUPPLY_PARAM,StringResponseTO.class);
4243
if (response.getStatus() !=1)
4344
thrownewEtherScanException(response.getMessage() +", with status " +response.getStatus());
@@ -47,7 +48,7 @@ public Supply supply() {
4748

4849
@NotNull
4950
@Override
50-
publicBigIntegersupply(finalStringcontract) {
51+
publicBigIntegersupply(finalStringcontract)throwsApiException{
5152
BasicUtils.validateAddress(contract);
5253

5354
finalStringurlParams =ACT_TOKEN_SUPPLY_PARAM +CONTRACT_ADDRESS_PARAM +contract;
@@ -60,7 +61,7 @@ public BigInteger supply(final String contract) {
6061

6162
@NotNull
6263
@Override
63-
publicPricelastPrice() {
64+
publicPricelastPrice()throwsApiException{
6465
finalPriceResponseTOresponse =getRequest(ACT_LASTPRICE_PARAM,PriceResponseTO.class);
6566
if (response.getStatus() !=1)
6667
thrownewEtherScanException(response.getMessage() +", with status " +response.getStatus());
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
packageio.api.etherscan.core.impl;
22

33
importio.api.etherscan.core.ITransactionApi;
4+
importio.api.etherscan.error.ApiException;
45
importio.api.etherscan.executor.IHttpExecutor;
56
importio.api.etherscan.manager.IQueueManager;
67
importio.api.etherscan.model.Status;
8+
importio.api.etherscan.model.utility.ReceiptStatusResponseTO;
79
importio.api.etherscan.model.utility.StatusResponseTO;
8-
importio.api.etherscan.model.utility.StringResponseTO;
910
importio.api.etherscan.util.BasicUtils;
1011
importorg.jetbrains.annotations.NotNull;
1112

@@ -14,9 +15,8 @@
1415
/**
1516
* Transaction API Implementation
1617
*
17-
* @see ITransactionApi
18-
*
1918
* @author GoodforGod
19+
* @see ITransactionApi
2020
* @since 28.10.2018
2121
*/
2222
publicclassTransactionApiProviderextendsBasicProviderimplementsITransactionApi {
@@ -34,29 +34,27 @@ public class TransactionApiProvider extends BasicProvider implements ITransactio
3434

3535
@NotNull
3636
@Override
37-
publicOptional<Status>execStatus(finalStringtxhash) {
37+
publicOptional<Status>execStatus(finalStringtxhash)throwsApiException{
3838
BasicUtils.validateTxHash(txhash);
3939

4040
finalStringurlParams =ACT_EXEC_STATUS_PARAM +TXHASH_PARAM +txhash;
4141
finalStatusResponseTOresponse =getRequest(urlParams,StatusResponseTO.class);
4242
BasicUtils.validateTxResponse(response);
4343

44-
return (response.getResult() ==null)
45-
?Optional.empty()
46-
:Optional.of(response.getResult());
44+
returnOptional.ofNullable(response.getResult());
4745
}
4846

4947
@NotNull
5048
@Override
51-
publicOptional<Boolean>receiptStatus(finalStringtxhash) {
49+
publicOptional<Boolean>receiptStatus(finalStringtxhash)throwsApiException{
5250
BasicUtils.validateTxHash(txhash);
5351

5452
finalStringurlParams =ACT_RECEIPT_STATUS_PARAM +TXHASH_PARAM +txhash;
55-
finalStringResponseTOresponse =getRequest(urlParams,StringResponseTO.class);
53+
finalReceiptStatusResponseTOresponse =getRequest(urlParams,ReceiptStatusResponseTO.class);
5654
BasicUtils.validateTxResponse(response);
5755

58-
return (BasicUtils.isEmpty(response.getResult()))
56+
return (response.getResult() ==null ||BasicUtils.isEmpty(response.getResult().getStatus()))
5957
?Optional.empty()
60-
:Optional.of(response.getResult().contains("1"));
58+
:Optional.of(response.getResult().getStatus().contains("1"));
6159
}
6260
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp