Make monero-serai Block::number not panic on invalid blocks

This commit is contained in:
Luke Parker
2024-01-06 00:02:55 -05:00
parent e7b0ed3e7e
commit 1ba2d8d832
2 changed files with 17 additions and 12 deletions

View File

@@ -58,10 +58,10 @@ pub struct Block {
}
impl Block {
pub fn number(&self) -> usize {
pub fn number(&self) -> Option<u64> {
match self.miner_tx.prefix.inputs.first() {
Some(Input::Gen(number)) => (*number).try_into().unwrap(),
_ => panic!("invalid block, miner TX didn't have a Input::Gen"),
Some(Input::Gen(number)) => Some(*number),
_ => None,
}
}