Skip to content
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 examples to contract, and cahnge cairo to 2.8.0 #192

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/Editor/EditorFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function EditorFooter({ withoutContent = false }) {
!isFullScreen && 'rounded-b-lg',
)}
>
<span>Cairo Compiler v2.6.3</span>
<span>Cairo Compiler v2.8.0</span>

{isFullScreen && (
<div className="flex items-center justify-end divide-x divide-gray-200 dark:divide-black-500">
Expand Down
69 changes: 69 additions & 0 deletions components/Editor/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,73 @@ fn fib(a: felt252, b: felt252, n: felt252) -> felt252 {
0 => a,
_ => fib(b, a + b, n - 1),
}
}`,
`#[starknet::contract]
mod SimpleContract {
#[storage]
struct Storage {
balance: felt252,
}

#[generate_trait]
impl InternalImpl of InternalTrait {
fn internal_function(self: @ContractState) -> felt252 {
self.balance.read()
}
}

fn other_internal_function(self: @ContractState) -> felt252 {
self.balance.read() + 5
}
}

use SimpleContract::{ InternalTrait, other_internal_function };

fn add(a: felt252, b: felt252, c: felt252) -> felt252 {
a + b + c
}

fn main() -> felt252 {
let mut state = SimpleContract::contract_state_for_testing();
state.balance.write(10);

let balance = state.balance.read();
let internal_balance = state.internal_function();
let other_balance = other_internal_function(@state);

let res = add(balance, internal_balance, other_balance);
res
}`,
`#[starknet::contract]
mod Fibonacci {
#[storage]
struct Storage {
n: u128,
}

#[generate_trait]
impl CalculationImpl of CalculationTrait {
fn calculate_fib(self: @ContractState) -> u128 {
fib(1, 1, self.n.read())
}
}

fn fib(a: u128, b: u128, n: u128) -> u128 {
match n {
0 => a,
_ => fib(b, a + b, n - 1),
}
}
}

use Fibonacci::CalculationTrait;

fn main() -> u128 {
let mut state = Fibonacci::contract_state_for_testing();
state.n.write(5);

let result = state.calculate_fib();
result
}`,
],
Sierra: [
Expand Down Expand Up @@ -434,4 +501,6 @@ export const CairoExampleNames = [
'Dictionaries',
'Ownership',
'Fibonacci',
'SimpleContract',
'FibonacciContract',
]
Loading