-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathContractAPIProvider.java
47 lines (39 loc) · 1.68 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
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.response.StringResponseTO;
import io.goodforgod.api.etherscan.util.BasicUtils;
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=";
ContractAPIProvider(RequestQueueManager requestQueueManager,
String baseUrl,
EthHttpClient executor,
Converter converter) {
super(requestQueueManager, "contract", baseUrl, executor, converter);
}
@NotNull
@Override
public Abi contractAbi(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());
}
}