blockchain-IoT / Motoro

Smart contracts for decentralized rentals of vehicles.
https://www.toptal.com/ethereum/motoro-iot-in-transportation
MIT License
106 stars 39 forks source link

Versioning #16

Open patrykmat opened 6 years ago

patrykmat commented 6 years ago

Feature request

As a CTO I want to be able to upload different versions of the smart contracts then I expect to have an additional smart contract Where I can redirect all requests from the old version of contract to a new one

jaszczw commented 6 years ago

There is a couple of ways of achieving that:

You can use delegatecall available in solidity that will call a method in another smart contract together with changeable variable currentVersionAddress we can call 'current' version of the contract from our 'proxy'.

example from https://github.com/shaunazzopardi/smart-contract-versioning called 'Proxy/Interface method'


    address currentVersion = <someAddress>;

    <type> <varName>;
    function <methodName>() public returns(<type>){
        if(currentVersion.delegatecall(msg.data)){
            returns <varName>;
        }
        else{
            revert();
        }
    }

Only Owner of the contract can modify the currentVersionAddress.

In more details it concept is explained on https://ethereum.stackexchange.com/questions/2404/upgradeable-smart-contracts

One of the limits of that approach is that you can have only variables available in the original contract, meaning you would have to either know a priori what will you require or provide a magic map of anything.

Sources:

  1. https://github.com/shaunazzopardi/smart-contract-versioning
  2. https://ethereum.stackexchange.com/questions/2404/upgradeable-smart-contracts
  3. https://forum.ethereum.org/discussion/4595/versioning-of-smart-contracts
michalmikolajczyk commented 6 years ago

Versioning best practices https://blog.zeppelin.solutions/proxy-libraries-in-solidity-79fbe4b970fd https://medium.com/rocket-pool/upgradable-solidity-contract-design-54789205276d

michalmikolajczyk commented 6 years ago

Consider moving to Zeppelin OS https://docs.zeppelinos.org/docs/start.html