From bb6f53fb4d39e4e456f24371219cc782d25b479c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schmidt=20Cristian=20Hern=C3=A1n?= Date: Sat, 24 Aug 2024 18:29:02 -0300 Subject: [PATCH] Add addWoman function and update addTraining logic --- packages/hardhat/contracts/Controller.sol | 26 ++++---- .../nextjs/contracts/deployedContracts.ts | 66 +++++++++++++++---- 2 files changed, 67 insertions(+), 25 deletions(-) diff --git a/packages/hardhat/contracts/Controller.sol b/packages/hardhat/contracts/Controller.sol index b25acb6..d171a10 100644 --- a/packages/hardhat/contracts/Controller.sol +++ b/packages/hardhat/contracts/Controller.sol @@ -4,30 +4,25 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/access/Ownable.sol"; -//import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -//import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; - -// withdraw tokens → https://stackoverflow.com/a/73452462/2430102 - -import "hardhat/console.sol"; - contract Controller is Ownable { //-------------------------------------------------------------- event Deposit(address indexed sender, uint256 amount); event Withdrawal(address indexed receiver, uint256 amount); + event NewTraining(uint256 id, string name); + event NewWoman(address indexed wallet); //-------------------------------------------------------------- - mapping(address => bool) public members; + mapping(address => string) public birthCertificate; struct Training { uint256 id; string name; } Training[] public trainings; - uint256 private lastTrainingID = 0; + uint256 public lastTrainingID = 0; mapping(address => uint256[]) public performed; @@ -52,18 +47,21 @@ contract Controller is Ownable { //-------------------------------------------------------------- - function getLastTrainingID() public view onlyOwner returns (uint256) { - return lastTrainingID; - } - function addTraining(string calldata name) external { - uint256 id = ++lastTrainingID; + uint256 id = lastTrainingID++; trainings.push(Training({ id: id, name: name })); emit NewTraining(id, name); } //-------------------------------------------------------------- + function addWoman(address wallet, string calldata proof) external { + birthCertificate[wallet] = proof; + emit NewWoman(wallet); + } + + //-------------------------------------------------------------- + function withdraw(uint256 _amount) external { require(address(this).balance >= _amount, "Insufficient balance"); diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 4acd00e..5cb5792 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { 31337: { Controller: { - address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", + address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", abi: [ { inputs: [ @@ -80,6 +80,19 @@ const deployedContracts = { name: "NewTraining", type: "event", }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "wallet", + type: "address", + }, + ], + name: "NewWoman", + type: "event", + }, { anonymous: false, inputs: [ @@ -131,6 +144,43 @@ const deployedContracts = { stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "address", + name: "wallet", + type: "address", + }, + { + internalType: "string", + name: "proof", + type: "string", + }, + ], + name: "addWoman", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "birthCertificate", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [], name: "deposit", @@ -152,19 +202,13 @@ const deployedContracts = { type: "function", }, { - inputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - name: "members", + inputs: [], + name: "getLastTrainingID", outputs: [ { - internalType: "bool", + internalType: "uint256", name: "", - type: "bool", + type: "uint256", }, ], stateMutability: "view",