in my code I am using events in order to log some date. I would like to include the name of the contracts I am calling out of my main contract into this event log. Does anyone have an idea how to do that?
2 Answers
This is not possible:
There is no way (yet) for a contract to read another contract's name. If you know the contracts you are calling, you can reference their name by some identifier, either a string or a number. Like
event contractCalled(uint256 indexed theContractsNumber)
i guess you could do a mapping in which you would register the name of the contract for its address :
mapping(address => string) contractName;
and then, use this mapping to put the name of the contract in the event
contract myContract{
mapping(address => string) contractName;
event myEvent(address contractRef);
function myContract(){
// constructor
...
}
myMethod(address _contract){
...
myEvent(contractName[_contract]);
}
}
Note however that you should have to populate yourself the mapping with the intended names you want.