citizen: implement Implement: The main contract that aggregates data from various repositories
This commit is contained in:
parent
94d0b92890
commit
13675b9688
136
contracts/EvidenceScout.sol
Normal file
136
contracts/EvidenceScout.sol
Normal file
@ -0,0 +1,136 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "./interfaces/RepositoryInterface.sol";
|
||||
import "./helpers/RepositoryHelper.sol";
|
||||
|
||||
contract EvidenceScout {
|
||||
struct RepositoryRecord {
|
||||
address repositoryAddress;
|
||||
string repositoryName;
|
||||
bytes32 repositoryHash;
|
||||
uint256 lastUpdatedTimestamp;
|
||||
bool isActive;
|
||||
}
|
||||
|
||||
mapping(bytes32 => RepositoryRecord) public repositories;
|
||||
mapping(address => bool) public authorizedAgents;
|
||||
|
||||
address public owner;
|
||||
uint256 public constant MAX_REPOSITORIES = 100;
|
||||
uint256 public totalRepositories;
|
||||
|
||||
event RepositoryRegistered(
|
||||
bytes32 indexed repositoryId,
|
||||
address indexed repositoryAddress,
|
||||
string repositoryName
|
||||
);
|
||||
|
||||
event RepositoryUpdated(
|
||||
bytes32 indexed repositoryId,
|
||||
address indexed repositoryAddress
|
||||
);
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner, "EvidenceScout: Unauthorized access");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier onlyAuthorizedAgent() {
|
||||
require(
|
||||
authorizedAgents[msg.sender] || msg.sender == owner,
|
||||
"EvidenceScout: Agent not authorized"
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
owner = msg.sender;
|
||||
authorizedAgents[msg.sender] = true;
|
||||
}
|
||||
|
||||
function registerRepository(
|
||||
address _repositoryAddress,
|
||||
string memory _repositoryName
|
||||
) external onlyAuthorizedAgent {
|
||||
require(
|
||||
_repositoryAddress != address(0),
|
||||
"EvidenceScout: Invalid repository address"
|
||||
);
|
||||
require(
|
||||
totalRepositories < MAX_REPOSITORIES,
|
||||
"EvidenceScout: Maximum repositories reached"
|
||||
);
|
||||
|
||||
bytes32 repositoryId = keccak256(
|
||||
abi.encodePacked(_repositoryAddress, _repositoryName)
|
||||
);
|
||||
|
||||
require(
|
||||
repositories[repositoryId].repositoryAddress == address(0),
|
||||
"EvidenceScout: Repository already exists"
|
||||
);
|
||||
|
||||
RepositoryInterface repositoryContract = RepositoryInterface(_repositoryAddress);
|
||||
|
||||
try repositoryContract.validateRepository() returns (bool isValid) {
|
||||
require(isValid, "EvidenceScout: Repository validation failed");
|
||||
} catch {
|
||||
revert("EvidenceScout: Repository validation error");
|
||||
}
|
||||
|
||||
repositories[repositoryId] = RepositoryRecord({
|
||||
repositoryAddress: _repositoryAddress,
|
||||
repositoryName: _repositoryName,
|
||||
repositoryHash: keccak256(abi.encodePacked(_repositoryAddress)),
|
||||
lastUpdatedTimestamp: block.timestamp,
|
||||
isActive: true
|
||||
});
|
||||
|
||||
totalRepositories++;
|
||||
|
||||
emit RepositoryRegistered(repositoryId, _repositoryAddress, _repositoryName);
|
||||
}
|
||||
|
||||
function updateRepositoryStatus(
|
||||
bytes32 _repositoryId,
|
||||
bool _isActive
|
||||
) external onlyAuthorizedAgent {
|
||||
require(
|
||||
repositories[_repositoryId].repositoryAddress != address(0),
|
||||
"EvidenceScout: Repository not found"
|
||||
);
|
||||
|
||||
repositories[_repositoryId].isActive = _isActive;
|
||||
repositories[_repositoryId].lastUpdatedTimestamp = block.timestamp;
|
||||
|
||||
emit RepositoryUpdated(
|
||||
_repositoryId,
|
||||
repositories[_repositoryId].repositoryAddress
|
||||
);
|
||||
}
|
||||
|
||||
function getRepositoryDetails(
|
||||
bytes32 _repositoryId
|
||||
) external view returns (RepositoryRecord memory) {
|
||||
require(
|
||||
repositories[_repositoryId].repositoryAddress != address(0),
|
||||
"EvidenceScout: Repository not found"
|
||||
);
|
||||
return repositories[_repositoryId];
|
||||
}
|
||||
|
||||
function addAuthorizedAgent(
|
||||
address _agent
|
||||
) external onlyOwner {
|
||||
require(_agent != address(0), "EvidenceScout: Invalid agent address");
|
||||
authorizedAgents[_agent] = true;
|
||||
}
|
||||
|
||||
function removeAuthorizedAgent(
|
||||
address _agent
|
||||
) external onlyOwner {
|
||||
require(_agent != owner, "EvidenceScout: Cannot remove owner");
|
||||
authorizedAgents[_agent] = false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user