1

I am experimenting with the zeppelin os upgradeable contracts but what I only need for my contract is to keep one specific state array when I deploy to another address. Avoiding proxy issues, upgrade frameworks and such, is there a way to do this manually somehow?

1

This is just a rough sketch to give you some ideas about partitioning concerns into a simple upgradable structure.

  • First, a very simple Owned contract for transferable access control.
  • Then a Keeper contract that is meant to hold the array during upgrades.
  • This version of Replaceable deploys it's own Keeper to get started. By doing so, Keeper recognizes that Replaceable is the owner, not the developer.
  • To actually replace Replaceable, you would first deploy a new version of it. In the replacement case, the constructor would not create a new Keeper. Instead, you would pass in the address of the existing Keeper and use keeper = Keeper(keeperAddress); Of course, Keeper will initially ignore the new contract because it doesn't "own" the data store. You tell the old Replaceable to pull the trigger and transfer ownership away from itself.

-

pragma solidity 0.4.24;

contract Owned {

    address public owner;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    constructor() public {
        owner = msg.sender;
    }

    function changeOwner(address newOwner) public onlyOwner returns(bool success) {
        owner = newOwner;
        return true;
    }
}

contract Keeper is Owned {

    bytes32[] public array;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    constructor() public {
        owner = msg.sender;
    }

    function appendArray(bytes32 value) public onlyOwner returns(uint arrayLength) {
        uint length = array.push(value);
        return length;
    }
}

contract Replacable is Owned {

    Keeper keeper;

    constructor() public {
        keeper = new Keeper();
    }

    function getKeeperAddress() public view returns(address keeperAddress) {
        return address(keeper);
    }

    function appendInKeeper(bytes32 value) public onlyOwner returns(uint arrayLength) {
        return keeper.appendArray(value);
    }

    function inspectInKeeper(uint row) public view returns(bytes32 value) {
        return keeper.array(row);
    }

    function appointNewReplacable(address newContract) public onlyOwner returns(bool success) {
        return keeper.changeOwner(newContract);
    }

}

I left out quite a few details to keep the example on point.

Hope it helps.

  • thanks it helps. Although this is a bit complicated and would make the zeppelinos option compelling for upgrades. I was thinking of something more of like make a function that spits out all the array and then have it passed as an argument to the new contract constructor manually – arisalexis Sep 6 '18 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.