From 64848125cfcbc2aa5a04cb1311e825a6e68845c5 Mon Sep 17 00:00:00 2001 From: FabienC Date: Thu, 7 Dec 2023 21:32:35 +0200 Subject: [PATCH] refactor: use assert instead of if with panic --- src/core/address_provider.cairo | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/core/address_provider.cairo b/src/core/address_provider.cairo index 85f140f..058c042 100644 --- a/src/core/address_provider.cairo +++ b/src/core/address_provider.cairo @@ -73,6 +73,7 @@ mod AddressProvider { const AddressProvider__AlreadySet: felt252 = 'Protocol addresses already set'; const AddressProvider__Expected15Addresses: felt252 = 'Expected 15 addresses'; } + #[constructor] fn constructor(ref self: ContractState) { self.ownable.initializer(get_caller_address()); @@ -82,12 +83,8 @@ mod AddressProvider { impl AddressProviderImpl of super::IAddressProvider { fn set_addresses(ref self: ContractState, addresses: Span) { self.ownable.assert_only_owner(); - if (self.is_address_setup_initialized.read()) { - panic_with_felt252(Errors::AddressProvider__AlreadySet); - } - if (addresses.len() != 15) { - panic_with_felt252(Errors::AddressProvider__Expected15Addresses); - } + assert(!self.is_address_setup_initialized.read(), Errors::AddressProvider__AlreadySet); + assert(addresses.len() == 15, Errors::AddressProvider__Expected15Addresses); let mut addr = addresses; loop { @@ -199,10 +196,9 @@ mod AddressProvider { #[generate_trait] impl AddressProviderInternalImpl of AddressProviderInternalTrait { + #[inline(always)] fn assert_not_address_zero(ref self: ContractState, address: ContractAddress) { - if (address.is_zero()) { - panic_with_felt252(CommunErrors::CommunErrors__AddressZero); - } + assert(address.is_non_zero(), CommunErrors::CommunErrors__AddressZero); } } }