Coverage Summary for Class: TransactionPoolAddResult (org.ethereum.core)
Class |
Class, %
|
Method, %
|
Line, %
|
TransactionPoolAddResult |
100%
(1/1)
|
75%
(9/12)
|
81.2%
(13/16)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2019 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package org.ethereum.core;
20
21 import com.google.common.annotations.VisibleForTesting;
22
23 import java.util.Collections;
24 import java.util.List;
25
26 public class TransactionPoolAddResult {
27 private final String errorMessage;
28 private final List<Transaction> queuedTransactionsAdded;
29 private final List<Transaction> pendingTransactionsAdded;
30
31 private TransactionPoolAddResult(String errorMessage, List<Transaction> queuedTransactionsAdded, List<Transaction> pendingTransactionsAdded) {
32 this.errorMessage = errorMessage;
33 this.queuedTransactionsAdded = Collections.unmodifiableList(queuedTransactionsAdded);
34 this.pendingTransactionsAdded = Collections.unmodifiableList(pendingTransactionsAdded);
35 }
36
37 public static TransactionPoolAddResult ok(List<Transaction> queuedTransactionsAdded, List<Transaction> pendingTransactionsAdded) {
38 return new TransactionPoolAddResult(null, queuedTransactionsAdded, pendingTransactionsAdded);
39 }
40
41 public boolean transactionsWereAdded() {
42 return pendingTransactionsWereAdded() || queuedTransactionsWereAdded();
43 }
44
45 @VisibleForTesting
46 public boolean queuedTransactionsWereAdded() {
47 return queuedTransactionsAdded != null && !queuedTransactionsAdded.isEmpty();
48 }
49
50 public boolean pendingTransactionsWereAdded() {
51 return pendingTransactionsAdded != null && !pendingTransactionsAdded.isEmpty();
52 }
53
54 public String getErrorMessage() {
55 return errorMessage;
56 }
57
58 public static TransactionPoolAddResult okQueuedTransaction(Transaction tx) {
59 return new TransactionPoolAddResult(null, Collections.singletonList(tx), Collections.emptyList());
60 }
61
62 public static TransactionPoolAddResult okPendingTransaction(Transaction tx) {
63 return new TransactionPoolAddResult(null, Collections.emptyList(), Collections.singletonList(tx));
64 }
65
66 public static TransactionPoolAddResult withError(String errorMessage) {
67 return new TransactionPoolAddResult(errorMessage, Collections.emptyList(), Collections.emptyList());
68 }
69
70 public static TransactionPoolAddResult okPendingTransactions(List<Transaction> pendingTransactionsAdded) {
71 return new TransactionPoolAddResult(null, Collections.emptyList(), pendingTransactionsAdded);
72 }
73
74 public List<Transaction> getPendingTransactionsAdded() {
75 return pendingTransactionsAdded;
76 }
77
78 public List<Transaction> getQueuedTransactionsAdded() {
79 return queuedTransactionsAdded;
80 }
81 }