//SPDX-License-Identifier: MIT import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; pragma solidity ^0.8.5; /************************************** CONTRACT **************************************/ interface IRoles { function isAsstManager(address account) external view returns(bool); function isUpdatesManager(address account) external view returns(bool); function isPauser(address account) external view returns(bool); } interface IRegistryPart1 { function getIsValued(string memory, string memory, uint256) external view returns (bool); function getIsReleased(string memory, string memory, uint256) external view returns (bool); } interface IAddressSmartContract { function getRolesContractAddress() external view returns (address); function getRegistryPart1Address() external view returns (address); } contract RegistryPart2 is Initializable, UUPSUpgradeable, AccessControlUpgradeable, PausableUpgradeable, OwnableUpgradeable { address private addressSC; function initialize( address AddressSmartContract) public initializer { addressSC = AddressSmartContract; __AccessControl_init(); __Pausable_init(); __Ownable_init(); } function _authorizeUpgrade(address) internal virtual override onlyOwner {} //TABLE ADDITONAL FIELDS struct LLD_AuxInfo{ bytes32 developer; bytes32 offSetStartDate; bytes32 offSetEndDate; bytes32 verifier; bytes32 longitude; bytes32 latitude; bool isAuxValued; } mapping (bytes32 => LLD_AuxInfo) public lookUpTable; function stringToBytes32(string memory _str) public pure returns (bytes32) { bytes memory tempBytes = bytes(_str); bytes32 convertedBytes; if(tempBytes.length == 0){ return 0x0; } assembly{ convertedBytes := mload(add(_str,32)) } return convertedBytes; } //----------------------- REGISTER NEW LLD FUNCTIONS -----------------------// function registerLLD_AuxInfo ( string memory LLD, string memory CreditType, uint256 Year, string memory Developer, string memory OffSetStartDate, string memory OffSetEndDate, string memory Verifier, string memory Longitude, string memory Latitude ) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isAsstManager(msg.sender), "Access Denied: Caller is NOT Assistant Manager!"); require(IRegistryPart1(IAddressSmartContract(addressSC).getRegistryPart1Address()).getIsValued(LLD, CreditType, Year), "Error: Input LLD not found with Registry-Part1!"); require(!(IRegistryPart1(IAddressSmartContract(addressSC).getRegistryPart1Address()).getIsReleased(LLD, CreditType, Year)), "Error: Input LLD is released from Registry!"); require(!getIsAuxValued(LLD, CreditType, Year), "Duplicate LLD: The LLD is already registered with Registry-Part2!"); bytes32 newEntry = keccak256(abi.encodePacked(LLD,CreditType,Year)); lookUpTable[newEntry].developer = stringToBytes32(Developer); lookUpTable[newEntry].offSetStartDate = stringToBytes32(OffSetStartDate); lookUpTable[newEntry].offSetEndDate = stringToBytes32(OffSetEndDate); lookUpTable[newEntry].verifier = stringToBytes32(Verifier); lookUpTable[newEntry].longitude = stringToBytes32(Longitude); lookUpTable[newEntry].latitude = stringToBytes32(Latitude); lookUpTable[newEntry].isAuxValued = true; } //----------------------- GETTER FUNCTIONS -----------------------// function getIsAuxValued(string memory LLD, string memory CreditType, uint256 Year) public view returns (bool) { if (lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].isAuxValued) return true; else return false; } function getLLD_AuxInfo(string memory LLD, string memory CreditType, uint256 Year) public view returns ( string memory Developer, string memory OffsetStartDate, string memory OffsetEndDate, string memory Verifier, string memory Longitude, string memory Latitude) { require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); return ( string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].developer)), string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].offSetStartDate)), string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].offSetEndDate)), string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].verifier)), string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].longitude)), string(abi.encodePacked(lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].latitude)) ); } //-----------------UPDATE REQUIRED FIELDS FUNCTIONS ----------------// function updateAddressSmartContract(address AddressSmartContract) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isAsstManager(msg.sender), "Access Denied: Caller is NOT Assistant Manager!"); require(AddressSmartContract != address(0), "Account: Zero or Invalid address!"); addressSC = AddressSmartContract; } //UPDATE LLD - LLDs SHOULD NOT BE ALLOWED TO UPDATE function updateLLD_AuxInfo(string memory oldLLD, string memory oldCreditType, uint256 oldYear, string memory newLLD, string memory newCreditType, uint256 newYear) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isAsstManager(msg.sender), "Access Denied: Caller is NOT Assistant Manager!"); require(getIsAuxValued(oldLLD, oldCreditType, oldYear), "Error: Input LLD not found in Registry-Part2!"); require(!getIsAuxValued(newLLD,newCreditType,newYear), "Error: Input NEW LLD values are already registered with Registry-Part2!"); require(!(keccak256(abi.encodePacked(newLLD)) == keccak256(abi.encodePacked(""))), "Invalid input: Zero or invalid LLD!"); require(!(keccak256(abi.encodePacked(newCreditType)) == keccak256(abi.encodePacked(""))), "Invalid input: Zero or invalid CreditType!"); require(!(newYear == 0), "Invalid input: Zero or invalid year!"); bytes32 oldEntry = keccak256(abi.encodePacked(oldLLD,oldCreditType,oldYear)); bytes32 newEntry = keccak256(abi.encodePacked(newLLD,newCreditType,newYear)); lookUpTable[newEntry].developer = lookUpTable[oldEntry].developer; lookUpTable[newEntry].offSetStartDate = lookUpTable[oldEntry].offSetStartDate; lookUpTable[newEntry].offSetEndDate = lookUpTable[oldEntry].offSetEndDate; lookUpTable[newEntry].verifier = lookUpTable[oldEntry].verifier; lookUpTable[newEntry].longitude = lookUpTable[oldEntry].longitude; lookUpTable[newEntry].latitude = lookUpTable[oldEntry].latitude; lookUpTable[newEntry].isAuxValued = true; deleteLLD(oldLLD, oldCreditType, oldYear); } //----------------------- UPDATE ADDITIONAL FIELDS FUNCTIONS -----------------------// //UPDATE developer function updateDeveloper(string memory LLD, string memory CreditType, uint256 Year, string memory NewDeveloper) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].developer = stringToBytes32(NewDeveloper); } //UPDATE offsetStartDate function updateOffSetStartDate(string memory LLD, string memory CreditType, uint256 Year, string memory NewOffSetStartDate) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].offSetStartDate = stringToBytes32(NewOffSetStartDate); } //UPDATE offsetEndDate function updateOffsetEndDate(string memory LLD, string memory CreditType, uint256 Year, string memory NewOffSetEndDate) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].offSetEndDate = stringToBytes32(NewOffSetEndDate); } //UPDATE verifier function updateVerifier(string memory LLD, string memory CreditType, uint256 Year, string memory NewVerifier) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].verifier = stringToBytes32(NewVerifier); } //UPDATE longitude function updateLongitude(string memory LLD, string memory CreditType, uint256 Year, string memory NewLongitude) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].longitude = stringToBytes32(NewLongitude); } //UPDATE latitude function updateLatitude(string memory LLD, string memory CreditType, uint256 Year, string memory NewLatitude) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isUpdatesManager(msg.sender), "Access Denied: Caller is NOT Updates Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found in Registry-Part2!"); lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))].latitude = stringToBytes32(NewLatitude); } //----------------------- PAUSER FUNCTIONS -----------------------// function pauseContract() public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isPauser(msg.sender), "Access Denied: Caller is NOT Pauser!"); _pause(); } function unpauseContract() public whenPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isPauser(msg.sender), "Access Denied: Caller is NOT Pauser!"); _unpause(); } //----------------------- KILL FUNCTIONS -----------------------// //DELETE A LLD ENTRY function deleteLLD(string memory LLD, string memory CreditType, uint256 Year) public whenNotPaused { require(IRoles(IAddressSmartContract(addressSC).getRolesContractAddress()).isAsstManager(msg.sender), "Access Denied: Caller is NOT Assistant Manager!"); require(getIsAuxValued(LLD, CreditType, Year), "Error: Input LLD not found with Registry!"); delete lookUpTable[keccak256(abi.encodePacked(LLD,CreditType,Year))]; } }