@@ -45,9 +45,8 @@ struct SelfReferencedMultiEraBlock {
45
45
/// Multi-era block - inner.
46
46
#[ derive( Debug ) ]
47
47
struct MultiEraBlockInner {
48
- /// What blockchain was the block produced on.
49
- //#[allow(dead_code)]
50
- pub chain : Network ,
48
+ /// What blockchain network was the block produced on.
49
+ network : Network ,
51
50
/// The Point on the blockchain this block can be found.
52
51
point : Point ,
53
52
/// The previous point on the blockchain before this block.
@@ -93,7 +92,7 @@ impl MultiEraBlock {
93
92
///
94
93
/// If the given bytes cannot be decoded as a multi-era block, an error is returned.
95
94
fn new_block (
96
- chain : Network , raw_data : Vec < u8 > , previous : & Point , fork : Fork ,
95
+ network : Network , raw_data : Vec < u8 > , previous : & Point , fork : Fork ,
97
96
) -> anyhow:: Result < Self > {
98
97
let builder = SelfReferencedMultiEraBlockTryBuilder {
99
98
raw_data,
@@ -127,7 +126,7 @@ impl MultiEraBlock {
127
126
// Special case, when the previous block is actually UNKNOWN, we can't check it.
128
127
if !previous. is_unknown ( )
129
128
// Otherwise, we make sure the hash chain is intact
130
- && ! previous. cmp_hash ( & decoded_block. header ( ) . previous_hash ( ) )
129
+ && previous != & decoded_block. header ( ) . previous_hash ( )
131
130
{
132
131
debug ! ( "{}, {:?}" , previous, decoded_block. header( ) . previous_hash( ) ) ;
133
132
@@ -140,7 +139,7 @@ impl MultiEraBlock {
140
139
Ok ( Self {
141
140
fork,
142
141
inner : Arc :: new ( MultiEraBlockInner {
143
- chain ,
142
+ network ,
144
143
point,
145
144
previous : previous. clone ( ) ,
146
145
data : self_ref_block,
@@ -156,9 +155,9 @@ impl MultiEraBlock {
156
155
///
157
156
/// If the given bytes cannot be decoded as a multi-era block, an error is returned.
158
157
pub fn new (
159
- chain : Network , raw_data : Vec < u8 > , previous : & Point , fork : Fork ,
158
+ network : Network , raw_data : Vec < u8 > , previous : & Point , fork : Fork ,
160
159
) -> anyhow:: Result < Self > {
161
- MultiEraBlock :: new_block ( chain , raw_data, previous, fork)
160
+ MultiEraBlock :: new_block ( network , raw_data, previous, fork)
162
161
}
163
162
164
163
/// Remake the block on a new fork.
@@ -169,6 +168,7 @@ impl MultiEraBlock {
169
168
/// Decodes the data into a multi-era block.
170
169
///
171
170
/// # Returns
171
+ ///
172
172
/// The decoded block data, which can easily be processed by a consumer.
173
173
#[ must_use]
174
174
#[ allow( clippy:: missing_panics_doc) ]
@@ -179,6 +179,7 @@ impl MultiEraBlock {
179
179
/// Decodes the data into a multi-era block.
180
180
///
181
181
/// # Returns
182
+ ///
182
183
/// The raw byte data of the block.
183
184
#[ must_use]
184
185
#[ allow( clippy:: missing_panics_doc) ]
@@ -189,6 +190,7 @@ impl MultiEraBlock {
189
190
/// Returns the block point of this block.
190
191
///
191
192
/// # Returns
193
+ ///
192
194
/// The block point of this block.
193
195
#[ must_use]
194
196
pub fn point ( & self ) -> Point {
@@ -198,6 +200,7 @@ impl MultiEraBlock {
198
200
/// Returns the block point of the previous block.
199
201
///
200
202
/// # Returns
203
+ ///
201
204
/// The previous blocks `Point`
202
205
#[ must_use]
203
206
pub fn previous ( & self ) -> Point {
@@ -210,9 +213,10 @@ impl MultiEraBlock {
210
213
/// (Immutable Database) of the Node.
211
214
///
212
215
/// # Returns
216
+ ///
213
217
/// `true` if the block is immutable, `false` otherwise.
214
218
#[ must_use]
215
- pub fn immutable ( & self ) -> bool {
219
+ pub fn is_immutable ( & self ) -> bool {
216
220
self . fork == 0 . into ( )
217
221
}
218
222
@@ -225,28 +229,32 @@ impl MultiEraBlock {
225
229
/// - 2+ - for each subsequent rollback detected while reading live blocks.
226
230
///
227
231
/// # Returns
232
+ ///
228
233
/// The fork the block was found on.
229
234
#[ must_use]
230
235
pub fn fork ( & self ) -> Fork {
231
236
self . fork
232
237
}
233
238
234
- /// What chain was the block from
239
+ /// What blockchain network was the block from
235
240
///
236
241
/// # Returns
237
- /// - The chain that this block originated on.
242
+ ///
243
+ /// - The network that this block originated on.
238
244
#[ must_use]
239
- pub fn chain ( & self ) -> Network {
240
- self . inner . chain
245
+ pub fn network ( & self ) -> Network {
246
+ self . inner . network
241
247
}
242
248
243
249
/// Get The Metadata fora a transaction and known label from the block
244
250
///
245
251
/// # Parameters
252
+ ///
246
253
/// - `txn_idx` - Index of the Transaction in the Block
247
254
/// - `label` - The label of the transaction
248
255
///
249
256
/// # Returns
257
+ ///
250
258
/// - Metadata for the given label in the transaction.
251
259
/// - Or None if the label requested isn't present.
252
260
#[ must_use]
@@ -262,7 +270,7 @@ impl MultiEraBlock {
262
270
self . inner . witness_map . as_ref ( )
263
271
}
264
272
265
- /// If the Witness exists for a given transaction then return its public key.
273
+ /// If the witness exists for a given transaction then return its public key.
266
274
#[ must_use]
267
275
pub fn witness_for_tx ( & self , vkey_hash : & VKeyHash , tx_num : TxnIndex ) -> Option < VerifyingKey > {
268
276
if let Some ( witnesses) = self . witness_map ( ) {
@@ -286,7 +294,7 @@ impl Display for MultiEraBlock {
286
294
let txns = block. tx_count ( ) ;
287
295
let aux_data = block. has_aux_data ( ) ;
288
296
289
- let fork = if self . immutable ( ) {
297
+ let fork = if self . is_immutable ( ) {
290
298
"Immutable" . to_string ( )
291
299
} else {
292
300
format ! ( "Fork: {fork:?}" )
@@ -461,6 +469,10 @@ pub(crate) mod tests {
461
469
) ;
462
470
463
471
assert ! ( block. is_err( ) ) ;
472
+ assert ! ( block
473
+ . unwrap_err( )
474
+ . to_string( )
475
+ . contains( "Previous slot is not less than current slot" ) ) ;
464
476
}
465
477
466
478
Ok ( ( ) )
0 commit comments