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];
}
}