Skip to content

Commit

Permalink
Added Program hash changed event (#13)
Browse files Browse the repository at this point in the history
* feat : ProgramHashChanged event implemented

* feat : Added ProgramInfoChanged
  • Loading branch information
Akashneelesh authored Mar 6, 2024
1 parent 4b82e2d commit 9aabff9
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/config/component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod config_cpt {
interface::IOwnable,
};
use piltover::config::interface::IConfig;
use starknet::ContractAddress;
use starknet::{ContractAddress, get_caller_address};
use super::errors;

#[storage]
Expand All @@ -32,6 +32,21 @@ mod config_cpt {
facts_registry: ContractAddress,
}

#[event]
#[derive(Copy, Drop, starknet::Event)]
enum Event {
ProgramInfoChanged: ProgramInfoChanged,
}

#[derive(Copy, Drop, starknet::Event)]
struct ProgramInfoChanged {
changed_by: ContractAddress,
old_program_hash: felt252,
new_program_hash: felt252,
old_config_hash: felt252,
new_config_hash: felt252,
}

#[embeddable_as(ConfigImpl)]
impl Config<
TContractState,
Expand All @@ -51,8 +66,18 @@ mod config_cpt {
ref self: ComponentState<TContractState>, program_hash: felt252, config_hash: felt252
) {
self.assert_only_owner_or_operator();
self.program_info.write((program_hash, config_hash))
// TODO(#6): ProgramHashChanged Event
let (old_program_hash, old_config_hash): (felt252, felt252) = self.program_info.read();
self.program_info.write((program_hash, config_hash));
self
.emit(
ProgramInfoChanged {
changed_by: get_caller_address(),
old_program_hash: old_program_hash,
new_program_hash: program_hash,
old_config_hash: old_config_hash,
new_config_hash: config_hash,
}
);
}

fn get_program_info(self: @ComponentState<TContractState>) -> (felt252, felt252) {
Expand Down

0 comments on commit 9aabff9

Please sign in to comment.