Ver Fonte

Create 4REALOSS.sol already deployed and confirmed https://polygonscan.com/verifyContract-solc?a=0xfa57b2c914ef81119fd490d54f4aa8e0156b9924&c=v0.6.8%2bcommit.0bbfe453&lictype=5

CodeWebToken há 1 ano atrás
pai
commit
04aa8bb5bc
1 ficheiros alterados com 76 adições e 0 exclusões
  1. 76 0
      4REALOSS.sol

+ 76 - 0
4REALOSS.sol

@@ -0,0 +1,76 @@
+/**
+ *Submitted for verification at Etherscan.io on 2024-07-15
+*/
+
+// SPDX-License-Identifier: MIT
+pragma solidity ^0.6.8;
+pragma experimental ABIEncoderV2;
+
+contract REALOSS {
+    
+    // Structure of project
+    struct Project {
+        int repoid;
+        string projectname;
+        string ipfsCID;
+        string description;
+    }
+
+    mapping(int => Project) private projects;
+    int private nextRepoId = 1;
+
+    // Function to add project details
+    function addProject(string memory projectname, string memory ipfsCID, string memory description) public {
+        Project memory newProject = Project(nextRepoId, projectname, ipfsCID, description);
+        projects[nextRepoId] = newProject;
+        nextRepoId++;
+    }
+
+    // Function to get details of a project
+    function getProject(int repoid) public view returns (string memory, string memory, string memory) {
+        Project memory project = projects[repoid];
+        require(project.repoid != 0, "Project not found"); // revert if project is not found
+        return (project.projectname, project.ipfsCID, project.description);
+    }
+
+    // Function to get all project IDs and names
+    function getProjects() public view returns (int[] memory, string[] memory) {
+        int[] memory ids = new int[](uint(nextRepoId) - 1);
+        string[] memory names = new string[](uint(nextRepoId) - 1);
+
+        for (uint i = 0; i < uint(nextRepoId) - 1; i++) {
+            ids[i] = int(i + 1);
+            names[i] = projects[int(i + 1)].projectname;
+        }
+
+        return (ids, names);
+    }
+
+    // Function to search projects by name
+    function searchProjectByName(string memory projectname) public view returns (int[] memory, string[] memory, string[] memory) {
+        uint count = 0;
+        
+        // First count matching projects
+        for (uint i = 1; i < uint(nextRepoId); i++) {
+            if (keccak256(bytes(projects[int(i)].projectname)) == keccak256(bytes(projectname))) {
+                count++;
+            }
+        }
+
+        int[] memory ids = new int[](count);
+        string[] memory ipfsCIDs = new string[](count);
+        string[] memory descriptions = new string[](count);
+
+        uint index = 0;
+        for (uint i = 1; i < uint(nextRepoId); i++) {
+            if (keccak256(bytes(projects[int(i)].projectname)) == keccak256(bytes(projectname))) {
+                ids[index] = projects[int(i)].repoid;
+                ipfsCIDs[index] = projects[int(i)].ipfsCID;
+                descriptions[index] = projects[int(i)].description;
+                index++;
+            }
+        }
+
+        return (ids, ipfsCIDs, descriptions);
+    }
+}