Proper error when trying to rewind to empty genesis

This commit is contained in:
Ignotus Peverell 2018-03-01 03:09:10 +00:00
parent 07df881a72
commit 7f478d79f6
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -682,28 +682,27 @@ fn indexes_at(block: &Block, commit_index: &ChainStore) -> Result<(u64, u64), Er
// use last regular output if we have any, otherwise last coinbase output
let last_output = if last_regular_output.is_some() {
last_regular_output
last_regular_output.unwrap()
} else if last_coinbase_output.is_some() {
last_coinbase_output
last_coinbase_output.unwrap()
} else {
None
return Err(Error::Other("can't get index in an empty block".to_owned()))
};
let out_idx = match last_output {
Some(output) => commit_index.get_output_pos(&output.commitment())
.map_err(|e| {
Error::StoreErr(e, format!("missing output pos for known block"))
})?,
None => 0,
};
let out_idx = commit_index
.get_output_pos(&last_output.commitment())
.map_err(|e| Error::StoreErr(e, format!("missing output pos for block")))?;
let kern_idx = match block.kernels.last() {
Some(kernel) => commit_index.get_kernel_pos(&kernel.excess)
.map_err(|e| {
Error::StoreErr(e, format!("missing kernel pos for known block"))
Error::StoreErr(e, format!("missing kernel pos for block"))
})?,
None => 0,
None => {
return Err(Error::Other("can't get index in an empty block".to_owned()));
}
};
Ok((out_idx, kern_idx))
}