Loading modified contracts keeping the same super class

by Suzana Maranhão   Last Updated September 10, 2019 21:28 PM - source

I am trying to implement upgrade of contracts. One pattern by [1] is to have a layer to resolve the actual address of a contract. I implemented that adding the Pausable manipulation. My idea was to pause the old contract before replace them. The old and the new implementation are Pausable contracts (Open Zeppelin). I imagined that it was possible to load the existing contract using their superclass (Pausable). However, this code does not work when trying to change the contract by the second time. In the first time, the code is ok because Resolver was compiled with the original contract and knows that it is Pausable. In the second time, it seems that Resolver cannot understand the load as a kind of Pausable. Do you know how the EVM works? Any idea to solve that?

contract Resolver {

mapping (string => address) nameToAddress;
mapping (string => address[]) nameToPreviousAddresses;

function changeContract(string memory name, address newAddr) public onlyOwner returns (bool) {

    address contractAddr = nameToAddress[name];
    if(newAddr != contractAddr) {

        if (contractAddr != address(0)) {
            Pausable pausable = Pausable(contractAddr);
            pausable.pause();
        }

        nameToPreviousAddresses[name].push(newAddr);
        nameToAddress[name] = newAddr;
        return true;
    }

    return false;
}

function getAddr(string memory name) public view returns (address) {
    return nameToAddress[name];
}

}

[1] https://consensys.github.io/smart-contract-best-practices/software_engineering/#upgrading-broken-contracts

Tags : solidity evm


Related Questions


How to map an address with a string array in solidity?

Updated October 09, 2018 12:28 PM

How to handle dynamic size string array in solidity?

Updated November 28, 2018 04:28 AM

What is the status of forbidden call in constructor?

Updated December 12, 2018 08:28 AM

How can I pass struct from one contract to another?

Updated January 10, 2019 23:28 PM

How to transfer Ether to ERC20 token contract?

Updated July 23, 2018 00:28 AM