-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStoredBlock.java
More file actions
189 lines (166 loc) · 4.95 KB
/
StoredBlock.java
File metadata and controls
189 lines (166 loc) · 4.95 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* Copyright 2013 Ronald W Hoffman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package JavaBitcoin;
import java.math.BigInteger;
/**
* A StoredBlock represents data that is stored in the chain database. This
* includes the Block as defined by the Bitcoin protocol.
*/
public class StoredBlock {
/** The work represented by the block chain up to and including this block */
private BigInteger chainWork;
/** The block hash */
private Sha256Hash blockHash;
/** The previous block hash */
private Sha256Hash prevBlockHash;
/** The block height */
private int blockHeight;
/** Block is on hold */
private boolean onHold = false;
/** Block is on the chain */
private boolean onChain = false;
/** The block */
private Block block;
/**
* Creates a StoredBlock without any block data for a block on the chain
*
* @param blockHash Block hash
* @param prevBlockHash Previous block hash
* @param chainWork Chain work
* @param blockHeight BlockHeight
*/
public StoredBlock(Sha256Hash blockHash, Sha256Hash prevBlockHash, BigInteger chainWork, int blockHeight) {
this.chainWork = chainWork;
this.blockHeight = blockHeight;
this.blockHash = blockHash;
this.prevBlockHash = prevBlockHash;
this.onChain = true;
}
/**
* Creates a StoredBlock containing a new block
*
* @param block The block to be stored
* @param chainWork Chain work
* @param blockHeight Block height
*/
public StoredBlock(Block block, BigInteger chainWork, int blockHeight) {
this(block, chainWork, blockHeight, false, false);
}
/**
* Creates a StoredBlock containing an existing block
*
* @param block The block
* @param chainWork Chain work
* @param blockHeight Block height
* @param onChain TRUE if the block is on the chain
* @param onHold TRUE if the block is on hold
*/
public StoredBlock(Block block, BigInteger chainWork, int blockHeight, boolean onChain, boolean onHold) {
this.block = block;
this.chainWork = chainWork;
this.blockHeight = blockHeight;
this.blockHash = block.getHash();
this.prevBlockHash = block.getPrevBlockHash();
this.onChain = onChain;
this.onHold = onHold;
}
/**
* Returns the stored block
*
* @return Stored block or null if the block has been pruned
*/
public Block getBlock() {
return block;
}
/**
* Returns the block hash
*
* @return The block hash
*/
public Sha256Hash getHash() {
return blockHash;
}
/**
* Returns the previous block hash
*
* @return The previous block hash
*/
public Sha256Hash getPrevBlockHash() {
return prevBlockHash;
}
/**
* Returns the chain work represented by this block
*
* @return The chain work
*/
public BigInteger getChainWork() {
return chainWork;
}
/**
* Sets the chain work represented by this block
* @param chainWork The chain work
*/
public void setChainWork(BigInteger chainWork) {
this.chainWork = chainWork;
}
/**
* Returns the block height
*
* @return The block height
*/
public int getHeight() {
return blockHeight;
}
/**
* Set the block height
* @param blockHeight The block height
*/
public void setHeight(int blockHeight) {
this.blockHeight = blockHeight;
}
/**
* Sets the block hold status
*
* @param onHold TRUE if the block is on hold
*/
public void setHold(boolean onHold) {
this.onHold = onHold;
}
/**
* Checks if the block is on hold
*
* @return TRUE if the block is on hold
*/
public boolean isOnHold() {
return onHold;
}
/**
* Sets the block chain status
*
* @param onChain TRUE if the block is on the chain
*/
public void setChain(boolean onChain) {
this.onChain = onChain;
}
/**
* Checks if the block is on the chain
*
* @return TRUE if the block is on the chain
*/
public boolean isOnChain() {
return onChain;
}
}