Skip to content

Commit

Permalink
Merge pull request #27 from Quantum3-Labs/vote-contract
Browse files Browse the repository at this point in the history
Add cairo contracts
  • Loading branch information
jrcarlos2000 authored Apr 3, 2024
2 parents 70d6123 + 8659401 commit 6f4bc78
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 311 deletions.
10 changes: 5 additions & 5 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const Home: NextPage = () => {

// console.log(data);

const { writeAsync } = useScaffoldContractWrite({
contractName: "HelloStarknet",
functionName: "increase_balance",
args: [1],
});
// const { writeAsync } = useScaffoldContractWrite({
// contractName: "HelloStarknet",
// functionName: "increase_balance",
// args: [1],
// });

// console.log(data, isLoading);
return (
Expand Down
284 changes: 1 addition & 283 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,288 +3,6 @@
* You should not edit it manually or your changes might be overwritten.
*/

const deployedContracts = {
sepolia: {
HelloStarknet: {
address:
"0x05e316173428d7358cb71e532acc6983608ec8a021f6e418a847969c53753452",
abi: [
{
type: "impl",
name: "HelloStarknetImpl",
interface_name: "contracts::helloStarknet::IHelloStarknet",
},
{
type: "interface",
name: "contracts::helloStarknet::IHelloStarknet",
items: [
{
type: "function",
name: "increase_balance",
inputs: [
{
name: "amount",
type: "core::felt252",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "get_balance",
inputs: [],
outputs: [
{
type: "core::felt252",
},
],
state_mutability: "view",
},
{
type: "function",
name: "get_balance6",
inputs: [],
outputs: [
{
type: "core::felt252",
},
],
state_mutability: "view",
},
{
type: "function",
name: "get_balance_increment",
inputs: [
{
name: "amount",
type: "core::felt252",
},
],
outputs: [
{
type: "core::felt252",
},
],
state_mutability: "view",
},
],
},
{
type: "event",
name: "contracts::helloStarknet::HelloStarknet::Event",
kind: "enum",
variants: [],
},
],
},
SimpleStorage: {
address:
"0x0501ed68f98395647d6b5f81500b74b597a93058eb8382f7231903d7933290b2",
abi: [
{
type: "impl",
name: "SimpleStorageImpl",
interface_name: "contracts::simpleStorage::ISimpleStorage",
},
{
type: "interface",
name: "contracts::simpleStorage::ISimpleStorage",
items: [
{
type: "function",
name: "get_name",
inputs: [],
outputs: [
{
type: "core::felt252",
},
],
state_mutability: "view",
},
{
type: "function",
name: "set_name",
inputs: [
{
name: "name",
type: "core::felt252",
},
],
outputs: [],
state_mutability: "external",
},
],
},
{
type: "constructor",
name: "constructor",
inputs: [
{
name: "name",
type: "core::felt252",
},
],
},
{
type: "event",
name: "contracts::simpleStorage::SimpleStorage::Event",
kind: "enum",
variants: [],
},
],
},
Vote: {
address:
"0x0246ede155184ce1f1f8ac52fece63870db4725c777b456237a81340ceff85b7",
abi: [
{
type: "impl",
name: "VoteImpl",
interface_name: "contracts::vote::VoteTrait",
},
{
type: "enum",
name: "core::bool",
variants: [
{
name: "False",
type: "()",
},
{
name: "True",
type: "()",
},
],
},
{
type: "interface",
name: "contracts::vote::VoteTrait",
items: [
{
type: "function",
name: "get_vote_status",
inputs: [],
outputs: [
{
type: "(core::integer::u8, core::integer::u8, core::integer::u8, core::integer::u8)",
},
],
state_mutability: "view",
},
{
type: "function",
name: "voter_can_vote",
inputs: [
{
name: "user_address",
type: "core::starknet::contract_address::ContractAddress",
},
],
outputs: [
{
type: "core::bool",
},
],
state_mutability: "view",
},
{
type: "function",
name: "is_voter_registered",
inputs: [
{
name: "address",
type: "core::starknet::contract_address::ContractAddress",
},
],
outputs: [
{
type: "core::bool",
},
],
state_mutability: "view",
},
{
type: "function",
name: "vote",
inputs: [
{
name: "vote",
type: "core::integer::u8",
},
],
outputs: [],
state_mutability: "external",
},
],
},
{
type: "constructor",
name: "constructor",
inputs: [
{
name: "voter_1",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "voter_2",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "voter_3",
type: "core::starknet::contract_address::ContractAddress",
},
],
},
{
type: "event",
name: "contracts::vote::Vote::VoteCast",
kind: "struct",
members: [
{
name: "voter",
type: "core::starknet::contract_address::ContractAddress",
kind: "data",
},
{
name: "vote",
type: "core::integer::u8",
kind: "data",
},
],
},
{
type: "event",
name: "contracts::vote::Vote::UnauthorizedAttempt",
kind: "struct",
members: [
{
name: "unauthorized_address",
type: "core::starknet::contract_address::ContractAddress",
kind: "data",
},
],
},
{
type: "event",
name: "contracts::vote::Vote::Event",
kind: "enum",
variants: [
{
name: "VoteCast",
type: "contracts::vote::Vote::VoteCast",
kind: "nested",
},
{
name: "UnauthorizedAttempt",
type: "contracts::vote::Vote::UnauthorizedAttempt",
kind: "nested",
},
],
},
],
},
},
} as const;
const deployedContracts = {} as const;

export default deployedContracts;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useScaffoldContractWrite = <
calls: deployedContractData
? [
{
contractAddress: deployedContractData.address,
contractAddress: deployedContractData?.address,
entrypoint: functionName,
calldata: args as any[],
},
Expand Down
10 changes: 6 additions & 4 deletions packages/nextjs/utils/scaffold-stark/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
UseContractReadProps,
UseContractWriteProps,
} from "@starknet-react/core";
import { Address } from "@starknet-react/chains";

type ConfiguredChainId =
(typeof scaffoldConfig)["targetNetworks"][0]["network"];
Expand All @@ -35,7 +36,7 @@ export enum ContractCodeStatus {
}

export type GenericContract = {
address: string;
address: Address;
abi: Abi;
};
export type GenericContractsDeclaration = {
Expand Down Expand Up @@ -134,10 +135,11 @@ export type UseScaffoldWriteConfig<
>
> = {
contractName: TContractName;
// onBlockConfirmation?: (txnReceipt: TransactionReceipt) => void; TODO check this lines
// blockConfirmations?: number;
} & IsContractDeclarationMissing<
Partial<UseContractWriteProps>,
Partial<UseContractWriteProps> & {
functionName: string;
args: any[];
},
{
functionName: TFunctionName;
} & Omit<
Expand Down
21 changes: 8 additions & 13 deletions packages/snfoundry/contracts/src/helloStarknet.cairo
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
#[starknet::interface]
pub trait IHelloStarknet<TContractState> {
fn increase_balance(ref self: TContractState, amount: felt252);
fn get_balance(self: @TContractState) -> felt252;
fn get_balance6(self: @TContractState) -> felt252;
fn get_balance_increment(self: @TContractState, amount: felt252) -> felt252;
fn increase_balance(ref self: TContractState, amount: u32);
fn get_balance(self: @TContractState) -> u32;
fn get_balance_increment(self: @TContractState, amount: u32) -> u32;
}

#[starknet::contract]
mod HelloStarknet {
#[storage]
struct Storage {
balance: felt252,
balance: u32,
}

#[abi(embed_v0)]
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> {
fn increase_balance(ref self: ContractState, amount: felt252) {
assert(amount != 0, 'amount cant be 0');
fn increase_balance(ref self: ContractState, amount: u32) {
assert(amount !=0, 'amount cannot be 0');
self.balance.write(self.balance.read() + amount);
}

fn get_balance(self: @ContractState) -> felt252 {
fn get_balance(self: @ContractState) -> u32 {
self.balance.read()
}

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

fn get_balance_increment(self: @ContractState, amount: felt252) -> felt252 {
fn get_balance_increment(self: @ContractState, amount: u32) -> u32 {
self.balance.read() + amount
}
}
Expand Down
Loading

0 comments on commit 6f4bc78

Please sign in to comment.