Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bill_payments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]

use remitwise_common::{
clamp_limit, EventCategory, EventPriority, RemitwiseEvents, ARCHIVE_BUMP_AMOUNT,
Expand Down Expand Up @@ -1064,7 +1065,7 @@ impl BillPayments {
pub fn batch_pay_bills(env: Env, caller: Address, bill_ids: Vec<u32>) -> Result<u32, Error> {
caller.require_auth();
Self::require_not_paused(&env, pause_functions::PAY_BILL)?;
if bill_ids.len() > (MAX_BATCH_SIZE as usize).try_into().unwrap() {
if bill_ids.len() > (MAX_BATCH_SIZE as usize).try_into().unwrap_or(u32::MAX) {
return Err(Error::BatchTooLarge);
}
let bills_map: Map<u32, Bill> = env
Expand Down
4 changes: 3 additions & 1 deletion data_migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Supports multiple formats (JSON, binary, CSV), checksum validation,
//! version compatibility checks, and data integrity verification.

#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]

use base64::Engine;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -105,7 +107,7 @@ impl ExportSnapshot {
/// Compute SHA256 checksum of the payload (canonical JSON).
pub fn compute_checksum(&self) -> String {
let mut hasher = Sha256::new();
hasher.update(serde_json::to_vec(&self.payload).expect("payload must be serializable"));
hasher.update(serde_json::to_vec(&self.payload).unwrap_or_else(|_| panic!("payload must be serializable")));
hex::encode(hasher.finalize().as_ref())
}

Expand Down
57 changes: 29 additions & 28 deletions family_wallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
use soroban_sdk::{
contract, contracterror, contractimpl, contracttype, symbol_short, token::TokenClient, Address,
Env, Map, Symbol, Vec,
Expand Down Expand Up @@ -291,7 +292,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

if members.get(member_address.clone()).is_some() {
return Err(Error::InvalidRole);
Expand Down Expand Up @@ -331,7 +332,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

members.get(member_address)
}
Expand All @@ -356,7 +357,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

let mut record = members
.get(member_address.clone())
Expand Down Expand Up @@ -437,7 +438,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

if !Self::is_owner_or_admin_in_members(&members, &caller) {
panic!("Only Owner or Admin can configure multi-sig");
Expand Down Expand Up @@ -499,7 +500,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&config_key)
.expect("Multi-sig config not found");
.unwrap_or_else(|| panic!("Multi-sig config not found"));

let requires_multisig = match (&tx_type, &data) {
(TransactionType::RegularWithdrawal, TransactionData::Withdrawal(_, _, amount)) => {
Expand Down Expand Up @@ -547,7 +548,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("PEND_TXS"))
.expect("Pending transactions map not initialized");
.unwrap_or_else(|| panic!("Pending transactions map not initialized"));

pending_txs.set(tx_id, pending_tx);
env.storage()
Expand All @@ -572,9 +573,9 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("PEND_TXS"))
.expect("Pending transactions map not initialized");
.unwrap_or_else(|| panic!("Pending transactions map not initialized"));

let mut pending_tx = pending_txs.get(tx_id).expect("Transaction not found");
let mut pending_tx = pending_txs.get(tx_id).unwrap_or_else(|| panic!("Transaction not found"));

let current_time = env.ledger().timestamp();
if current_time > pending_tx.expires_at {
Expand All @@ -591,7 +592,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&Self::get_config_key(pending_tx.tx_type))
.expect("Multi-sig config not found");
.unwrap_or_else(|| panic!("Multi-sig config not found"));

let mut is_authorized = false;
for authorized_signer in config.signers.iter() {
Expand Down Expand Up @@ -626,7 +627,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("EXEC_TXS"))
.expect("Executed transactions map not initialized");
.unwrap_or_else(|| panic!("Executed transactions map not initialized"));

executed_txs.set(tx_id, true);
env.storage()
Expand Down Expand Up @@ -660,7 +661,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&Self::get_config_key(TransactionType::LargeWithdrawal))
.expect("Multi-sig config not found");
.unwrap_or_else(|| panic!("Multi-sig config not found"));

let tx_type = if amount > config.spending_limit {
TransactionType::LargeWithdrawal
Expand Down Expand Up @@ -828,7 +829,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

let timestamp = env.ledger().timestamp();
members.set(
Expand Down Expand Up @@ -857,7 +858,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

if caller != owner {
panic!("Only Owner can remove family members");
Expand All @@ -872,7 +873,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

members.remove(member.clone());
env.storage()
Expand All @@ -888,7 +889,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("PEND_TXS"))
.expect("Pending transactions map not initialized");
.unwrap_or_else(|| panic!("Pending transactions map not initialized"));

pending_txs.get(tx_id)
}
Expand All @@ -902,7 +903,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

members.get(member)
}
Expand All @@ -911,7 +912,7 @@ impl FamilyWallet {
env.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized")
.unwrap_or_else(|| panic!("Wallet not initialized"))
}

pub fn get_emergency_config(env: Env) -> Option<EmergencyConfig> {
Expand Down Expand Up @@ -1109,7 +1110,7 @@ impl FamilyWallet {
env.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized")
.unwrap_or_else(|| panic!("Wallet not initialized"))
});
if admin != caller {
panic!("Only pause admin can pause");
Expand All @@ -1128,7 +1129,7 @@ impl FamilyWallet {
env.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized")
.unwrap_or_else(|| panic!("Wallet not initialized"))
});
if admin != caller {
panic!("Only pause admin can unpause");
Expand Down Expand Up @@ -1180,7 +1181,7 @@ impl FamilyWallet {
env.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized")
.unwrap_or_else(|| panic!("Wallet not initialized"))
});
if admin != caller {
panic!("Only upgrade admin can set version");
Expand Down Expand Up @@ -1212,7 +1213,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));
let timestamp = env.ledger().timestamp();
let mut count = 0u32;
for item in members.iter() {
Expand Down Expand Up @@ -1251,7 +1252,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("OWNER"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));
if caller != owner {
panic!("Only Owner can remove members");
}
Expand All @@ -1264,7 +1265,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));
let mut count = 0u32;
for addr in addresses.iter() {
if addr.clone() == owner {
Expand Down Expand Up @@ -1320,7 +1321,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("EM_CONF"))
.expect("Emergency config not set");
.unwrap_or_else(|| panic!("Emergency config not set"));

if amount > config.max_amount {
panic!("Emergency amount exceeds maximum allowed");
Expand Down Expand Up @@ -1398,7 +1399,7 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
.unwrap_or_else(|| panic!("Wallet not initialized"));

if let Some(mut member_data) = members.get(member.clone()) {
member_data.role = *new_role;
Expand Down Expand Up @@ -1499,8 +1500,8 @@ impl FamilyWallet {
.storage()
.instance()
.get(&symbol_short!("MEMBERS"))
.expect("Wallet not initialized");
let member = members.get(caller.clone()).expect("Not a family member");
.unwrap_or_else(|| panic!("Wallet not initialized"));
let member = members.get(caller.clone()).unwrap_or_else(|| panic!("Not a family member"));
if Self::role_has_expired(env, caller) {
panic!("Role has expired");
}
Expand Down Expand Up @@ -1533,7 +1534,7 @@ impl FamilyWallet {
let mut v = Vec::new(env);
let start = n - MAX_ACCESS_AUDIT_ENTRIES;
for i in start..n {
v.push_back(entries.get(i).unwrap());
v.push_back(entries.get(i).unwrap_or_else(|| panic!("Item not found")));
}
entries = v;
}
Expand Down
17 changes: 14 additions & 3 deletions insurance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
use soroban_sdk::{
contract, contracterror, contractimpl, contracttype, symbol_short, Address, Env, Map, String,
Symbol, Vec,
Expand Down Expand Up @@ -242,6 +243,7 @@ impl Insurance {
}
pub fn pause(env: Env, caller: Address) -> Result<(), InsuranceError> {
caller.require_auth();
let admin = Self::get_pause_admin(&env).unwrap_or_else(|| panic!("No pause admin set"));
let admin = Self::get_pause_admin(&env).ok_or(InsuranceError::Unauthorized)?;
if admin != caller {
return Err(InsuranceError::Unauthorized);
Expand All @@ -255,6 +257,7 @@ impl Insurance {
}
pub fn unpause(env: Env, caller: Address) -> Result<(), InsuranceError> {
caller.require_auth();
let admin = Self::get_pause_admin(&env).unwrap_or_else(|| panic!("No pause admin set"));
let admin = Self::get_pause_admin(&env).ok_or(InsuranceError::Unauthorized)?;
if admin != caller {
return Err(InsuranceError::Unauthorized);
Expand All @@ -275,7 +278,7 @@ impl Insurance {
}
pub fn pause_function(env: Env, caller: Address, func: Symbol) -> Result<(), InsuranceError> {
caller.require_auth();
let admin = Self::get_pause_admin(&env).expect("No pause admin set");
let admin = Self::get_pause_admin(&env).unwrap_or_else(|| panic!("No pause admin set"));
if admin != caller {
return Err(InsuranceError::Unauthorized);
}
Expand All @@ -292,7 +295,7 @@ impl Insurance {
}
pub fn unpause_function(env: Env, caller: Address, func: Symbol) -> Result<(), InsuranceError> {
caller.require_auth();
let admin = Self::get_pause_admin(&env).expect("No pause admin set");
let admin = Self::get_pause_admin(&env).unwrap_or_else(|| panic!("No pause admin set"));
if admin != caller {
return Err(InsuranceError::Unauthorized);
}
Expand Down Expand Up @@ -355,7 +358,10 @@ impl Insurance {
}
pub fn set_version(env: Env, caller: Address, new_version: u32) -> Result<(), InsuranceError> {
caller.require_auth();
let admin = Self::get_upgrade_admin(&env).expect("No upgrade admin set");
let admin = match Self::get_upgrade_admin(&env) {
Some(a) => a,
None => panic!("No upgrade admin set"),
};
if admin != caller {
return Err(InsuranceError::Unauthorized);
}
Expand Down Expand Up @@ -879,6 +885,7 @@ impl Insurance {
let current_time = env.ledger().timestamp();
let mut paid_count = 0;
for id in policy_ids.iter() {
let mut policy = policies.get(id).unwrap_or_else(|| panic!("Policy not found"));
let mut policy = policies_map.get(id).unwrap();
policy.next_payment_date = current_time + (30 * 86400);
let event = PremiumPaidEvent {
Expand Down Expand Up @@ -1001,6 +1008,7 @@ impl Insurance {
.get(&symbol_short!("POLICIES"))
.unwrap_or_else(|| Map::new(&env));

let mut policy = policies.get(policy_id).unwrap_or_else(|| panic!("Policy not found"));
let mut policy = policies
.get(policy_id)
.ok_or(InsuranceError::PolicyNotFound)?;
Expand Down Expand Up @@ -1151,6 +1159,7 @@ impl Insurance {
.get(&symbol_short!("POLICIES"))
.unwrap_or_else(|| Map::new(&env));

let mut policy = policies.get(policy_id).unwrap_or_else(|| panic!("Policy not found"));
let mut policy = policies
.get(policy_id)
.ok_or(InsuranceError::PolicyNotFound)?;
Expand Down Expand Up @@ -1255,6 +1264,7 @@ impl Insurance {
.get(&symbol_short!("PREM_SCH"))
.unwrap_or_else(|| Map::new(&env));

let mut schedule = schedules.get(schedule_id).unwrap_or_else(|| panic!("Schedule not found"));
let mut schedule = schedules
.get(schedule_id)
.ok_or(InsuranceError::PolicyNotFound)?;
Expand Down Expand Up @@ -1297,6 +1307,7 @@ impl Insurance {
.get(&symbol_short!("PREM_SCH"))
.unwrap_or_else(|| Map::new(&env));

let mut schedule = schedules.get(schedule_id).unwrap_or_else(|| panic!("Schedule not found"));
let mut schedule = schedules
.get(schedule_id)
.ok_or(InsuranceError::PolicyNotFound)?;
Expand Down
17 changes: 14 additions & 3 deletions remittance_split/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![no_std]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
mod test;
// test module declared above

use soroban_sdk::{
Expand Down Expand Up @@ -726,9 +728,18 @@ impl RemittanceSplit {
}

let split = Self::get_split(env);
let s0 = split.get(0).unwrap() as i128;
let s1 = split.get(1).unwrap() as i128;
let s2 = split.get(2).unwrap() as i128;
let s0 = match split.get(0) {
Some(v) => v as i128,
None => return Err(RemittanceSplitError::Overflow),
};
let s1 = match split.get(1) {
Some(v) => v as i128,
None => return Err(RemittanceSplitError::Overflow),
};
let s2 = match split.get(2) {
Some(v) => v as i128,
None => return Err(RemittanceSplitError::Overflow),
};

let spending = total_amount
.checked_mul(s0)
Expand Down
Loading
Loading