Skip to content
Snippets Groups Projects
Commit 43d3cd9a authored by Jonas SPRENGER's avatar Jonas SPRENGER
Browse files

[feat] blockchain-dal: replace panic! by fatal_error!

parent b110e079
No related branches found
No related tags found
1 merge request!141Jonas/127 replace all panics by fatal error
......@@ -17,6 +17,7 @@ use dubp_documents::documents::transaction::*;
use dubp_documents::BlockNumber;
use dup_crypto::hashs::Hash;
use dup_crypto::keys::PubKey;
use durs_common_tools::fatal_error;
use std::cmp::Ordering;
use std::ops::{Add, Sub};
......@@ -46,7 +47,7 @@ impl Add for SourceAmount {
if self.1 == s2.1 {
SourceAmount(self.0 + s2.0, self.1)
} else {
panic!("Source change base not yet supported !")
fatal_error!("Source change base not yet supported !")
}
}
}
......@@ -57,7 +58,7 @@ impl Sub for SourceAmount {
if self.1 == s2.1 {
SourceAmount(self.0 - s2.0, self.1)
} else {
panic!("Source change base not yet supported !")
fatal_error!("Source change base not yet supported !")
}
}
}
......@@ -98,14 +99,14 @@ impl UTXO {
pub fn get_conditions(&self) -> UTXOConditionsGroup {
match *self {
UTXO::V10(ref utxo_v10) => utxo_v10.get_conditions(),
_ => panic!("UTXO version not supported !"),
_ => fatal_error!("UTXO version not supported !"),
}
}
/// UTXO amount
pub fn get_amount(&self) -> SourceAmount {
match *self {
UTXO::V10(ref utxo_v10) => utxo_v10.get_amount(),
_ => panic!("UTXO version not supported !"),
_ => fatal_error!("UTXO version not supported !"),
}
}
}
......
......@@ -57,6 +57,7 @@ use dubp_documents::CurrencyName;
use dubp_documents::{BlockHash, BlockNumber, Blockstamp, PreviousBlockstamp};
use dup_crypto::hashs::Hash;
use dup_crypto::keys::*;
use durs_common_tools::fatal_error;
use durs_wot::data::{rusty::RustyWebOfTrust, NodeId};
use fnv::FnvHashMap;
use rustbreak::backend::{FileBackend, MemoryBackend};
......@@ -289,7 +290,7 @@ impl CurrencyV10DBs {
CurrencyV10DBs {
du_db: open_db::<UDsV10Datas>(db_path, "du.db").expect("Fail to open UDsV10DB"),
tx_db: open_db::<TxV10Datas>(db_path, "tx.db")
.unwrap_or_else(|_| panic!("Fail to open TxV10DB")),
.unwrap_or_else(|_| fatal_error!("Fail to open TxV10DB")),
utxos_db: open_db::<UTXOsV10Datas>(db_path, "sources.db")
.expect("Fail to open UTXOsV10DB"),
balances_db: open_db::<BalancesV10Datas>(db_path, "balances.db")
......
......@@ -132,7 +132,7 @@ pub fn get_current_frame(
for block_number in frame_begin..current_block.block.number.0 {
let issuer = db
.get(&BlockNumber(block_number))
.unwrap_or_else(|| panic!("Fail to get block #{} !", block_number))
.unwrap_or_else(|| fatal_error!("Fail to get block #{} !", block_number))
.block
.issuers()[0];
let issuer_count_blocks = if let Some(issuer_count_blocks) = current_frame.get(&issuer)
......
......@@ -28,7 +28,7 @@ pub fn get_currency_params(
genesis_block.block.parameters.expect("safe unwrap"),
)))
} else {
panic!("The genesis block are None parameters !");
fatal_error!("The genesis block are None parameters !");
}
} else {
None
......
......@@ -15,6 +15,7 @@
use crate::entities::block::DALBlock;
use dup_crypto::keys::PubKey;
use durs_common_tools::fatal_error;
use durs_wot::operations::centrality::{CentralitiesCalculator, UlrikBrandesCentralityCalculator};
use durs_wot::operations::distance::{
DistanceCalculator, RustyDistanceCalculator, WotDistance, WotDistanceParameters,
......@@ -68,12 +69,12 @@ pub fn get_sentry_requirement(members_count: usize, step_max: u32) -> u32 {
} else if members_count < 1_889_569 {
18
} else {
panic!(
fatal_error!(
"get_sentry_requirement not define for members_count greater than 1_889_569 !"
);
}
}
_ => panic!("get_sentry_requirement not define for step_max != 5 !"),
_ => fatal_error!("get_sentry_requirement not define for step_max != 5 !"),
}
}
......@@ -85,7 +86,7 @@ pub fn calculate_average_density<T: WebOfTrust>(wot: &T) -> usize {
for member in &enabled_members {
count_actives_links += wot
.issued_count(*member)
.unwrap_or_else(|| panic!("Fail to get issued_count of wot_id {}", (*member).0));
.unwrap_or_else(|| fatal_error!("Fail to get issued_count of wot_id {}", (*member).0));
}
((count_actives_links as f32 / enabled_members_count as f32) * 1_000.0) as usize
}
......
......@@ -20,6 +20,7 @@ use dubp_documents::documents::identity::IdentityDocument;
use dubp_documents::Document;
use dubp_documents::{BlockNumber, Blockstamp};
use dup_crypto::keys::PubKey;
use durs_common_tools::fatal_error;
use durs_wot::NodeId;
/// Remove identity from databases
......@@ -102,14 +103,14 @@ pub fn exclude_identity(
DALIdentityState::ExpireMember(renewed_counts) => {
DALIdentityState::Member(renewed_counts)
}
_ => panic!("Try to revert exclusion for a no excluded identity !"),
_ => fatal_error!("Try to revert exclusion for a no excluded identity !"),
}
} else {
match idty_datas.state {
DALIdentityState::Member(renewed_counts) => {
DALIdentityState::ExpireMember(renewed_counts)
}
_ => panic!("Try to exclude for an already excluded/revoked identity !"),
_ => fatal_error!("Try to exclude for an already excluded/revoked identity !"),
}
};
idty_datas.expired_on = if revert {
......@@ -145,7 +146,7 @@ pub fn revoke_identity(
| DALIdentityState::ImplicitRevoked(renewed_counts) => {
DALIdentityState::ExpireMember(renewed_counts)
}
_ => panic!("Try to revert revoke_identity() for a no revoked idty !"),
_ => fatal_error!("Try to revert revoke_identity() for a no revoked idty !"),
}
} else {
match member_datas.state {
......@@ -159,7 +160,7 @@ pub fn revoke_identity(
DALIdentityState::ImplicitRevoked(renewed_counts)
}
}
_ => panic!("Try to revert revoke an already revoked idty !"),
_ => fatal_error!("Try to revert revoke an already revoked idty !"),
}
};
member_datas.revoked_on = if revert {
......@@ -201,7 +202,7 @@ pub fn renewal_identity(
DALIdentityState::ExpireMember(new_renewed_counts)
}
}
_ => panic!("Try to revert renewal_identity() for an excluded or revoked idty !"),
_ => fatal_error!("Try to revert renewal_identity() for an excluded or revoked idty !"),
}
} else {
match idty_datas.state {
......@@ -215,7 +216,7 @@ pub fn renewal_identity(
new_renewed_counts.push(0);
DALIdentityState::Member(new_renewed_counts)
}
_ => panic!("Try to renewed a revoked identity !"),
_ => fatal_error!("Try to renewed a revoked identity !"),
}
};
// Calculate new ms_chainable_on value
......
......@@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use dubp_documents::documents::transaction::*;
use durs_common_tools::fatal_error;
use crate::entities::sources::{SourceAmount, SourceIndexV10, UTXOIndexV10, UTXOV10};
use crate::*;
......@@ -75,12 +76,12 @@ pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError
new_sources_index.remove(&source.0);
(*balance, new_sources_index)
} else {
panic!("Fail to revert tx : an output conditions don't exist in BalancesDB.")
fatal_error!("Fail to revert tx : an output conditions don't exist in BalancesDB.")
};
let new_balance = if balance >= source_amount {
balance - source_amount
} else {
panic!("Fail to revert tx : an output revert cause negative balance.")
fatal_error!("Fail to revert tx : an output revert cause negative balance.")
};
new_balances_consumed_adress.insert(conditions, (new_balance, new_sources_index));
}
......@@ -270,7 +271,7 @@ pub fn apply_and_write_tx(
// Get utxo
let utxo = db.get(&utxo_index).unwrap_or_else(|| {
debug!("apply_tx=\"{:#?}\"", tx_doc);
panic!(
fatal_error!(
"ApplyBLockError : unknow UTXO in inputs : {:?} !",
utxo_index
)
......@@ -312,7 +313,7 @@ pub fn apply_and_write_tx(
new_balances_consumed_adress
.push((conditions.clone(), (new_balance, new_sources_index)));
} else {
panic!("Apply Tx : try to consume a source, but the owner address is not found in balances db : {:?}", conditions)
fatal_error!("Apply Tx : try to consume a source, but the owner address is not found in balances db : {:?}", conditions)
}
}
new_balances_consumed_adress
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment