-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Program hash changed event #13
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
@@ -32,6 +32,19 @@ mod config_cpt { | |
facts_registry: ContractAddress, | ||
} | ||
|
||
#[event] | ||
#[derive(Copy, Drop, starknet::Event)] | ||
enum Event { | ||
ProgramHashChanged: ProgramHashChanged, | ||
} | ||
|
||
#[derive(Copy, Drop, starknet::Event)] | ||
struct ProgramHashChanged { | ||
changed_by: ContractAddress, | ||
old_program_hash: felt252, | ||
new_program_hash: felt252, | ||
} | ||
|
||
#[embeddable_as(ConfigImpl)] | ||
impl Config< | ||
TContractState, | ||
|
@@ -51,8 +64,16 @@ 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, _): (felt252, felt252) = self.program_info.read(); | ||
self.program_info.write((program_hash, config_hash)); | ||
self | ||
.emit( | ||
ProgramHashChanged { | ||
changed_by: get_caller_address(), | ||
old_program_hash: old_program_hash, | ||
new_program_hash: program_hash, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in this contract the program info contains both the config hash and the program hash (as design that may be challenged @drspacemn if we should be more like solidity version), we should have a new event. Something like: struct ProgramInfoChanged {
changed_by: ContractAddress,
old_program_hash: ...,
new_program_hash: ...,
old_config_hash: ...,
new_config_hash: ...,
} WDYT guys @Akashneelesh @drspacemn @b-j-roberts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep true, it will have both the program_hash and config_hash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say either create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I'll just change it into ProgramInfoChanged and commit it now |
||
} | ||
); | ||
} | ||
|
||
fn get_program_info(self: @ComponentState<TContractState>) -> (felt252, felt252) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our current style is to not import functions like this, instead when you use the function do
Starknet::get_caller_address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is how its been done in other projects as well,
I feel this is like a best practices thing, instead if we have another instance we dont need to do
Rather just call
get_caller_address