-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathContractAPIProvider.java
78 lines (65 loc) · 3.17 KB
/
ContractAPIProvider.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
67
68
69
70
71
72
73
74
75
76
77
78
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
import io.goodforgod.api.etherscan.http.EthHttpClient;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.model.Abi;
import io.goodforgod.api.etherscan.model.ContractCreation;
import io.goodforgod.api.etherscan.model.response.ContractCreationResponseTO;
import io.goodforgod.api.etherscan.model.response.StringResponseTO;
import io.goodforgod.api.etherscan.util.BasicUtils;
import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
/**
* Contract API Implementation
*
* @see ContractAPI
* @author GoodforGod
* @since 28.10.2018
*/
final class ContractAPIProvider extends BasicProvider implements ContractAPI {
private static final String ACT_ABI_PARAM = ACT_PREFIX + "getabi";
private static final String ADDRESS_PARAM = "&address=";
private static final String ACT_CONTRACT_CREATION_PARAM = "getcontractcreation";
private static final String ACT_CONTRACT_CREATION = ACT_PREFIX + ACT_CONTRACT_CREATION_PARAM;
private static final String ACT_CONTRACT_ADDRESSES_PARAM = "&contractaddresses=";
ContractAPIProvider(RequestQueueManager requestQueueManager,
String baseUrl,
EthHttpClient executor,
Converter converter,
int retryCount) {
super(requestQueueManager, "contract", baseUrl, executor, converter, retryCount);
}
@NotNull
@Override
public Abi contractAbi(@NotNull String address) throws EtherScanException {
BasicUtils.validateAddress(address);
final String urlParam = ACT_ABI_PARAM + ADDRESS_PARAM + address;
final StringResponseTO response = getRequest(urlParam, StringResponseTO.class);
if (response.getStatus() != 1 && response.getMessage().startsWith("NOTOK")) {
throw new EtherScanResponseException(response);
}
return (response.getResult().startsWith("Contract sou"))
? Abi.nonVerified()
: Abi.verified(response.getResult());
}
@NotNull
@Override
public List<ContractCreation> contractCreation(@NotNull List<String> contractAddresses) throws EtherScanException {
BasicUtils.validateAddresses(contractAddresses);
final String urlParam = ACT_CONTRACT_CREATION + ACT_CONTRACT_ADDRESSES_PARAM
+ BasicUtils.toAddressParam(contractAddresses);
final ContractCreationResponseTO response = getRequest(urlParam, ContractCreationResponseTO.class);
if (response.getStatus() != 1 && response.getMessage().startsWith("NOTOK")) {
throw new EtherScanResponseException(response);
}
return response.getResult().stream()
.map(to -> ContractCreation.builder()
.withContractCreator(to.getContractCreator())
.withContractAddress(to.getContractAddress())
.withTxHash(to.getTxHash())
.build())
.collect(Collectors.toList());
}
}