-
Notifications
You must be signed in to change notification settings - Fork 17
/
UTXOPool.java
executable file
·54 lines (45 loc) · 1.55 KB
/
UTXOPool.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
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public class UTXOPool {
/**
* The current collection of UTXOs, with each one mapped to its corresponding transaction output
*/
private HashMap<UTXO, Transaction.Output> H;
/** Creates a new empty UTXOPool */
public UTXOPool() {
H = new HashMap<UTXO, Transaction.Output>();
}
/** Creates a new UTXOPool that is a copy of {@code uPool} */
public UTXOPool(UTXOPool uPool) {
H = new HashMap<UTXO, Transaction.Output>(uPool.H);
}
/** Adds a mapping from UTXO {@code utxo} to transaction output @code{txOut} to the pool */
public void addUTXO(UTXO utxo, Transaction.Output txOut) {
H.put(utxo, txOut);
}
/** Removes the UTXO {@code utxo} from the pool */
public void removeUTXO(UTXO utxo) {
H.remove(utxo);
}
/**
* @return the transaction output corresponding to UTXO {@code utxo}, or null if {@code utxo} is
* not in the pool.
*/
public Transaction.Output getTxOutput(UTXO ut) {
return H.get(ut);
}
/** @return true if UTXO {@code utxo} is in the pool and false otherwise */
public boolean contains(UTXO utxo) {
return H.containsKey(utxo);
}
/** Returns an {@code ArrayList} of all UTXOs in the pool */
public ArrayList<UTXO> getAllUTXO() {
Set<UTXO> setUTXO = H.keySet();
ArrayList<UTXO> allUTXO = new ArrayList<UTXO>();
for (UTXO ut : setUTXO) {
allUTXO.add(ut);
}
return allUTXO;
}
}