Hi all,
I'm Trying to add upgrade plugin to my Smart Contract Registry
//SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
/**
* @title traceability
* @dev Contract with abstraction for traceability in a supply chain
*/
import "@openzeppelin/contracts/access/Ownable.sol";
contract Registry is Ownable {
address[] public whitelistedAddresses;
bool public onlyWhitelisted = true;
/**
* @dev Define the structure for a basic product
*/
struct Worker {
string Name;
string Account;
string location;
string description;
string State;
uint256 CreationDate;
bool exist;
}
/**
* @dev Mapping that define the storage of a Worker
*/
mapping(string => Worker) private StorageWorker;
mapping(address => mapping(string => bool)) private wallet;
/**
* @dev Declare events according the Time Record operations:
*/
event CreateWorker(address Name, string id, uint256 CreationDate, string Account, string State);
event GetWorker(address Name, string id, string State);
event CreationReject(address Name, string id, string RejectMessage);
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function transferOwnership(address _newOwner) public override onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Function that create the Worker:
*/
function creationWorker(string memory Name, string memory description, string memory id, string memory location, string memory Account, string memory State ) public {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
}
if(StorageWorker[id].exist) {
emit CreationReject(msg.sender, id, "Worker con this id already exist");
return;
}
StorageWorker[id] = Worker(Name, Account, location, description, State, block.timestamp, true);
wallet[msg.sender][id] = true;
emit CreateWorker(msg.sender, id, block.timestamp, Account, State);
}
/**
* @dev Getter of the characteristic of a Worker:
*/
function getWorker(string memory id) public view returns (string memory, string memory, string memory, uint256, string memory) {
return (StorageWorker[id].Name, StorageWorker[id].description, StorageWorker[id].location, StorageWorker[id].CreationDate, StorageWorker[id].Account);
}
function getWorkerState(string memory id) public view returns (string memory, string memory, string memory, string memory) {
return (StorageWorker[id].Name, StorageWorker[id].Account, StorageWorker[id].description, StorageWorker[id].State);
}
/**
* @dev Funcion to check the ownership of a Worker:
*/
function isOwner(address owner, string memory id) public view returns (bool) {
if(wallet[owner][id]) {
return true;
}
return false;
}
}
I just created an upgradeable deployproxy.js:
const { ethers, upgrades } = require("hardhat");
async function main() {
const Registry = await ethers.getContractFactory("Registry");
const proxy = await upgrades.deployProxy(Registry, [], { unsafeAllowCustomTypes: true });
await proxy.deployed();
console.log(proxy.address);
}
main();
When I try to deploy it, shows the following error:
Error: Contract `Registry` is not upgrade safe
contracts/Registry.sol:14: Variable `onlyWhitelisted` is assigned an initial value
Move the assignment to the initializer