-
Notifications
You must be signed in to change notification settings - Fork 34
/
NotifyTransactionExpiredHandler.java
83 lines (74 loc) · 3.04 KB
/
NotifyTransactionExpiredHandler.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
79
80
81
82
83
package org.stellar.anchor.platform.rpc;
import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.stellar.anchor.api.platform.PlatformTransactionData.Sep.SEP_24;
import static org.stellar.anchor.api.platform.PlatformTransactionData.Sep.SEP_31;
import static org.stellar.anchor.api.platform.PlatformTransactionData.Sep.SEP_6;
import static org.stellar.anchor.api.rpc.method.RpcMethod.NOTIFY_TRANSACTION_EXPIRED;
import static org.stellar.anchor.api.sep.SepTransactionStatus.EXPIRED;
import java.util.Arrays;
import java.util.Set;
import org.stellar.anchor.api.platform.PlatformTransactionData.Sep;
import org.stellar.anchor.api.rpc.method.NotifyTransactionExpiredRequest;
import org.stellar.anchor.api.rpc.method.RpcMethod;
import org.stellar.anchor.api.sep.SepTransactionStatus;
import org.stellar.anchor.asset.AssetService;
import org.stellar.anchor.event.EventService;
import org.stellar.anchor.metrics.MetricsService;
import org.stellar.anchor.platform.data.JdbcSepTransaction;
import org.stellar.anchor.platform.data.JdbcTransactionPendingTrustRepo;
import org.stellar.anchor.platform.validator.RequestValidator;
import org.stellar.anchor.sep24.Sep24TransactionStore;
import org.stellar.anchor.sep31.Sep31TransactionStore;
import org.stellar.anchor.sep6.Sep6TransactionStore;
public class NotifyTransactionExpiredHandler
extends RpcMethodHandler<NotifyTransactionExpiredRequest> {
private final JdbcTransactionPendingTrustRepo transactionPendingTrustRepo;
public NotifyTransactionExpiredHandler(
Sep6TransactionStore txn6Store,
Sep24TransactionStore txn24Store,
Sep31TransactionStore txn31Store,
RequestValidator requestValidator,
AssetService assetService,
EventService eventService,
MetricsService metricsService,
JdbcTransactionPendingTrustRepo transactionPendingTrustRepo) {
super(
txn6Store,
txn24Store,
txn31Store,
requestValidator,
assetService,
eventService,
metricsService,
NotifyTransactionExpiredRequest.class);
this.transactionPendingTrustRepo = transactionPendingTrustRepo;
}
@Override
public RpcMethod getRpcMethod() {
return NOTIFY_TRANSACTION_EXPIRED;
}
@Override
protected SepTransactionStatus getNextStatus(
JdbcSepTransaction txn, NotifyTransactionExpiredRequest request) {
return EXPIRED;
}
@Override
protected Set<SepTransactionStatus> getSupportedStatuses(JdbcSepTransaction txn) {
if (Set.of(SEP_6, SEP_24, SEP_31).contains(Sep.from(txn.getProtocol()))) {
if (!areFundsReceived(txn)) {
return Arrays.stream(SepTransactionStatus.values())
.filter(s -> !isErrorStatus(s) && !isFinalStatus(s))
.collect(toSet());
}
}
return emptySet();
}
@Override
protected void updateTransactionWithRpcRequest(
JdbcSepTransaction txn, NotifyTransactionExpiredRequest request) {
if (transactionPendingTrustRepo.existsById(txn.getId())) {
transactionPendingTrustRepo.deleteById(txn.getId());
}
}
}