Hi @JesseAbram,
Welcome to the community forum
Looking at the Solidity documentation on Libraries:
https://solidity.readthedocs.io/en/v0.5.15/contracts.html#libraries
There is an example library Set
:
The calls to
Set.contains
,Set.insert
andSet.remove
are all compiled as calls (DELEGATECALL
) to an external contract/library. If you use libraries, be aware that an actual external function call is performed.
There is an example library BigInt
:
shows how to use types stored in memory and internal functions in libraries in order to implement custom types without the overhead of external function calls
My understanding is that you would need to interact with your storage library using public functions for it to be external, as per the library Set
example in the Solidity documentation (though there is the added gas cost of external calls).
I deployed your example and the library wasn't required to be deployed separately. (I verified the contract)
https://rinkeby.etherscan.io/tx/0xfd5c58afa248bbb64a970e487dba364cfc870a623536af5ee64b7fbeb95f5c89
I added a call to the library public function and the library was deployed separately. (I verified the library and the contract)
https://rinkeby.etherscan.io/tx/0xea5edfc821c0b0902f36ab117b2a3288b7c609ce8f82c7a6e469c50bcc7eb171
https://rinkeby.etherscan.io/tx/0x3de97c30bc9ced8f890d06e59d625562a8703b5b494625e9cf2a03a55a9c0bc6
Storage.sol
pragma solidity ^0.5.0;
library Storage {
struct Structing {
uint256 this;
mapping(uint256 => bool) that;
} // this does not require linking and is therefore embedding in contract demo?
function bePublic() public {} // with this function library should not embed, yet it does not seem to work
}
demo.sol
Includes call to library public function
pragma solidity ^0.5.0;
import "./Storage.sol";
contract demo {
Storage.Structing public structing;
function doStuff() public {
Storage.bePublic();
}
}
We recently had a discussion about Using modifiers for permission access control when faced with the code size limit.
in general and ideally, we shouldn’t have to change how we use the language, the compiler should automagically handle this for us and optimize for contract byte size or gas cost depending how we configure it. Rather than we having to understand the internal workings of the compiler and manually optimize to handle the implementation.
This is definitely frustrating and I have similar feelings for having to use libraries to work around contract byte size.
Please ask all the questions that you need.