1

I have read this and I was wondering if this is a suitable implementation.

contract A { 
    address owner;  

    function A() { 
        owner = msg.sender; 
    }

    function useB() returns (bool){ 
        B b = new B(msg.sender);
        if (!b.call.value(msg.value)(bytes4(sha3("deposit()")))) { throw; } 
        return true;

}
}

contract B { 
    address owner;
    address controllingContract;
    uint balance;

    modifier onlyOwner {
        if (msg.sender != owner) { throw; } 
        _;
    }
    modifier controlledContract {
        if (msg.sender != controllingContract) { throw; }
        _;
    }

    function B(address _owner) {
        controllingContract = msg.sender; 
        owner = _owner; 
    }
    function deposit() controlledContract{
        balance += msg.value; 
    }
    function updateContract(address _updatedContract) onlyOwner { 
        controllingContract = _updatedContract; 
    }
}
1

Create a storage contract, where you would put all your data (in Structs, for example). Design them as tables and subtables, to have as much flexibility as possible.

Then you set up a main contract and either define the storage contract's Address in it (do not forget to make this editable by yourself or whoever else) and use it for calling data from your data contract, or pass the storage contract's address along as an argument when calling your getter method.

The advantage is, that you won't have to bother about actual updating mechanisms - you just deploy your main contract again and use it's new address for interacting with your dApp (or whatever you're using the contract for)

You might be familiar with Truffle (https://github.com/ConsenSys/truffle) - it manages the replacement of new contract addresses in existing dApps automatically for you, this comes really handy. You can even pass an older address as an argument, to interact with an older version of your contract, if you need to.

  • Hi Nikita Fuchs, I"m really interested in your logic, do you mind showing us an example of your implementation or coming up with a simple one? Thanks a lot ! – fabdarice Jun 14 '17 at 23:40

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.