-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(if-else): add if-else access control * fix(if_else): CI issue * fix: add pr review changes * fix: pr review comments * docs: add documentation to contract * docs(src): add readme file * docs(src): add contract desc * fix: terminology & add to SUMMARY * feat(events): add events * chore: add to summary * chore: add type * fix: pr review changes --------- Co-authored-by: msaug <[email protected]>
- Loading branch information
1 parent
ddf4da0
commit cb89213
Showing
6 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "counter" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
starknet = "1.1.0" | ||
|
||
[[target.starknet-contract]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[contract] | ||
mod SimpleCounter { | ||
struct Storage { | ||
// Counter value | ||
_counter: u256, | ||
} | ||
|
||
#[event] | ||
// Increment event - emitted when the counter is incremented. | ||
fn Increment(counterVal: u256) {} | ||
|
||
#[constructor] | ||
fn constructor() {} | ||
|
||
#[external] | ||
fn increment() { | ||
let mut counter: u256 = _counter::read(); | ||
counter += 1; | ||
_counter::write(counter); | ||
// Emit event | ||
Increment(counter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod counter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Events | ||
|
||
An event is defined as function with the #[event] attribute. The parameters of the function correspond to data that will be emitted. An event is to be logged for easy and fast access to querying the data at a later time. | ||
|
||
Here's a simple example of a contract using events that emit an event each time a counter is incremented by the "increment" function: | ||
|
||
```rust | ||
{{#include ../listings/ch00-introduction/events/src/counter.cairo}} | ||
``` |