How would you call a function with a modifier from another contract. Let the contracts be:
contract MyContract {
address owner;
modifier getModified (address owner) {
if (msg.sender != owner) throw;
_;
}
function func(address newOwnerAddress) getModified(owner) returns (address newOwner) {
//....code....
}
}
contract newContract {
MyContract myContract = MyContract(0x08271...);
function bid(uint amt, address _oldOwner, address _newOwner) returns(bool success) {
if (amt > ...) {
myContract.func(_newOwner,{getModified:_oldOwner})
}
}
}
I am getting an error Error: Undeclared identifier: getModified
for getModified
in Remix. I tried reading the docs but they also dont mention the funcition call with modifiers to other contracts.
Thanks in advance.
msg.sender
asfunction func(address newOwnerAddress) getModified(msg.sender) ...
. Then inbid
,myContract.func(_newOwner);
should work.getModified(owner)
serves no purpose as it's always going to be theowner
state variable which you already have in scope. But now it's unclear whether your intent forif (msg.sender != owner)
refers to theowner
state variable orowner
parameter. Furthermoreif (msg.sender != owner)
will always be testing the calling contact againstowner
at it is the calling contract who ismsg.sender
.myContract.func(_newOwner,{getModified:_oldOwner})
as a valid calling convention.func
only takes one parameter.@o0ragman0o
, I have the test code here, the functions I am trying to interact is actually different. I have a function in some contract, and I want to call a specific function (which has a modifier), in that contract and answering your doubt, inif (msg.sender != owner)
refers to theowner
parameter. But@eth
shouldn't the modifier be mentioned while making a function call forfunc
. So I think the question still stands: how do you call a function with a modifier from another contract?getModified(owner)
modifier just substitutes the value of the global variableowner
everwhere that thegetModified
definition uses the parameterowner