mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-08 12:21:09 +03:00
Proper error when trying to rewind to empty genesis
This commit is contained in:
parent
07df881a72
commit
7f478d79f6
1 changed files with 11 additions and 12 deletions
|
@ -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
|
// use last regular output if we have any, otherwise last coinbase output
|
||||||
let last_output = if last_regular_output.is_some() {
|
let last_output = if last_regular_output.is_some() {
|
||||||
last_regular_output
|
last_regular_output.unwrap()
|
||||||
} else if last_coinbase_output.is_some() {
|
} else if last_coinbase_output.is_some() {
|
||||||
last_coinbase_output
|
last_coinbase_output.unwrap()
|
||||||
} else {
|
} else {
|
||||||
None
|
return Err(Error::Other("can't get index in an empty block".to_owned()))
|
||||||
};
|
};
|
||||||
|
|
||||||
let out_idx = match last_output {
|
let out_idx = commit_index
|
||||||
Some(output) => commit_index.get_output_pos(&output.commitment())
|
.get_output_pos(&last_output.commitment())
|
||||||
.map_err(|e| {
|
.map_err(|e| Error::StoreErr(e, format!("missing output pos for block")))?;
|
||||||
Error::StoreErr(e, format!("missing output pos for known block"))
|
|
||||||
})?,
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let kern_idx = match block.kernels.last() {
|
let kern_idx = match block.kernels.last() {
|
||||||
Some(kernel) => commit_index.get_kernel_pos(&kernel.excess)
|
Some(kernel) => commit_index.get_kernel_pos(&kernel.excess)
|
||||||
.map_err(|e| {
|
.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))
|
Ok((out_idx, kern_idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue