Timeline for Mapping to contract
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 16, 2018 at 17:09 | comment | added | Rob Hitchens |
You're bringing the whole bytecode of MyContract into MappingExample . The code for MyContract isn't shown, but let's say it's near the gasLimit because it's a complex beast. MappingExample will be that big plus additional bytecode for its own function. Multiple layers of this style lead to contracts that are too large to be deployed. This is what happens when you say MyContract c . You could just as well say MyContractInterface c and it would be smaller. ethereum.stackexchange.com/questions/5726/…
|
|
Jun 16, 2018 at 5:41 | comment | added | Patrik Stas | @RobHitchens,Storing it as MyContract enables us to call methods of that contract directly, but I couldn't validate the "being very expensive" statement. Why would it be? What extra information other than contract address would this "Contract type" include? Solidity at compile time verifies that methods you are calling are present. I was curious, so I tried it ethfiddle.com/yug3vEjOBk and whether you call addDbAsAddress or addDbAsInstance, it consumes about same amount of gas. The IdDatabase contract is long to verify that DbController doesn't stores contrat's function names/signatures | |
Dec 3, 2017 at 21:13 | comment | added | Rob Hitchens |
MyContract isn't an address. Variables cast as MyContract will have all the methods in the contract, whereas an address only has the methods that go with addresses. The sugar that might confuse the issue is that contract types are directly convertible to addresses. You can get away with returns(address theContract) { return c; } . I guess by "directly" they mean we don't have to explicitly recast them with something like return address(c);
|
|
Dec 3, 2017 at 21:02 | comment | added | lvella |
Are you sure mapping(uint32 => MyContract) isn't just a syntactic sugar for mapping(uint32 => address) ? I thought MyContract(theAddress) was just a cast...
|
|
Dec 3, 2017 at 20:32 | history | answered | Rob Hitchens | CC BY-SA 3.0 |