-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTransactionPool.java
executable file
·38 lines (29 loc) · 1020 Bytes
/
TransactionPool.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
import java.util.ArrayList;
import java.util.HashMap;
public class TransactionPool {
private HashMap<ByteArrayWrapper, Transaction> H;
public TransactionPool() {
H = new HashMap<ByteArrayWrapper, Transaction>();
}
public TransactionPool(TransactionPool txPool) {
H = new HashMap<ByteArrayWrapper, Transaction>(txPool.H);
}
public void addTransaction(Transaction tx) {
ByteArrayWrapper hash = new ByteArrayWrapper(tx.getHash());
H.put(hash, tx);
}
public void removeTransaction(byte[] txHash) {
ByteArrayWrapper hash = new ByteArrayWrapper(txHash);
H.remove(hash);
}
public Transaction getTransaction(byte[] txHash) {
ByteArrayWrapper hash = new ByteArrayWrapper(txHash);
return H.get(hash);
}
public ArrayList<Transaction> getTransactions() {
ArrayList<Transaction> T = new ArrayList<Transaction>();
for (Transaction tx : H.values())
T.add(tx);
return T;
}
}