@@ -158,7 +158,7 @@ impl MultiEraBlock {
158
158
/// # Errors
159
159
///
160
160
/// If the given bytes cannot be decoded as a multi-era block, an error is returned.
161
- pub fn new (
161
+ pub ( crate ) fn new (
162
162
chain : Network , raw_data : Vec < u8 > , previous : & Point , fork : u64 ,
163
163
) -> anyhow:: Result < Self , Error > {
164
164
// This lets us reliably count any bad block arising from deserialization.
@@ -170,55 +170,93 @@ impl MultiEraBlock {
170
170
}
171
171
172
172
/// Remake the block on a new fork.
173
- pub fn set_fork ( & mut self , fork : u64 ) {
173
+ pub ( crate ) fn set_fork ( & mut self , fork : u64 ) {
174
174
self . fork = fork;
175
175
}
176
176
177
177
/// Decodes the data into a multi-era block.
178
+ ///
179
+ /// # Returns
180
+ /// The decoded block data, which can easily be processed by a consumer.
178
181
#[ must_use]
179
182
#[ allow( clippy:: missing_panics_doc) ]
180
183
pub fn decode ( & self ) -> & pallas:: ledger:: traverse:: MultiEraBlock {
181
184
self . inner . data . borrow_block ( )
182
185
}
183
186
184
187
/// Decodes the data into a multi-era block.
188
+ ///
189
+ /// # Returns
190
+ /// The raw byte data of the block.
185
191
#[ must_use]
186
192
#[ allow( clippy:: missing_panics_doc) ]
187
193
pub fn raw ( & self ) -> & Vec < u8 > {
188
194
self . inner . data . borrow_raw_data ( )
189
195
}
190
196
191
197
/// Returns the block point of this block.
198
+ ///
199
+ /// # Returns
200
+ /// The block point of this block.
192
201
#[ must_use]
193
202
pub fn point ( & self ) -> Point {
194
203
self . inner . point . clone ( )
195
204
}
196
205
197
206
/// Returns the block point of the previous block.
207
+ ///
208
+ /// # Returns
209
+ /// The previous blocks `Point`
198
210
#[ must_use]
199
211
pub fn previous ( & self ) -> Point {
200
212
self . inner . previous . clone ( )
201
213
}
202
214
203
215
/// Is the block data immutable on-chain.
216
+ ///
217
+ /// Immutable blocks are by-definition those that exist in the Mithril Snapshot
218
+ /// (Immutable Database) of the Node.
219
+ ///
220
+ /// # Returns
221
+ /// `true` if the block is immutable, `false` otherwise.
204
222
#[ must_use]
205
223
pub fn immutable ( & self ) -> bool {
206
224
self . fork == 0
207
225
}
208
226
209
- /// Is the block data immutable on-chain.
227
+ /// What fork is the block from.
228
+ ///
229
+ /// The fork is a synthetic number that represents how many rollbacks have been
230
+ /// detected in the running chain. The fork is:
231
+ /// - 0 - for all immutable data;
232
+ /// - 1 - for any data read from the blockchain during a *backfill* on initial sync
233
+ /// - 2+ - for each subsequent rollback detected while reading live blocks.
234
+ ///
235
+ /// # Returns
236
+ /// The fork the block was found on.
210
237
#[ must_use]
211
238
pub fn fork ( & self ) -> u64 {
212
239
self . fork
213
240
}
214
241
215
242
/// What chain was the block from
243
+ ///
244
+ /// # Returns
245
+ /// - The chain that this block originated on.
216
246
#[ must_use]
217
247
pub fn chain ( & self ) -> Network {
218
248
self . inner . chain
219
249
}
220
250
221
251
/// Get The Decoded Metadata fora a transaction and known label from the block
252
+ ///
253
+ /// # Parameters
254
+ /// - `txn_idx` - Index of the Transaction in the Block
255
+ /// - `label` - The label of the transaction
256
+ ///
257
+ /// # Returns
258
+ /// - Metadata for the given label in the transaction.
259
+ /// - Or None if the label requested isn't present.
222
260
#[ must_use]
223
261
pub fn txn_metadata (
224
262
& self , txn_idx : usize , label : u64 ,
@@ -233,10 +271,23 @@ impl MultiEraBlock {
233
271
}
234
272
235
273
/// Returns the witness map for the block.
236
- #[ allow( dead_code) ]
237
274
pub ( crate ) fn witness_map ( & self ) -> Option < & TxWitness > {
238
275
self . inner . witness_map . as_ref ( )
239
276
}
277
+
278
+ /// If the Witness exists for a given transaction then return its public key.
279
+ #[ must_use]
280
+ pub fn witness_for_tx ( & self , vkey_hash : & [ u8 ; 28 ] , tx_num : u16 ) -> Option < Vec < u8 > > {
281
+ if let Some ( witnesses) = self . witness_map ( ) {
282
+ if witnesses. check_witness_in_tx ( vkey_hash, tx_num) {
283
+ if let Some ( pub_key) = witnesses. get_witness_pk_addr ( vkey_hash) {
284
+ return Some ( pub_key. into ( ) ) ;
285
+ }
286
+ }
287
+ }
288
+
289
+ None
290
+ }
240
291
}
241
292
242
293
impl Display for MultiEraBlock {
0 commit comments