-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathTransactionAPIProvider.java
59 lines (48 loc) · 2.26 KB
/
TransactionAPIProvider.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
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.http.EthHttpClient;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.model.Status;
import io.goodforgod.api.etherscan.model.response.ReceiptStatusResponseTO;
import io.goodforgod.api.etherscan.model.response.StatusResponseTO;
import io.goodforgod.api.etherscan.util.BasicUtils;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
/**
* Transaction API Implementation
*
* @author GoodforGod
* @see TransactionAPI
* @since 28.10.2018
*/
final class TransactionAPIProvider extends BasicProvider implements TransactionAPI {
private static final String ACT_EXEC_STATUS_PARAM = ACT_PREFIX + "getstatus";
private static final String ACT_RECEIPT_STATUS_PARAM = ACT_PREFIX + "gettxreceiptstatus";
private static final String TXHASH_PARAM = "&txhash=";
TransactionAPIProvider(RequestQueueManager queue,
String baseUrl,
EthHttpClient executor,
Converter converter) {
super(queue, "transaction", baseUrl, executor, converter);
}
@NotNull
@Override
public Optional<Status> statusExec(@NotNull String txhash) throws EtherScanException {
BasicUtils.validateTxHash(txhash);
final String urlParams = ACT_EXEC_STATUS_PARAM + TXHASH_PARAM + txhash;
final StatusResponseTO response = getRequest(urlParams, StatusResponseTO.class);
BasicUtils.validateTxResponse(response);
return Optional.ofNullable(response.getResult());
}
@NotNull
@Override
public Optional<Boolean> statusReceipt(@NotNull String txhash) throws EtherScanException {
BasicUtils.validateTxHash(txhash);
final String urlParams = ACT_RECEIPT_STATUS_PARAM + TXHASH_PARAM + txhash;
final ReceiptStatusResponseTO response = getRequest(urlParams, ReceiptStatusResponseTO.class);
BasicUtils.validateTxResponse(response);
return (response.getResult() == null || BasicUtils.isEmpty(response.getResult().getStatus()))
? Optional.empty()
: Optional.of(response.getResult().getStatus().contains("1"));
}
}