1

This is very similar to another question. I was wondering if it is a proper design to have a function to transfer ownership. In the example below, I am trying to restrict Dao.add to be called only by Service.add. Are the following steps correct:

  1. Create Dao contract
  2. Create Service contract with the address of Dao contract
  3. Call Dao.transferOwnership with the address of Service contract
  4. Call Service.add

Code:

pragma solidity ^0.4.11;

contract Dao {

    address public owner;

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

    modifier onlyOwner {
        require (msg.sender == owner);
        _;
    }

    function transferOwnership(address newOwner) onlyOwner {
        owner = newOwner;
    }

    struct Lookup {
        uint id;
        string name;
    }

    mapping(uint => Lookup) internal lookupById;

    function getLookupById(uint _id) public constant returns (uint, string) {
        return (lookupById[_id].id, lookupById[_id].name);
    }

    function add(uint _id, string _name) onlyOwner {

        Lookup memory newLookup;
        newLookup.id = _id;
        newLookup.name = _name;
        lookupById[_id] = newLookup;
    }
}

contract Service {

    Dao dao;

    function Service(address daoAddress) {
        dao = Dao(daoAddress);
    }

    function add(uint _id, string _name) {
        dao.add(_id, _name);
    }
}
1

It sounds correct, as long as your intention is to relinquish your ownership of the DAO contract and give it to Service contract. Once you do that you will not be able to call the functions modified by onlyOwner. Only the Service contract will.

I'm writing an article that touches the ownership subject, you can read the draft here: https://medium.freecodecamp.org/a-protocol-for-saleable-smart-contracts-829bc2ce02b3

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.