Solidity documentation says it is possible to use anything as mapping value, which I assume includes a contract:
_ValueType
can actually be any type, including mappings.
but I couldn't find an example or documentation on how to work with it.
If I have the following mapping, how can I know if the contract in the mapping exists, or have suicided?
pragma solidity ^0.4.0;
contract MyContract {
// ...
}
contract MappingExample {
mapping(uint32 => MyContract) inner_contracts;
function do_something(uint32 key) {
MyContract c;
if(/* inner_contracts[key] exists??? */) {
c = inner_contracts[key];
} else {
c = new MyContract;
inner_contracts[key] = c;
}
// do stuff with c
}
}
mapping(uint32 => address)
instead, and refer to this answer for checking whether the contract on a particular address exists.