-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created ElectionFactory.sol file * Created the basic functions for the Election Factory contract * Created a function to delete an election * Created an onlyOwner modifier * Done with the ElectionFactory.sol file * Updated code * Changd the indentation of the file
- Loading branch information
1 parent
649ec86
commit a3bd480
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"editor.tabSize": 2 | ||
"editor.tabSize": 2, | ||
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "./Election.sol"; | ||
|
||
contract ElectionFactory { | ||
address owner; | ||
|
||
//Array to keep track of the elections | ||
address[] elections; | ||
|
||
constructor (){ | ||
owner = msg.sender; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "You are not the owner"); | ||
_; | ||
} | ||
|
||
//Event emitted when an election is created | ||
event ElectionCreated(address electionAddress); | ||
|
||
//Function to create new election | ||
function createElection( | ||
string memory _title, | ||
string memory _description, | ||
bool _isPublic, | ||
uint _startDate, | ||
uint _endDate | ||
) public { | ||
//Create a new instance of the Election contract | ||
Election newElection = new Election( | ||
_title, | ||
_description, | ||
_isPublic, | ||
_startDate, | ||
_endDate | ||
); | ||
|
||
//Store the address of the newly created election | ||
elections.push(address(newElection)); | ||
|
||
//Emit an event for the creation of the new contract | ||
emit ElectionCreated(address(newElection)); | ||
} | ||
|
||
|
||
//function to get addresses of all elections | ||
function getElections() public view returns (address[] memory){ | ||
return elections; | ||
} | ||
|
||
//function to delete an election | ||
function deleteElection(uint _electionID) public onlyOwner { | ||
delete elections[_electionID]; | ||
} | ||
|
||
//Function to retrieve the total number of elections | ||
function getTotalElections() public view returns (uint) { | ||
return elections.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters