move overflow into separate error type

This commit is contained in:
NikVolf 2016-12-13 23:26:39 +01:00
parent a9c897ec7b
commit 4fdf56ccf4
2 changed files with 14 additions and 2 deletions

View File

@ -127,8 +127,16 @@ impl<'a> BlockRule for BlockCoinbaseClaim<'a> {
let claim = self.block.transactions[0].raw.total_spends();
let (fees, overflow) = available.overflowing_sub(spends);
let (reward, overflow2) = fees.overflowing_add(block_reward_satoshi(self.height));
if overflow || overflow2 || claim > reward {
if overflow {
return Err(Error::TransactionFeesOverflow);
}
let (reward, overflow) = fees.overflowing_add(block_reward_satoshi(self.height));
if overflow {
return Err(Error::TransactionFeeAndRewardOverflow);
}
if claim > reward {
Err(Error::CoinbaseOverspend { expected_max: reward, actual: claim })
} else {
Ok(())

View File

@ -36,6 +36,10 @@ pub enum Error {
NonFinalBlock,
/// Old version block.
OldVersionBlock,
/// Sum of the transaction fees in block + coinbase reward exceeds u64::max
TransactionFeeAndRewardOverflow,
/// Sum of the transaction fees in block exceeds u64::max
TransactionFeesOverflow,
}
#[derive(Debug, PartialEq)]