Skip to content

Commit

Permalink
feat: add Enum in contract
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit fd6064e
Author: Philippe ROSTAN <[email protected]>
Date:   Mon Jul 3 19:26:54 2023 +0200

    feat: merge in hellocairo2

commit 0246933
Author: Philippe ROSTAN <[email protected]>
Date:   Mon Jul 3 17:21:45 2023 +0200

    feat: merge v5.16.0
    Squashed commit of the following:

    commit e5696b4
    Author: semantic-release-bot <[email protected]>
    Date:   Mon Jul 3 15:08:31 2023 +0000

        chore(release): 5.16.0 [skip ci]

        * cairo1 version2 support ([e564033](e564033))
        * extract parser from CallData and Cairo ([b7eba2a](b7eba2a))
        * parsers ([cce9029](cce9029))

    commit 3389085
    Merge: e6b861a 589c948
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 17:06:08 2023 +0200

        Merge pull request #670 from 0xs34n/next-version

        Next version

    commit 589c948
    Merge: ffa6d07 03ee060
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 16:38:23 2023 +0200

        Merge pull request #665 from 0xs34n/0.12.0/abi-parser

        abi parser Cario1 Version2

    commit 03ee060
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 16:32:11 2023 +0200

        chore: cleanup

    commit 6c0eae2
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 14:07:45 2023 +0200

        chore: compiled files

    commit e564033
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 14:05:52 2023 +0200

        feat: cairo1 version2 support

    commit ffa6d07
    Merge: e6b861a 6f8164f
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 11:43:42 2023 +0200

        Merge pull request #664 from amanusk/cairo_v2_example

        Add example of new synatx cairo contract

    commit cae5abd
    Author: Toni Tabak <[email protected]>
    Date:   Mon Jul 3 11:41:51 2023 +0200

        chore: refact

    commit cce9029
    Author: Toni Tabak <[email protected]>
    Date:   Fri Jun 30 16:16:21 2023 +0200

        feat: parsers

    commit b7eba2a
    Author: Toni Tabak <[email protected]>
    Date:   Fri Jun 30 16:13:14 2023 +0200

        feat: extract parser from CallData and Cairo

    commit 6f8164f
    Author: amanusk <[email protected]>
    Date:   Thu Jun 29 21:23:28 2023 +0300

        Add example of new synatx cairo contract

commit 15c1dcc
Author: Philippe ROSTAN <[email protected]>
Date:   Sun Jul 2 14:36:05 2023 +0200

    feat: sierra.json with enums

commit 7e6e136
Merge: b2e7a40 e6b861a
Author: Philippe ROSTAN <[email protected]>
Date:   Fri Jun 30 12:36:18 2023 +0200

    Merge pull request #1 from 0xs34n/develop

    merge
  • Loading branch information
PhilippeR26 committed Jul 18, 2023
1 parent 8915b03 commit 1a08793
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions __mocks__/cairo/helloCairo2/hello.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ struct Bet {
amount: u256,
}

#[derive(Copy, Drop, Serde)]
struct Order {
p1: felt252,
p2: u16,
}

#[derive(Copy, Drop, Serde)]
enum MyEnum {
Response: Order,
Warning: felt252,
Error: u16,
}

#[starknet::interface]
trait IHelloStarknet<TContractState> {
Expand Down Expand Up @@ -106,6 +118,10 @@ trait IHelloStarknet<TContractState> {

// used for changes to redeclare contract
fn array2ddd_felt(self: @TContractState, testdd: Array<Array<felt252>>) -> felt252;
fn my_enum_output(self: @TContractState, val1: u16) -> MyEnum;
fn option_u8_output(self: @TContractState, val1: u8) -> Option<u8>;
fn option_order_output(self: @TContractState, val1: u16) -> Option<Order>;
fn option_order_input(self: @TContractState, inp: Option<Order>) -> u16;
}

// MAIN APP
Expand Down Expand Up @@ -139,6 +155,7 @@ mod HelloStarknet {
use super::Bet;
use super::UserData;
use super::Foo;
use super::{Order, MyEnum};

#[storage]
struct Storage {
Expand All @@ -151,6 +168,17 @@ mod HelloStarknet {
user1: UserData,
}

#[l1_handler]
fn increase_bal(ref self: ContractState, from_address: felt252, amount: felt252) {
let current = self.balance.read();
self.balance.write(current + amount);
}


#[constructor]
fn constructor(ref self: ContractState) {}


#[external(v0)]
impl IHelloStarknetImpl of super::IHelloStarknet<ContractState> {
// Felt252 test.
Expand Down Expand Up @@ -312,5 +340,41 @@ mod HelloStarknet {
fn array2ddd_felt(self: @ContractState, testdd: Array<Array<felt252>>) -> felt252 {
return *(testdd.at(0_u32)).at(0_u32);
}

// return MyEnum
fn my_enum_output(self: @ContractState, val1: u16) -> MyEnum {
if val1 < 100 {
return MyEnum::Error(3);
}
if val1 == 100 {
return MyEnum::Warning('attention:100');
}
MyEnum::Response(Order { p1: 1, p2: val1 })
}
// return Option<litteral>
fn option_u8_output(self: @ContractState, val1: u8) -> Option<u8> {
if val1 < 100 {
return Option::None(());
}
Option::Some(val1 + 1)
}
// return Option<Order>
fn option_order_output(self: @ContractState, val1: u16) -> Option<Order> {
if val1 < 100 {
return Option::None(());
}
Option::Some(Order { p1: 18, p2: val1 })
}
// use as input Option<Order>
fn option_order_input(self: @ContractState, inp: Option<Order>) -> u16 {
match inp {
Option::Some(x) => {
return x.p2;
},
Option::None(()) => {
return 17;
}
}
}
}
}

0 comments on commit 1a08793

Please sign in to comment.