Skip to content

Commit

Permalink
return a SyscallResult in upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 31, 2023
1 parent 08fdc5a commit d4e7476
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions starknet/src/space/space.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::traits::TryInto;
use core::traits::Destruct;
use starknet::{ClassHash, ContractAddress};
use starknet::{ClassHash, ContractAddress, SyscallResult};
use sx::types::{UserAddress, Strategy, Proposal, IndexedStrategy, Choice, UpdateSettingsCalldata};

#[starknet::interface]
Expand Down Expand Up @@ -65,15 +65,15 @@ trait ISpace<TContractState> {
fn cancel(ref self: TContractState, proposal_id: u256);
fn upgrade(
ref self: TContractState, class_hash: ClassHash, initialize_calldata: Array<felt252>
);
) -> SyscallResult<()>;
}

#[starknet::contract]
mod Space {
use super::ISpace;
use starknet::{
storage_access::{StorePacking, StoreUsingPacking}, ClassHash, ContractAddress, info, Store,
syscalls
syscalls, SyscallResult,
};
use zeroable::Zeroable;
use array::{ArrayTrait, SpanTrait};
Expand Down Expand Up @@ -527,12 +527,12 @@ mod Space {

fn upgrade(
ref self: ContractState, class_hash: ClassHash, initialize_calldata: Array<felt252>
) {
) -> SyscallResult<()> {
let state: Ownable::ContractState = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@state);

assert(class_hash.is_non_zero(), 'Class Hash cannot be zero');
starknet::replace_class_syscall(class_hash).unwrap();
starknet::replace_class_syscall(class_hash)?;

// Allowing initializer to be called again.
let mut state: Reinitializable::ContractState =
Expand All @@ -542,8 +542,7 @@ mod Space {
// Call initializer on the new version.
syscalls::call_contract_syscall(
info::get_contract_address(), INITIALIZE_SELECTOR, initialize_calldata.span()
)
.unwrap();
)?;

self
.emit(
Expand All @@ -553,6 +552,7 @@ mod Space {
}
)
);
SyscallResult::Ok(())
}

fn owner(self: @ContractState) -> ContractAddress {
Expand Down

0 comments on commit d4e7476

Please sign in to comment.