Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FREE X ALGORITHM #14658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions decentralized
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DecentralizedAlgorithm {
struct Algorithm {
string name;
string code; // Pseudocode or reference to the algorithm
uint256 votes;
}

Algorithm[] public algorithms;
mapping(address => uint256) public userVotes;

event AlgorithmAdded(string name, string code);
event Voted(address indexed user, uint256 algorithmId);

function addAlgorithm(string memory _name, string memory _code) public {
algorithms.push(Algorithm({
name: _name,
code: _code,
votes: 0
}));
emit AlgorithmAdded(_name, _code);
}

function vote(uint256 _algorithmId) public {
require(_algorithmId < algorithms.length, "Invalid algorithm ID");
require(userVotes[msg.sender] == 0, "User has already voted");

algorithms[_algorithmId].votes += 1;
userVotes[msg.sender] = _algorithmId;

emit Voted(msg.sender, _algorithmId);
}

function getAlgorithms() public view returns (Algorithm[] memory) {
return algorithms;
}
}