I have two contracts, an active contract A is interacting with the external world and many passive contracts P (dynamically added) are designed to trigger some functions when in contract A certain conditions are met.
Therefore contract A is supposed to call a callback function of each of P contracts; I was wondering what would be the best way to register
a callback function of newly added P into already deployed contract A?
contract A{
uint numberOfContractsAdded;
struct ToCallBackContracts{
address contractAddress;
bytes4 contractMethodToCall;
bytes32 theOnlyArgument;
}
mapping(uint -> ToCallBackContracts) contracts;
constructor A(){}
function triggeredFromOutside(bytes32 param)public returns (bool){
for(var i=0; i<numberOfContractsAdded; i++){
//2- how? call the callback function of each registered contract
}
}
function registerCallback(bytes4 _cMethod, address _cAddress){
//1- how? to save contract/method, number of parameters to receive?
}
}
contract P{
address addressOfA;
constructor P(address _addressOfA){
addressOfA = _addressOfA;
}
function _callback(bytes32 param){
//do something
}
function callFromOutsideToRegisterWithA(bytes32 param){
//3- how? to register with A
}
}
There are 3 HOWs pointed out in the code for better understanding to summarize the question if I understand it right..
disclaimer: code is not tested/compiled/checked for syntax and only for demonstration purposes.
events
wont solve the problem at hand, I would need to passparam
as you notice inP._callback
signature. – khawarizmi Aug 1 '18 at 8:17handleEvent
function to take a parameter and pass it in A. If not, I'll write up another solution – Henk Aug 1 '18 at 8:18A
may change the parameter to pass to the contracts soevents
may be a bit unfit for my case – khawarizmi Aug 1 '18 at 8:36