0

I have follows this answer related to Upgradeable smart contracts and Zeppelin's solution.

I have tested those examples, where I was able to update the interface of the functions that are already defined. Bu no matter what I was not able to add new functions into the upgraded contract. I guess since ABI is fixed, it does not allow me to add new functions in to my contracts.

[Q] Overall is it possible to add new functions to the upgraded contract?

I think to add a generic function that might make a delegate call to the new added function, such as newFunction under Example contract.

Problem I face:

  • I was not able pass the struct that contains contract's Storage as parameter on the delegate call. The error I am having is this type cannot be encoded on the delegate call.

  • TheContract is the contract the I was able to upgrade.

code_link

    pragma solidity ^0.4.8;

    import "../contracts/LibInterface.sol";

    library Example {
         function getUint(LibInterface.S storage s) public constant returns (uint) {
              return s.i;
         }
         function setUint(LibInterface.S storage s, uint i) public {
              s.i = i;
         }

        function newFunction(uint i){
              s.i = i*2;
        }
    }

code_link:

contract TheContract {
   LibInterface.S s;
   address lib

   constructor(address ExampleAddress) {
        lib = ExampleAddress; //Set with Example contract's deployed address.
   }

   using LibInterface for LibInterface.S;

   function getUint() public constant returns (uint) {
            return s.getUint();
   }

   function set(uint i) public {
         return s.setUint(i);
   }

  function getUintDelegate() public constant returns (uint) {
       return lib.delegatecall(abi.encodePacked(bytes4(keccak256("getUint(LibInterface.S storage,address)")), s, i));
  }

   function setUintDelegate(uint i) public {         
       lib.delegatecall(abi.encodePacked(bytes4(keccak256("setUint(LibInterface.S storage,address)")), s, i));
  }

  function callToNewFunction(LibInterface.S storage s){
       lib.delegatecall(abi.encodePacked(bytes4(keccak256("newFunction(LibInterface.S storage,address)")), s, i));
  }

}

Your Answer

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

Browse other questions tagged or ask your own question.