-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
27 lines (22 loc) · 801 Bytes
/
Block.java
File metadata and controls
27 lines (22 loc) · 801 Bytes
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
package org.example;
import java.util.List;
class Block {
int index;
long timestamp;
List<Transaction> transactions;
int proof;
String previousBlockHeaderHash;
String merkleRoot;
public Block(int index, long timestamp, List<Transaction> transactions, int proof, String previousBlockHeaderHash) {
this.index = index;
this.timestamp = timestamp;
this.transactions = transactions;
this.proof = proof;
this.previousBlockHeaderHash = previousBlockHeaderHash;
this.merkleRoot = calculateMerkleRoot(transactions);
}
private String calculateMerkleRoot(List<Transaction> transactions) {
MerkleTree merkleTree = new MerkleTree(transactions);
return merkleTree.getRoot();
}
}