1

Let's say I have a contract right now that I want to interact with a future or existing contract. This contract has two modifiers (onlyPermittedContracts and onlyOwner) that dictate whether or not a contract or user is allowed to invoke a certain function.

contract owned {
    address public owner;
    mapping (address => bool) public permittedContracts;
    function owned(){
        owner = msg.sender;
    }
    modifier onlyOwner{
        if(msg.sender != owner){
            throw;
        }
        _;
    }
    function transferOwnership (address newOwner) onlyOwner{
        owner = newOwner;
    }
    function addPermittedContract(address newPermittedContract)onlyOwner{
        if(permittedContracts[newPermittedContract]==true){
            throw;
        }
        permittedContracts[newPermittedContract]=true;
    }
    function removePermittedContract(address oldPermittedContract)onlyOwner{
        if(permittedContracts[oldPermittedContract]!=true){
            throw;
        }
        permittedContracts[oldPermittedContract]=false;
    }
    modifier onlyPermittedContracts{
        if(permittedContracts[msg.sender]!= true){
            throw;
        }
        _;
    }
}

contract ExistingContract is owned{
    //stuff has been removed
    mapping (address=> uint) public balanceOf;
    function issueNewToken(address recipient, uint amount)onlyOwner onlyPermittedContracts{
        if(balanceOf[recipient]+amount<balanceOf[recipient]){throw;}
        balanceOf[recipient]+=amount;
    }
}

Now let's say I want to make a new contract that will refer to this existing, pre-deployed contract:

contract NewToken{
    oldToken previousToken = new oldToken();
    previousToken.issueNewToken(xxxxx, yyyy);

}

//an abstract contract
contract OldToken{
    function issueNewToken(address recipient, uint amount){}
}

My question is, how much information do I need to include in the issueNewToken() function in the abstract contract I have in my second contract? Do I need to describe the various modifiers, or is this sufficient for the program to run? Thanks.

1 Answer 1

1

The way you are doing it is correct. Modifiers are part of how the contract operates internally, but they are don't affect the external interface in any way. From just the function name and argument types, the function can be called unambiguously.

For more details, see the ABI specification

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.