-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockChain.java
executable file
·51 lines (44 loc) · 1.59 KB
/
BlockChain.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
// Block Chain should maintain only limited block nodes to satisfy the functions
// You should not have all the blocks added to the block chain in memory
// as it would cause a memory overflow.
public class BlockChain {
public static final int CUT_OFF_AGE = 10;
/**
* create an empty block chain with just a genesis block. Assume {@code genesisBlock} is a valid
* block
*/
public BlockChain(Block genesisBlock) {
// IMPLEMENT THIS
}
/** Get the maximum height block */
public Block getMaxHeightBlock() {
// IMPLEMENT THIS
}
/** Get the UTXOPool for mining a new block on top of max height block */
public UTXOPool getMaxHeightUTXOPool() {
// IMPLEMENT THIS
}
/** Get the transaction pool to mine a new block */
public TransactionPool getTransactionPool() {
// IMPLEMENT THIS
}
/**
* Add {@code block} to the block chain if it is valid. For validity, all transactions should be
* valid and block should be at {@code height > (maxHeight - CUT_OFF_AGE)}.
*
* <p>
* For example, you can try creating a new block over the genesis block (block height 2) if the
* block chain height is {@code <=
* CUT_OFF_AGE + 1}. As soon as {@code height > CUT_OFF_AGE + 1}, you cannot create a new block
* at height 2.
*
* @return true if block is successfully added
*/
public boolean addBlock(Block block) {
// IMPLEMENT THIS
}
/** Add a transaction to the transaction pool */
public void addTransaction(Transaction tx) {
// IMPLEMENT THIS
}
}