Skip to content

Commit

Permalink
Add addWoman function and update addTraining logic
Browse files Browse the repository at this point in the history
  • Loading branch information
schcriher committed Aug 24, 2024
1 parent 087fd23 commit bb6f53f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 25 deletions.
26 changes: 12 additions & 14 deletions packages/hardhat/contracts/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");

Expand Down
66 changes: 55 additions & 11 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const deployedContracts = {
31337: {
Controller: {
address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
abi: [
{
inputs: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit bb6f53f

Please sign in to comment.