-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUTXOPool.java
More file actions
58 lines (48 loc) · 1.57 KB
/
UTXOPool.java
File metadata and controls
58 lines (48 loc) · 1.57 KB
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
/*
* UTXOPool.java
*
* This class represents a UTXO pool, which is a mapping from UTXOs
* to their corresponding transction outputs
*/
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 <uPool>
public UTXOPool(UTXOPool uPool) {
H = new HashMap<UTXO, Transaction.Output>(uPool.H);
}
// Adds a mapping from UTXO <utxo> to transaction output <txOut> to the pool
public void addUTXO(UTXO utxo, Transaction.Output txOut) {
H.put(utxo, txOut);
}
// Removes the UTXO <utxo> from the pool
public void removeUTXO(UTXO utxo) {
H.remove(utxo);
}
// Returns the transaction output corresponding to UTXO <utxo>, or null if
// <utxo> is not in the pool.
public Transaction.Output getTxOutput(UTXO ut) {
return H.get(ut);
}
// Returns true if UTXO <utxo> is in the pool and false otherwise
public boolean contains(UTXO utxo) {
return H.containsKey(utxo);
}
// Returns an 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;
}
}