From 139a30eec193bba9e3f2bcab07fcf7f26e281a45 Mon Sep 17 00:00:00 2001 From: eddnewgate Date: Mon, 29 Jul 2024 00:10:54 +0545 Subject: [PATCH] feat: ozz access control added (#2) * feat: ozz access control added * feat: lint fix --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++-------------- Scarb.lock | 8 ++++++- Scarb.toml | 6 ++++-- src/lib.cairo | 42 ++++++++++++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4755d78..616a4a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,41 @@ -name: CI +name: Lint and Build on: - workflow_dispatch: + pull_request: + branches: + - main push: branches: - - main - pull_request: -permissions: read-all + - main jobs: - check: + lin: + name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: software-mansion/setup-scarb@v1 - - name: Check cairo format - run: scarb fmt --check - + - uses: actions/checkout@v3 + - name: Extract scarb version + run: | + SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/') + echo "SCARB_VERSION=$SCARB_VERSION" >> $GITHUB_ENV + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} + - name: Cairo lint + run: scarb fmt --check + test: + name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: software-mansion/setup-scarb@v1 - - uses: foundry-rs/setup-snfoundry@v3 - - name: Test cairo contract - run: scarb test \ No newline at end of file + - uses: actions/checkout@v3 + - name: Extract scarb version + run: | + SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/') + echo "SCARB_VERSION=$SCARB_VERSION" >> $GITHUB_ENV + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} + - uses: foundry-rs/setup-snfoundry@v3 + - name: Cairo Build + run: scarb build \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock index 6659036..f374ca6 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -2,9 +2,15 @@ version = 1 [[package]] -name = "push_coom" +name = "openzeppelin" +version = "0.15.0-rc.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?rev=49816b6763fea500396a97b5178c3e30a85eecc7#49816b6763fea500396a97b5178c3e30a85eecc7" + +[[package]] +name = "push_comm" version = "0.1.0" dependencies = [ + "openzeppelin", "snforge_std", ] diff --git a/Scarb.toml b/Scarb.toml index aa9ed3f..12559b2 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,12 +1,14 @@ [package] -name = "push_coom" +name = "push_comm" version = "0.1.0" edition = "2023_11" +scarb-version = "2.7.0-rc.4" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet = "2.6.4" +starknet = "2.7.0-rc.3" +openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev="49816b6763fea500396a97b5178c3e30a85eecc7" } [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.27.0" } diff --git a/src/lib.cairo b/src/lib.cairo index 8409116..6d90822 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -2,7 +2,45 @@ pub trait IPushComm {} #[starknet::contract] -mod PushComm { +pub mod MyContract { + use starknet::storage::Map; + use starknet::ContractAddress; + use openzeppelin::access::ownable::OwnableComponent; + + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); + + // Ownable Mixin + #[abi(embed_v0)] + impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl; + impl InternalImpl = OwnableComponent::InternalImpl; + + #[storage] - struct Storage {} + struct Storage { + #[substorage(v0)] + ownable: OwnableComponent::Storage, + user: User, + } + + #[derive(Drop, Serde, starknet::Store)] + pub struct User { + count: u256, + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + OwnableEvent: OwnableComponent::Event + } + + #[constructor] + fn constructor(ref self: ContractState, owner: ContractAddress) { + // Set the initial owner of the contract + self.ownable.initializer(owner); + } + + + #[abi(embed_v0)] + impl PushComm of super::IPushComm {} }